Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
| 27 | #include <linux/i2c.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 28 | #include <linux/input.h> |
| 29 | #include <linux/intel-iommu.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/reservation.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 34 | #include <linux/vgaarb.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 35 | |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 36 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 37 | #include <drm/drm_atomic_helper.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 38 | #include <drm/drm_atomic_uapi.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 39 | #include <drm/drm_dp_helper.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 40 | #include <drm/drm_edid.h> |
| 41 | #include <drm/drm_fourcc.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 42 | #include <drm/drm_plane_helper.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 43 | #include <drm/drm_probe_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 44 | #include <drm/drm_rect.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 45 | #include <drm/i915_drm.h> |
| 46 | |
| 47 | #include "i915_drv.h" |
| 48 | #include "i915_gem_clflush.h" |
| 49 | #include "i915_trace.h" |
| 50 | #include "intel_drv.h" |
| 51 | #include "intel_dsi.h" |
| 52 | #include "intel_frontbuffer.h" |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 53 | |
Chris Wilson | 9f58892 | 2019-01-16 15:33:04 +0000 | [diff] [blame] | 54 | #include "intel_drv.h" |
| 55 | #include "intel_dsi.h" |
| 56 | #include "intel_frontbuffer.h" |
| 57 | |
| 58 | #include "i915_drv.h" |
| 59 | #include "i915_gem_clflush.h" |
| 60 | #include "i915_reset.h" |
| 61 | #include "i915_trace.h" |
| 62 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 63 | /* Primary plane formats for gen <= 3 */ |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 64 | static const u32 i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 65 | DRM_FORMAT_C8, |
| 66 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 67 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 68 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* Primary plane formats for gen >= 4 */ |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 72 | static const u32 i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 73 | DRM_FORMAT_C8, |
| 74 | DRM_FORMAT_RGB565, |
| 75 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 76 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 77 | DRM_FORMAT_XRGB2101010, |
| 78 | DRM_FORMAT_XBGR2101010, |
| 79 | }; |
| 80 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 81 | static const u64 i9xx_format_modifiers[] = { |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 82 | I915_FORMAT_MOD_X_TILED, |
| 83 | DRM_FORMAT_MOD_LINEAR, |
| 84 | DRM_FORMAT_MOD_INVALID |
| 85 | }; |
| 86 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 87 | /* Cursor formats */ |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 88 | static const u32 intel_cursor_formats[] = { |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 89 | DRM_FORMAT_ARGB8888, |
| 90 | }; |
| 91 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 92 | static const u64 cursor_format_modifiers[] = { |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 93 | DRM_FORMAT_MOD_LINEAR, |
| 94 | DRM_FORMAT_MOD_INVALID |
| 95 | }; |
| 96 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 97 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 98 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 99 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 100 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 101 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 102 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
| 103 | struct drm_i915_gem_object *obj, |
| 104 | struct drm_mode_fb_cmd2 *mode_cmd); |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 105 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state); |
| 106 | static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 107 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 108 | const struct intel_link_m_n *m_n, |
| 109 | const struct intel_link_m_n *m2_n2); |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 110 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 111 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 112 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 113 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 114 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 115 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 116 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 117 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 118 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 119 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 120 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 121 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 122 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state); |
| 123 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state); |
| 124 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 125 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 126 | struct drm_modeset_acquire_ctx *ctx); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 127 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 128 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 129 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 130 | struct { |
| 131 | int min, max; |
| 132 | } dot, vco, n, m, m1, m2, p, p1; |
| 133 | |
| 134 | struct { |
| 135 | int dot_limit; |
| 136 | int p2_slow, p2_fast; |
| 137 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 138 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 139 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 140 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 141 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 142 | { |
| 143 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 144 | |
| 145 | /* Obtain SKU information */ |
| 146 | mutex_lock(&dev_priv->sb_lock); |
| 147 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 148 | CCK_FUSE_HPLL_FREQ_MASK; |
| 149 | mutex_unlock(&dev_priv->sb_lock); |
| 150 | |
| 151 | return vco_freq[hpll_freq] * 1000; |
| 152 | } |
| 153 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 154 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 155 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 156 | { |
| 157 | u32 val; |
| 158 | int divider; |
| 159 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 160 | mutex_lock(&dev_priv->sb_lock); |
| 161 | val = vlv_cck_read(dev_priv, reg); |
| 162 | mutex_unlock(&dev_priv->sb_lock); |
| 163 | |
| 164 | divider = val & CCK_FREQUENCY_VALUES; |
| 165 | |
| 166 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 167 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 168 | "%s change in progress\n", name); |
| 169 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 170 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 171 | } |
| 172 | |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 173 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 174 | const char *name, u32 reg) |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 175 | { |
| 176 | if (dev_priv->hpll_freq == 0) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 177 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 178 | |
| 179 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 180 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 181 | } |
| 182 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 183 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 184 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 185 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 186 | return; |
| 187 | |
| 188 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 189 | CCK_CZ_CLOCK_CONTROL); |
| 190 | |
| 191 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 192 | } |
| 193 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 194 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 195 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 196 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 197 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 198 | if (HAS_DDI(dev_priv)) |
| 199 | return pipe_config->port_clock; /* SPLL */ |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 200 | else |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 201 | return dev_priv->fdi_pll_freq; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 204 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 205 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 206 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 207 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 208 | .m = { .min = 96, .max = 140 }, |
| 209 | .m1 = { .min = 18, .max = 26 }, |
| 210 | .m2 = { .min = 6, .max = 16 }, |
| 211 | .p = { .min = 4, .max = 128 }, |
| 212 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 213 | .p2 = { .dot_limit = 165000, |
| 214 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 217 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 218 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 219 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 220 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 221 | .m = { .min = 96, .max = 140 }, |
| 222 | .m1 = { .min = 18, .max = 26 }, |
| 223 | .m2 = { .min = 6, .max = 16 }, |
| 224 | .p = { .min = 4, .max = 128 }, |
| 225 | .p1 = { .min = 2, .max = 33 }, |
| 226 | .p2 = { .dot_limit = 165000, |
| 227 | .p2_slow = 4, .p2_fast = 4 }, |
| 228 | }; |
| 229 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 230 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 231 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 232 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 233 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 234 | .m = { .min = 96, .max = 140 }, |
| 235 | .m1 = { .min = 18, .max = 26 }, |
| 236 | .m2 = { .min = 6, .max = 16 }, |
| 237 | .p = { .min = 4, .max = 128 }, |
| 238 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 239 | .p2 = { .dot_limit = 165000, |
| 240 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 241 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 242 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 243 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 244 | .dot = { .min = 20000, .max = 400000 }, |
| 245 | .vco = { .min = 1400000, .max = 2800000 }, |
| 246 | .n = { .min = 1, .max = 6 }, |
| 247 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 248 | .m1 = { .min = 8, .max = 18 }, |
| 249 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 250 | .p = { .min = 5, .max = 80 }, |
| 251 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 252 | .p2 = { .dot_limit = 200000, |
| 253 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 256 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 257 | .dot = { .min = 20000, .max = 400000 }, |
| 258 | .vco = { .min = 1400000, .max = 2800000 }, |
| 259 | .n = { .min = 1, .max = 6 }, |
| 260 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 261 | .m1 = { .min = 8, .max = 18 }, |
| 262 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 263 | .p = { .min = 7, .max = 98 }, |
| 264 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 265 | .p2 = { .dot_limit = 112000, |
| 266 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 267 | }; |
| 268 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 269 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 270 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 271 | .dot = { .min = 25000, .max = 270000 }, |
| 272 | .vco = { .min = 1750000, .max = 3500000}, |
| 273 | .n = { .min = 1, .max = 4 }, |
| 274 | .m = { .min = 104, .max = 138 }, |
| 275 | .m1 = { .min = 17, .max = 23 }, |
| 276 | .m2 = { .min = 5, .max = 11 }, |
| 277 | .p = { .min = 10, .max = 30 }, |
| 278 | .p1 = { .min = 1, .max = 3}, |
| 279 | .p2 = { .dot_limit = 270000, |
| 280 | .p2_slow = 10, |
| 281 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 282 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 285 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 286 | .dot = { .min = 22000, .max = 400000 }, |
| 287 | .vco = { .min = 1750000, .max = 3500000}, |
| 288 | .n = { .min = 1, .max = 4 }, |
| 289 | .m = { .min = 104, .max = 138 }, |
| 290 | .m1 = { .min = 16, .max = 23 }, |
| 291 | .m2 = { .min = 5, .max = 11 }, |
| 292 | .p = { .min = 5, .max = 80 }, |
| 293 | .p1 = { .min = 1, .max = 8}, |
| 294 | .p2 = { .dot_limit = 165000, |
| 295 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 298 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 299 | .dot = { .min = 20000, .max = 115000 }, |
| 300 | .vco = { .min = 1750000, .max = 3500000 }, |
| 301 | .n = { .min = 1, .max = 3 }, |
| 302 | .m = { .min = 104, .max = 138 }, |
| 303 | .m1 = { .min = 17, .max = 23 }, |
| 304 | .m2 = { .min = 5, .max = 11 }, |
| 305 | .p = { .min = 28, .max = 112 }, |
| 306 | .p1 = { .min = 2, .max = 8 }, |
| 307 | .p2 = { .dot_limit = 0, |
| 308 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 309 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 310 | }; |
| 311 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 312 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 313 | .dot = { .min = 80000, .max = 224000 }, |
| 314 | .vco = { .min = 1750000, .max = 3500000 }, |
| 315 | .n = { .min = 1, .max = 3 }, |
| 316 | .m = { .min = 104, .max = 138 }, |
| 317 | .m1 = { .min = 17, .max = 23 }, |
| 318 | .m2 = { .min = 5, .max = 11 }, |
| 319 | .p = { .min = 14, .max = 42 }, |
| 320 | .p1 = { .min = 2, .max = 6 }, |
| 321 | .p2 = { .dot_limit = 0, |
| 322 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 323 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 324 | }; |
| 325 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 326 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 327 | .dot = { .min = 20000, .max = 400000}, |
| 328 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 329 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 330 | .n = { .min = 3, .max = 6 }, |
| 331 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 332 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 333 | .m1 = { .min = 0, .max = 0 }, |
| 334 | .m2 = { .min = 0, .max = 254 }, |
| 335 | .p = { .min = 5, .max = 80 }, |
| 336 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 337 | .p2 = { .dot_limit = 200000, |
| 338 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 339 | }; |
| 340 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 341 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 342 | .dot = { .min = 20000, .max = 400000 }, |
| 343 | .vco = { .min = 1700000, .max = 3500000 }, |
| 344 | .n = { .min = 3, .max = 6 }, |
| 345 | .m = { .min = 2, .max = 256 }, |
| 346 | .m1 = { .min = 0, .max = 0 }, |
| 347 | .m2 = { .min = 0, .max = 254 }, |
| 348 | .p = { .min = 7, .max = 112 }, |
| 349 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 350 | .p2 = { .dot_limit = 112000, |
| 351 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 352 | }; |
| 353 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 354 | /* Ironlake / Sandybridge |
| 355 | * |
| 356 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 357 | * the range value for them is (actual_value - 2). |
| 358 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 359 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 360 | .dot = { .min = 25000, .max = 350000 }, |
| 361 | .vco = { .min = 1760000, .max = 3510000 }, |
| 362 | .n = { .min = 1, .max = 5 }, |
| 363 | .m = { .min = 79, .max = 127 }, |
| 364 | .m1 = { .min = 12, .max = 22 }, |
| 365 | .m2 = { .min = 5, .max = 9 }, |
| 366 | .p = { .min = 5, .max = 80 }, |
| 367 | .p1 = { .min = 1, .max = 8 }, |
| 368 | .p2 = { .dot_limit = 225000, |
| 369 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 370 | }; |
| 371 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 372 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 373 | .dot = { .min = 25000, .max = 350000 }, |
| 374 | .vco = { .min = 1760000, .max = 3510000 }, |
| 375 | .n = { .min = 1, .max = 3 }, |
| 376 | .m = { .min = 79, .max = 118 }, |
| 377 | .m1 = { .min = 12, .max = 22 }, |
| 378 | .m2 = { .min = 5, .max = 9 }, |
| 379 | .p = { .min = 28, .max = 112 }, |
| 380 | .p1 = { .min = 2, .max = 8 }, |
| 381 | .p2 = { .dot_limit = 225000, |
| 382 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 383 | }; |
| 384 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 385 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 386 | .dot = { .min = 25000, .max = 350000 }, |
| 387 | .vco = { .min = 1760000, .max = 3510000 }, |
| 388 | .n = { .min = 1, .max = 3 }, |
| 389 | .m = { .min = 79, .max = 127 }, |
| 390 | .m1 = { .min = 12, .max = 22 }, |
| 391 | .m2 = { .min = 5, .max = 9 }, |
| 392 | .p = { .min = 14, .max = 56 }, |
| 393 | .p1 = { .min = 2, .max = 8 }, |
| 394 | .p2 = { .dot_limit = 225000, |
| 395 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 396 | }; |
| 397 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 398 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 399 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 400 | .dot = { .min = 25000, .max = 350000 }, |
| 401 | .vco = { .min = 1760000, .max = 3510000 }, |
| 402 | .n = { .min = 1, .max = 2 }, |
| 403 | .m = { .min = 79, .max = 126 }, |
| 404 | .m1 = { .min = 12, .max = 22 }, |
| 405 | .m2 = { .min = 5, .max = 9 }, |
| 406 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 407 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 408 | .p2 = { .dot_limit = 225000, |
| 409 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 410 | }; |
| 411 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 412 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 413 | .dot = { .min = 25000, .max = 350000 }, |
| 414 | .vco = { .min = 1760000, .max = 3510000 }, |
| 415 | .n = { .min = 1, .max = 3 }, |
| 416 | .m = { .min = 79, .max = 126 }, |
| 417 | .m1 = { .min = 12, .max = 22 }, |
| 418 | .m2 = { .min = 5, .max = 9 }, |
| 419 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 420 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 421 | .p2 = { .dot_limit = 225000, |
| 422 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 423 | }; |
| 424 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 425 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 426 | /* |
| 427 | * These are the data rate limits (measured in fast clocks) |
| 428 | * since those are the strictest limits we have. The fast |
| 429 | * clock and actual rate limits are more relaxed, so checking |
| 430 | * them would make no difference. |
| 431 | */ |
| 432 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 433 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 434 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 435 | .m1 = { .min = 2, .max = 3 }, |
| 436 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 437 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 438 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 439 | }; |
| 440 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 441 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 442 | /* |
| 443 | * These are the data rate limits (measured in fast clocks) |
| 444 | * since those are the strictest limits we have. The fast |
| 445 | * clock and actual rate limits are more relaxed, so checking |
| 446 | * them would make no difference. |
| 447 | */ |
| 448 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 449 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 450 | .n = { .min = 1, .max = 1 }, |
| 451 | .m1 = { .min = 2, .max = 2 }, |
| 452 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 453 | .p1 = { .min = 2, .max = 4 }, |
| 454 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 455 | }; |
| 456 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 457 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 458 | /* FIXME: find real dot limits */ |
| 459 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 460 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 461 | .n = { .min = 1, .max = 1 }, |
| 462 | .m1 = { .min = 2, .max = 2 }, |
| 463 | /* FIXME: find real m2 limits */ |
| 464 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 465 | .p1 = { .min = 2, .max = 4 }, |
| 466 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 467 | }; |
| 468 | |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 469 | static void |
| 470 | skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 471 | { |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 472 | if (enable) |
| 473 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 474 | DUPS1_GATING_DIS | DUPS2_GATING_DIS); |
| 475 | else |
| 476 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 477 | I915_READ(CLKGATE_DIS_PSL(pipe)) & |
| 478 | ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); |
| 479 | } |
| 480 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 481 | static bool |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 482 | needs_modeset(const struct drm_crtc_state *state) |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 483 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 484 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 487 | /* |
| 488 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 489 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 490 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 491 | * The helpers' return value is the rate of the clock that is fed to the |
| 492 | * display engine's pipe which can be the above fast dot clock rate or a |
| 493 | * divided-down version of it. |
| 494 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 495 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 496 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 497 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 498 | clock->m = clock->m2 + 2; |
| 499 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 500 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 501 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 502 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 503 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 504 | |
| 505 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 506 | } |
| 507 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 508 | static u32 i9xx_dpll_compute_m(struct dpll *dpll) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 509 | { |
| 510 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 511 | } |
| 512 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 513 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 514 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 515 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 516 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 517 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 518 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 519 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 520 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 521 | |
| 522 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 525 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 526 | { |
| 527 | clock->m = clock->m1 * clock->m2; |
| 528 | clock->p = clock->p1 * clock->p2; |
| 529 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 530 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 531 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 532 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 533 | |
| 534 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 535 | } |
| 536 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 537 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 538 | { |
| 539 | clock->m = clock->m1 * clock->m2; |
| 540 | clock->p = clock->p1 * clock->p2; |
| 541 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 542 | return 0; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 543 | clock->vco = DIV_ROUND_CLOSEST_ULL((u64)refclk * clock->m, |
| 544 | clock->n << 22); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 545 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 546 | |
| 547 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 548 | } |
| 549 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 550 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 551 | |
| 552 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 553 | * Returns whether the given set of divisors are valid for a given refclk with |
| 554 | * the given connectors. |
| 555 | */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 556 | static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 557 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 558 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 559 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 560 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 561 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 562 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 563 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 564 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 565 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 566 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 567 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 568 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 569 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 570 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 571 | if (clock->m1 <= clock->m2) |
| 572 | INTELPllInvalid("m1 <= m2\n"); |
| 573 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 574 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 575 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 576 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 577 | INTELPllInvalid("p out of range\n"); |
| 578 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 579 | INTELPllInvalid("m out of range\n"); |
| 580 | } |
| 581 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 582 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 583 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 584 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 585 | * connector, etc., rather than just a single range. |
| 586 | */ |
| 587 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 588 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | |
| 590 | return true; |
| 591 | } |
| 592 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 593 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 594 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 595 | const struct intel_crtc_state *crtc_state, |
| 596 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 597 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 598 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 600 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 601 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 602 | * For LVDS just rely on its current settings for dual-channel. |
| 603 | * We haven't figured out how to reliably set up different |
| 604 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 605 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 606 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 607 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 608 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 609 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | } else { |
| 611 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 612 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 613 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 614 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 615 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 616 | } |
| 617 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 618 | /* |
| 619 | * Returns a set of divisors for the desired target clock with the given |
| 620 | * refclk, or FALSE. The returned values represent the clock equation: |
| 621 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 622 | * |
| 623 | * Target and reference clocks are specified in kHz. |
| 624 | * |
| 625 | * If match_clock is provided, then best_clock P divider must match the P |
| 626 | * divider from @match_clock used for LVDS downclocking. |
| 627 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 628 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 629 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 630 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 631 | int target, int refclk, struct dpll *match_clock, |
| 632 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 633 | { |
| 634 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 635 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 636 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 637 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 638 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 639 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 640 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 641 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 642 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 643 | clock.m1++) { |
| 644 | for (clock.m2 = limit->m2.min; |
| 645 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 646 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 647 | break; |
| 648 | for (clock.n = limit->n.min; |
| 649 | clock.n <= limit->n.max; clock.n++) { |
| 650 | for (clock.p1 = limit->p1.min; |
| 651 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 652 | int this_err; |
| 653 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 654 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 655 | if (!intel_PLL_is_valid(to_i915(dev), |
| 656 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 657 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 658 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 659 | if (match_clock && |
| 660 | clock.p != match_clock->p) |
| 661 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 662 | |
| 663 | this_err = abs(clock.dot - target); |
| 664 | if (this_err < err) { |
| 665 | *best_clock = clock; |
| 666 | err = this_err; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | return (err != target); |
| 674 | } |
| 675 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 676 | /* |
| 677 | * Returns a set of divisors for the desired target clock with the given |
| 678 | * refclk, or FALSE. The returned values represent the clock equation: |
| 679 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 680 | * |
| 681 | * Target and reference clocks are specified in kHz. |
| 682 | * |
| 683 | * If match_clock is provided, then best_clock P divider must match the P |
| 684 | * divider from @match_clock used for LVDS downclocking. |
| 685 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 686 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 687 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 688 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 689 | int target, int refclk, struct dpll *match_clock, |
| 690 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 691 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 692 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 693 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 694 | int err = target; |
| 695 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 696 | memset(best_clock, 0, sizeof(*best_clock)); |
| 697 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 698 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 699 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 700 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 701 | clock.m1++) { |
| 702 | for (clock.m2 = limit->m2.min; |
| 703 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 704 | for (clock.n = limit->n.min; |
| 705 | clock.n <= limit->n.max; clock.n++) { |
| 706 | for (clock.p1 = limit->p1.min; |
| 707 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 708 | int this_err; |
| 709 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 710 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 711 | if (!intel_PLL_is_valid(to_i915(dev), |
| 712 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 713 | &clock)) |
| 714 | continue; |
| 715 | if (match_clock && |
| 716 | clock.p != match_clock->p) |
| 717 | continue; |
| 718 | |
| 719 | this_err = abs(clock.dot - target); |
| 720 | if (this_err < err) { |
| 721 | *best_clock = clock; |
| 722 | err = this_err; |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | return (err != target); |
| 730 | } |
| 731 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 732 | /* |
| 733 | * Returns a set of divisors for the desired target clock with the given |
| 734 | * refclk, or FALSE. The returned values represent the clock equation: |
| 735 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 736 | * |
| 737 | * Target and reference clocks are specified in kHz. |
| 738 | * |
| 739 | * If match_clock is provided, then best_clock P divider must match the P |
| 740 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 741 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 742 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 743 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 744 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 745 | int target, int refclk, struct dpll *match_clock, |
| 746 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 747 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 748 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 749 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 750 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 751 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 752 | /* approximately equals target * 0.00585 */ |
| 753 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 754 | |
| 755 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 756 | |
| 757 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 758 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 759 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 760 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 761 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 762 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 763 | for (clock.m1 = limit->m1.max; |
| 764 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 765 | for (clock.m2 = limit->m2.max; |
| 766 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 767 | for (clock.p1 = limit->p1.max; |
| 768 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 769 | int this_err; |
| 770 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 771 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 772 | if (!intel_PLL_is_valid(to_i915(dev), |
| 773 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 774 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 775 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 776 | |
| 777 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 778 | if (this_err < err_most) { |
| 779 | *best_clock = clock; |
| 780 | err_most = this_err; |
| 781 | max_n = clock.n; |
| 782 | found = true; |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 788 | return found; |
| 789 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 790 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 791 | /* |
| 792 | * Check if the calculated PLL configuration is more optimal compared to the |
| 793 | * best configuration and error found so far. Return the calculated error. |
| 794 | */ |
| 795 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 796 | const struct dpll *calculated_clock, |
| 797 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 798 | unsigned int best_error_ppm, |
| 799 | unsigned int *error_ppm) |
| 800 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 801 | /* |
| 802 | * For CHV ignore the error and consider only the P value. |
| 803 | * Prefer a bigger P value based on HW requirements. |
| 804 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 805 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 806 | *error_ppm = 0; |
| 807 | |
| 808 | return calculated_clock->p > best_clock->p; |
| 809 | } |
| 810 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 811 | if (WARN_ON_ONCE(!target_freq)) |
| 812 | return false; |
| 813 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 814 | *error_ppm = div_u64(1000000ULL * |
| 815 | abs(target_freq - calculated_clock->dot), |
| 816 | target_freq); |
| 817 | /* |
| 818 | * Prefer a better P value over a better (smaller) error if the error |
| 819 | * is small. Ensure this preference for future configurations too by |
| 820 | * setting the error to 0. |
| 821 | */ |
| 822 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 823 | *error_ppm = 0; |
| 824 | |
| 825 | return true; |
| 826 | } |
| 827 | |
| 828 | return *error_ppm + 10 < best_error_ppm; |
| 829 | } |
| 830 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 831 | /* |
| 832 | * Returns a set of divisors for the desired target clock with the given |
| 833 | * refclk, or FALSE. The returned values represent the clock equation: |
| 834 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 835 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 836 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 837 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 838 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 839 | int target, int refclk, struct dpll *match_clock, |
| 840 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 841 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 842 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 843 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 844 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 845 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 846 | /* min update 19.2 MHz */ |
| 847 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 848 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 849 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 850 | target *= 5; /* fast clock */ |
| 851 | |
| 852 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 853 | |
| 854 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 855 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Ville Syrjälä | 811bbf0 | 2013-09-24 21:26:25 +0300 | [diff] [blame] | 856 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
Ville Syrjälä | 889059d | 2013-09-24 21:26:27 +0300 | [diff] [blame] | 857 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
Ville Syrjälä | c1a9ae4 | 2013-09-24 21:26:23 +0300 | [diff] [blame] | 858 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 859 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 860 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 861 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 862 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 863 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 864 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 865 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 866 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 867 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 868 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 869 | if (!intel_PLL_is_valid(to_i915(dev), |
| 870 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 871 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 872 | continue; |
| 873 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 874 | if (!vlv_PLL_is_optimal(dev, target, |
| 875 | &clock, |
| 876 | best_clock, |
| 877 | bestppm, &ppm)) |
| 878 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 879 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 880 | *best_clock = clock; |
| 881 | bestppm = ppm; |
| 882 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | } |
| 886 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 887 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 888 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 889 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 890 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 891 | /* |
| 892 | * Returns a set of divisors for the desired target clock with the given |
| 893 | * refclk, or FALSE. The returned values represent the clock equation: |
| 894 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 895 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 896 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 897 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 898 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 899 | int target, int refclk, struct dpll *match_clock, |
| 900 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 901 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 902 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 903 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 904 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 905 | struct dpll clock; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 906 | u64 m2; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 907 | int found = false; |
| 908 | |
| 909 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 910 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 911 | |
| 912 | /* |
| 913 | * Based on hardware doc, the n always set to 1, and m1 always |
| 914 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 915 | * revisit this because n may not 1 anymore. |
| 916 | */ |
| 917 | clock.n = 1, clock.m1 = 2; |
| 918 | target *= 5; /* fast clock */ |
| 919 | |
| 920 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 921 | for (clock.p2 = limit->p2.p2_fast; |
| 922 | clock.p2 >= limit->p2.p2_slow; |
| 923 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 924 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 925 | |
| 926 | clock.p = clock.p1 * clock.p2; |
| 927 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 928 | m2 = DIV_ROUND_CLOSEST_ULL(((u64)target * clock.p * |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 929 | clock.n) << 22, refclk * clock.m1); |
| 930 | |
| 931 | if (m2 > INT_MAX/clock.m1) |
| 932 | continue; |
| 933 | |
| 934 | clock.m2 = m2; |
| 935 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 936 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 937 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 938 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 939 | continue; |
| 940 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 941 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 942 | best_error_ppm, &error_ppm)) |
| 943 | continue; |
| 944 | |
| 945 | *best_clock = clock; |
| 946 | best_error_ppm = error_ppm; |
| 947 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
| 951 | return found; |
| 952 | } |
| 953 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 954 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 955 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 956 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 957 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 958 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 959 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 960 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 961 | target_clock, refclk, NULL, best_clock); |
| 962 | } |
| 963 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 964 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 965 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 966 | /* Be paranoid as we can arrive here with only partial |
| 967 | * state retrieved from the hardware during setup. |
| 968 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 969 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 970 | * as Haswell has gained clock readout/fastboot support. |
| 971 | * |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 972 | * We can ditch the crtc->primary->state->fb check as soon as we can |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 973 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 974 | * |
| 975 | * FIXME: The intel_crtc->active here should be switched to |
| 976 | * crtc->state->active once we have proper CRTC states wired up |
| 977 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 978 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 979 | return crtc->active && crtc->base.primary->state->fb && |
| 980 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 981 | } |
| 982 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 983 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 984 | enum pipe pipe) |
| 985 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 986 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 987 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 988 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 989 | } |
| 990 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 991 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
| 992 | enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 993 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 994 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 995 | u32 line1, line2; |
| 996 | u32 line_mask; |
| 997 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 998 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 999 | line_mask = DSL_LINEMASK_GEN2; |
| 1000 | else |
| 1001 | line_mask = DSL_LINEMASK_GEN3; |
| 1002 | |
| 1003 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1004 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1005 | line2 = I915_READ(reg) & line_mask; |
| 1006 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1007 | return line1 != line2; |
| 1008 | } |
| 1009 | |
| 1010 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) |
| 1011 | { |
| 1012 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1013 | enum pipe pipe = crtc->pipe; |
| 1014 | |
| 1015 | /* Wait for the display line to settle/start moving */ |
| 1016 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) |
| 1017 | DRM_ERROR("pipe %c scanline %s wait timed out\n", |
| 1018 | pipe_name(pipe), onoff(state)); |
| 1019 | } |
| 1020 | |
| 1021 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) |
| 1022 | { |
| 1023 | wait_for_pipe_scanline_moving(crtc, false); |
| 1024 | } |
| 1025 | |
| 1026 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) |
| 1027 | { |
| 1028 | wait_for_pipe_scanline_moving(crtc, true); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1029 | } |
| 1030 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1031 | static void |
| 1032 | intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1033 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1034 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1035 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1036 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1037 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1038 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1039 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1040 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1041 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1042 | if (intel_wait_for_register(dev_priv, |
| 1043 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1044 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1045 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1046 | } else { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1047 | intel_wait_for_pipe_scanline_stopped(crtc); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1048 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1051 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1052 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1053 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1054 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1055 | u32 val; |
| 1056 | bool cur_state; |
| 1057 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1058 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1059 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1060 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1061 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1062 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1063 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1064 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1065 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1066 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1067 | { |
| 1068 | u32 val; |
| 1069 | bool cur_state; |
| 1070 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1071 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1072 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1073 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1074 | |
| 1075 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1076 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1077 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1078 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1079 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1080 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1081 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1082 | enum pipe pipe, bool state) |
| 1083 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1084 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1085 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1086 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1087 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1088 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1089 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1090 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1091 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1092 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1093 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1094 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1095 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1096 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1097 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1098 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1099 | } |
| 1100 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1101 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1102 | |
| 1103 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1104 | enum pipe pipe, bool state) |
| 1105 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1106 | u32 val; |
| 1107 | bool cur_state; |
| 1108 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1109 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1110 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1111 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1112 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1113 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1114 | } |
| 1115 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1116 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1117 | |
| 1118 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1119 | enum pipe pipe) |
| 1120 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1121 | u32 val; |
| 1122 | |
| 1123 | /* ILK FDI PLL is always enabled */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1124 | if (IS_GEN(dev_priv, 5)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1125 | return; |
| 1126 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1127 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1128 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1129 | return; |
| 1130 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1131 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1132 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1133 | } |
| 1134 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1135 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1136 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1137 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1138 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1139 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1140 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1141 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1142 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1143 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1144 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1145 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1148 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1149 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1150 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1151 | u32 val; |
Ville Syrjälä | 10ed55e | 2018-05-23 17:57:18 +0300 | [diff] [blame] | 1152 | enum pipe panel_pipe = INVALID_PIPE; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1153 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1154 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1155 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1156 | return; |
| 1157 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1158 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1159 | u32 port_sel; |
| 1160 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1161 | pp_reg = PP_CONTROL(0); |
| 1162 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1163 | |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1164 | switch (port_sel) { |
| 1165 | case PANEL_PORT_SELECT_LVDS: |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1166 | intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe); |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1167 | break; |
| 1168 | case PANEL_PORT_SELECT_DPA: |
| 1169 | intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe); |
| 1170 | break; |
| 1171 | case PANEL_PORT_SELECT_DPC: |
| 1172 | intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe); |
| 1173 | break; |
| 1174 | case PANEL_PORT_SELECT_DPD: |
| 1175 | intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe); |
| 1176 | break; |
| 1177 | default: |
| 1178 | MISSING_CASE(port_sel); |
| 1179 | break; |
| 1180 | } |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1181 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1182 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1183 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1184 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1185 | } else { |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1186 | u32 port_sel; |
| 1187 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1188 | pp_reg = PP_CONTROL(0); |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1189 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
| 1190 | |
| 1191 | WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS); |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1192 | intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | val = I915_READ(pp_reg); |
| 1196 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1197 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1198 | locked = false; |
| 1199 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1200 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1201 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1202 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1203 | } |
| 1204 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1205 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1206 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1207 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1208 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1209 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1210 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1211 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 1212 | intel_wakeref_t wakeref; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1213 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1214 | /* we keep both pipes enabled on 830 */ |
| 1215 | if (IS_I830(dev_priv)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1216 | state = true; |
| 1217 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1218 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 1219 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 1220 | if (wakeref) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1221 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1222 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1223 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 1224 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1225 | } else { |
| 1226 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1229 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1230 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1231 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1234 | static void assert_plane(struct intel_plane *plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1235 | { |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 1236 | enum pipe pipe; |
| 1237 | bool cur_state; |
| 1238 | |
| 1239 | cur_state = plane->get_hw_state(plane, &pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1240 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1241 | I915_STATE_WARN(cur_state != state, |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1242 | "%s assertion failure (expected %s, current %s)\n", |
| 1243 | plane->base.name, onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1244 | } |
| 1245 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1246 | #define assert_plane_enabled(p) assert_plane(p, true) |
| 1247 | #define assert_plane_disabled(p) assert_plane(p, false) |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1248 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1249 | static void assert_planes_disabled(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1250 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1251 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1252 | struct intel_plane *plane; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1253 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1254 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
| 1255 | assert_plane_disabled(plane); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1258 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1259 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1260 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1261 | drm_crtc_vblank_put(crtc); |
| 1262 | } |
| 1263 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1264 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1265 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1266 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1267 | u32 val; |
| 1268 | bool enabled; |
| 1269 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1270 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1271 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1272 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1273 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1274 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1277 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1278 | enum pipe pipe, enum port port, |
| 1279 | i915_reg_t dp_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1280 | { |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1281 | enum pipe port_pipe; |
| 1282 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1283 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1284 | state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe); |
| 1285 | |
| 1286 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1287 | "PCH DP %c enabled on transcoder %c, should be disabled\n", |
| 1288 | port_name(port), pipe_name(pipe)); |
| 1289 | |
| 1290 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1291 | "IBX PCH DP %c still using transcoder B\n", |
| 1292 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1296 | enum pipe pipe, enum port port, |
| 1297 | i915_reg_t hdmi_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1298 | { |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1299 | enum pipe port_pipe; |
| 1300 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1301 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1302 | state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe); |
| 1303 | |
| 1304 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1305 | "PCH HDMI %c enabled on transcoder %c, should be disabled\n", |
| 1306 | port_name(port), pipe_name(pipe)); |
| 1307 | |
| 1308 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1309 | "IBX PCH HDMI %c still using transcoder B\n", |
| 1310 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1314 | enum pipe pipe) |
| 1315 | { |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1316 | enum pipe port_pipe; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1317 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1318 | assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B); |
| 1319 | assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C); |
| 1320 | assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1321 | |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1322 | I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) && |
| 1323 | port_pipe == pipe, |
| 1324 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
| 1325 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1326 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1327 | I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) && |
| 1328 | port_pipe == pipe, |
| 1329 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
| 1330 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1331 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 1332 | /* PCH SDVOB multiplex with HDMIB */ |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1333 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB); |
| 1334 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC); |
| 1335 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1338 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1339 | const struct intel_crtc_state *pipe_config) |
| 1340 | { |
| 1341 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1342 | enum pipe pipe = crtc->pipe; |
| 1343 | |
| 1344 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1345 | POSTING_READ(DPLL(pipe)); |
| 1346 | udelay(150); |
| 1347 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1348 | if (intel_wait_for_register(dev_priv, |
| 1349 | DPLL(pipe), |
| 1350 | DPLL_LOCK_VLV, |
| 1351 | DPLL_LOCK_VLV, |
| 1352 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1353 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1354 | } |
| 1355 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1356 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1357 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1358 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1359 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1360 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1361 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1362 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1363 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1364 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1365 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1366 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1367 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1368 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1369 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1370 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1371 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1372 | } |
| 1373 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1374 | |
| 1375 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1376 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1377 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1378 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1379 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1380 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1381 | u32 tmp; |
| 1382 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1383 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1384 | |
| 1385 | /* Enable back the 10bit clock to display controller */ |
| 1386 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1387 | tmp |= DPIO_DCLKP_EN; |
| 1388 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1389 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1390 | mutex_unlock(&dev_priv->sb_lock); |
| 1391 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1392 | /* |
| 1393 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1394 | */ |
| 1395 | udelay(1); |
| 1396 | |
| 1397 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1398 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1399 | |
| 1400 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1401 | if (intel_wait_for_register(dev_priv, |
| 1402 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1403 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1404 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1408 | const struct intel_crtc_state *pipe_config) |
| 1409 | { |
| 1410 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1411 | enum pipe pipe = crtc->pipe; |
| 1412 | |
| 1413 | assert_pipe_disabled(dev_priv, pipe); |
| 1414 | |
| 1415 | /* PLL is protected by panel, make sure we can write it */ |
| 1416 | assert_panel_unlocked(dev_priv, pipe); |
| 1417 | |
| 1418 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1419 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1420 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1421 | if (pipe != PIPE_A) { |
| 1422 | /* |
| 1423 | * WaPixelRepeatModeFixForC0:chv |
| 1424 | * |
| 1425 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1426 | * the value from DPLLBMD to either pipe B or C. |
| 1427 | */ |
Ville Syrjälä | dfa311f | 2017-09-13 17:08:54 +0300 | [diff] [blame] | 1428 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1429 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1430 | I915_WRITE(CBR4_VLV, 0); |
| 1431 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1432 | |
| 1433 | /* |
| 1434 | * DPLLB VGA mode also seems to cause problems. |
| 1435 | * We should always have it disabled. |
| 1436 | */ |
| 1437 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1438 | } else { |
| 1439 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1440 | POSTING_READ(DPLL_MD(pipe)); |
| 1441 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1442 | } |
| 1443 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1444 | static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1445 | { |
| 1446 | struct intel_crtc *crtc; |
| 1447 | int count = 0; |
| 1448 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1449 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1450 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1451 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1452 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1453 | |
| 1454 | return count; |
| 1455 | } |
| 1456 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1457 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
| 1458 | const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1459 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1460 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1461 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1462 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1463 | int i; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1464 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1465 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1466 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1467 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1468 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1469 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1470 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1471 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1472 | if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1473 | /* |
| 1474 | * It appears to be important that we don't enable this |
| 1475 | * for the current pipe before otherwise configuring the |
| 1476 | * PLL. No idea how this should be handled if multiple |
| 1477 | * DVO outputs are enabled simultaneosly. |
| 1478 | */ |
| 1479 | dpll |= DPLL_DVO_2X_MODE; |
| 1480 | I915_WRITE(DPLL(!crtc->pipe), |
| 1481 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1482 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1483 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1484 | /* |
| 1485 | * Apparently we need to have VGA mode enabled prior to changing |
| 1486 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1487 | * dividers, even though the register value does change. |
| 1488 | */ |
| 1489 | I915_WRITE(reg, 0); |
| 1490 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1491 | I915_WRITE(reg, dpll); |
| 1492 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1493 | /* Wait for the clocks to stabilize. */ |
| 1494 | POSTING_READ(reg); |
| 1495 | udelay(150); |
| 1496 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1497 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1498 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1499 | crtc_state->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1500 | } else { |
| 1501 | /* The pixel multiplier can only be updated once the |
| 1502 | * DPLL is enabled and the clocks are stable. |
| 1503 | * |
| 1504 | * So write it again. |
| 1505 | */ |
| 1506 | I915_WRITE(reg, dpll); |
| 1507 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1508 | |
| 1509 | /* We do this three times for luck */ |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1510 | for (i = 0; i < 3; i++) { |
| 1511 | I915_WRITE(reg, dpll); |
| 1512 | POSTING_READ(reg); |
| 1513 | udelay(150); /* wait for warmup */ |
| 1514 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1515 | } |
| 1516 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1517 | static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1518 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1519 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1520 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1521 | enum pipe pipe = crtc->pipe; |
| 1522 | |
| 1523 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1524 | if (IS_I830(dev_priv) && |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1525 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1526 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1527 | I915_WRITE(DPLL(PIPE_B), |
| 1528 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1529 | I915_WRITE(DPLL(PIPE_A), |
| 1530 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1531 | } |
| 1532 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1533 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1534 | if (IS_I830(dev_priv)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1535 | return; |
| 1536 | |
| 1537 | /* Make sure the pipe isn't still relying on us */ |
| 1538 | assert_pipe_disabled(dev_priv, pipe); |
| 1539 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1540 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1541 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1544 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1545 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1546 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1547 | |
| 1548 | /* Make sure the pipe isn't still relying on us */ |
| 1549 | assert_pipe_disabled(dev_priv, pipe); |
| 1550 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1551 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1552 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1553 | if (pipe != PIPE_A) |
| 1554 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1555 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1556 | I915_WRITE(DPLL(pipe), val); |
| 1557 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1561 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1562 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1563 | u32 val; |
| 1564 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1565 | /* Make sure the pipe isn't still relying on us */ |
| 1566 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1567 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1568 | val = DPLL_SSC_REF_CLK_CHV | |
| 1569 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1570 | if (pipe != PIPE_A) |
| 1571 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1572 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1573 | I915_WRITE(DPLL(pipe), val); |
| 1574 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1575 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1576 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1577 | |
| 1578 | /* Disable 10bit clock to display controller */ |
| 1579 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1580 | val &= ~DPIO_DCLKP_EN; |
| 1581 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1582 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1583 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1586 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1587 | struct intel_digital_port *dport, |
| 1588 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1589 | { |
| 1590 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1591 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1592 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1593 | switch (dport->base.port) { |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1594 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1595 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1596 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1597 | break; |
| 1598 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1599 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1600 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1601 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1602 | break; |
| 1603 | case PORT_D: |
| 1604 | port_mask = DPLL_PORTD_READY_MASK; |
| 1605 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1606 | break; |
| 1607 | default: |
| 1608 | BUG(); |
| 1609 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1610 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1611 | if (intel_wait_for_register(dev_priv, |
| 1612 | dpll_reg, port_mask, expected_mask, |
| 1613 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1614 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1615 | port_name(dport->base.port), |
| 1616 | I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1619 | static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1620 | { |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1621 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1622 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1623 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1624 | i915_reg_t reg; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 1625 | u32 val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1626 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1627 | /* Make sure PCH DPLL is enabled */ |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1628 | assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1629 | |
| 1630 | /* FDI must be feeding us bits for PCH ports */ |
| 1631 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1632 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1633 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1634 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1635 | /* Workaround: Set the timing override bit before enabling the |
| 1636 | * pch transcoder. */ |
| 1637 | reg = TRANS_CHICKEN2(pipe); |
| 1638 | val = I915_READ(reg); |
| 1639 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1640 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1641 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1642 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1643 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1644 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1645 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1646 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1647 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1648 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1649 | * Make the BPC in transcoder be consistent with |
| 1650 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1651 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1652 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1653 | val &= ~PIPECONF_BPC_MASK; |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1654 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1655 | val |= PIPECONF_8BPC; |
| 1656 | else |
| 1657 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1658 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1659 | |
| 1660 | val &= ~TRANS_INTERLACE_MASK; |
| 1661 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1662 | if (HAS_PCH_IBX(dev_priv) && |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1663 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1664 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1665 | else |
| 1666 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1667 | else |
| 1668 | val |= TRANS_PROGRESSIVE; |
| 1669 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1670 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1671 | if (intel_wait_for_register(dev_priv, |
| 1672 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1673 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1674 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1675 | } |
| 1676 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1677 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1678 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1679 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1680 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1681 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1682 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1683 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1684 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1685 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1686 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1687 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1688 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1689 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1690 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1691 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1692 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1693 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1694 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1695 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1696 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1697 | else |
| 1698 | val |= TRANS_PROGRESSIVE; |
| 1699 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1700 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1701 | if (intel_wait_for_register(dev_priv, |
| 1702 | LPT_TRANSCONF, |
| 1703 | TRANS_STATE_ENABLE, |
| 1704 | TRANS_STATE_ENABLE, |
| 1705 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1706 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1707 | } |
| 1708 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1709 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1710 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1711 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1712 | i915_reg_t reg; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 1713 | u32 val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1714 | |
| 1715 | /* FDI relies on the transcoder */ |
| 1716 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1717 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1718 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1719 | /* Ports must be off as well */ |
| 1720 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1721 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1722 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1723 | val = I915_READ(reg); |
| 1724 | val &= ~TRANS_ENABLE; |
| 1725 | I915_WRITE(reg, val); |
| 1726 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1727 | if (intel_wait_for_register(dev_priv, |
| 1728 | reg, TRANS_STATE_ENABLE, 0, |
| 1729 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1730 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1731 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1732 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1733 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1734 | reg = TRANS_CHICKEN2(pipe); |
| 1735 | val = I915_READ(reg); |
| 1736 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1737 | I915_WRITE(reg, val); |
| 1738 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1739 | } |
| 1740 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1741 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1742 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1743 | u32 val; |
| 1744 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1745 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1746 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1747 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1748 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1749 | if (intel_wait_for_register(dev_priv, |
| 1750 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1751 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1752 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1753 | |
| 1754 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1755 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1756 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1757 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1760 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1761 | { |
| 1762 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1763 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1764 | if (HAS_PCH_LPT(dev_priv)) |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1765 | return PIPE_A; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1766 | else |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1767 | return crtc->pipe; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1768 | } |
| 1769 | |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 1770 | static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state) |
| 1771 | { |
| 1772 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1773 | |
| 1774 | /* |
| 1775 | * On i965gm the hardware frame counter reads |
| 1776 | * zero when the TV encoder is enabled :( |
| 1777 | */ |
| 1778 | if (IS_I965GM(dev_priv) && |
| 1779 | (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT))) |
| 1780 | return 0; |
| 1781 | |
| 1782 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 1783 | return 0xffffffff; /* full 32 bit counter */ |
| 1784 | else if (INTEL_GEN(dev_priv) >= 3) |
| 1785 | return 0xffffff; /* only 24 bits of frame count */ |
| 1786 | else |
| 1787 | return 0; /* Gen2 doesn't have a hardware frame counter */ |
| 1788 | } |
| 1789 | |
| 1790 | static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state) |
| 1791 | { |
| 1792 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1793 | |
| 1794 | drm_crtc_set_max_vblank_count(&crtc->base, |
| 1795 | intel_crtc_max_vblank_count(crtc_state)); |
| 1796 | drm_crtc_vblank_on(&crtc->base); |
| 1797 | } |
| 1798 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1799 | static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1800 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1801 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1802 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1803 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1804 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1805 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1806 | u32 val; |
| 1807 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1808 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1809 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1810 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1811 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1812 | /* |
| 1813 | * A pipe without a PLL won't actually be able to drive bits from |
| 1814 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1815 | * need the check. |
| 1816 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 1817 | if (HAS_GMCH(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1818 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1819 | assert_dsi_pll_enabled(dev_priv); |
| 1820 | else |
| 1821 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1822 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1823 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1824 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1825 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1826 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1827 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1828 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1829 | } |
| 1830 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1831 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1832 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1833 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1834 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1835 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1836 | /* we keep both pipes enabled on 830 */ |
| 1837 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1838 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1839 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1840 | |
| 1841 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1842 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1843 | |
| 1844 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1845 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1846 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1847 | * resets to its proper value. That also messes up the frame count |
| 1848 | * when it's derived from the timestamps. So let's wait for the |
| 1849 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1850 | */ |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 1851 | if (intel_crtc_max_vblank_count(new_crtc_state) == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1852 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1853 | } |
| 1854 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1855 | static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1856 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1857 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1858 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1859 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1860 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1861 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1862 | u32 val; |
| 1863 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1864 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1865 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1866 | /* |
| 1867 | * Make sure planes won't keep trying to pump pixels to us, |
| 1868 | * or we might hang the display. |
| 1869 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1870 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1871 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1872 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1873 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1874 | if ((val & PIPECONF_ENABLE) == 0) |
| 1875 | return; |
| 1876 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1877 | /* |
| 1878 | * Double wide has implications for planes |
| 1879 | * so best keep it disabled when not needed. |
| 1880 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1881 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1882 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1883 | |
| 1884 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1885 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1886 | val &= ~PIPECONF_ENABLE; |
| 1887 | |
| 1888 | I915_WRITE(reg, val); |
| 1889 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1890 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1891 | } |
| 1892 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1893 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1894 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1895 | return IS_GEN(dev_priv, 2) ? 2048 : 4096; |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1896 | } |
| 1897 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1898 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1899 | intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1900 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1901 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1902 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1903 | |
| 1904 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1905 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1906 | return cpp; |
| 1907 | case I915_FORMAT_MOD_X_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1908 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1909 | return 128; |
| 1910 | else |
| 1911 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1912 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1913 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1914 | return 128; |
| 1915 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1916 | case I915_FORMAT_MOD_Y_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1917 | if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv)) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1918 | return 128; |
| 1919 | else |
| 1920 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1921 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1922 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1923 | return 128; |
| 1924 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1925 | case I915_FORMAT_MOD_Yf_TILED: |
| 1926 | switch (cpp) { |
| 1927 | case 1: |
| 1928 | return 64; |
| 1929 | case 2: |
| 1930 | case 4: |
| 1931 | return 128; |
| 1932 | case 8: |
| 1933 | case 16: |
| 1934 | return 256; |
| 1935 | default: |
| 1936 | MISSING_CASE(cpp); |
| 1937 | return cpp; |
| 1938 | } |
| 1939 | break; |
| 1940 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1941 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1942 | return cpp; |
| 1943 | } |
| 1944 | } |
| 1945 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1946 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1947 | intel_tile_height(const struct drm_framebuffer *fb, int color_plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1948 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1949 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1950 | return 1; |
| 1951 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1952 | return intel_tile_size(to_i915(fb->dev)) / |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1953 | intel_tile_width_bytes(fb, color_plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1956 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1957 | static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1958 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1959 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1960 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1961 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane); |
| 1962 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1963 | |
| 1964 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1965 | *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1966 | } |
| 1967 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1968 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1969 | intel_fb_align_height(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1970 | int color_plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1971 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1972 | unsigned int tile_height = intel_tile_height(fb, color_plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1973 | |
| 1974 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1975 | } |
| 1976 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1977 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1978 | { |
| 1979 | unsigned int size = 0; |
| 1980 | int i; |
| 1981 | |
| 1982 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1983 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1984 | |
| 1985 | return size; |
| 1986 | } |
| 1987 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 1988 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 1989 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 1990 | const struct drm_framebuffer *fb, |
| 1991 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 1992 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1993 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 1994 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1995 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 1996 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 2000 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 2001 | { |
| 2002 | if (IS_I830(dev_priv)) |
| 2003 | return 16 * 1024; |
| 2004 | else if (IS_I85X(dev_priv)) |
| 2005 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 2006 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 2007 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 2008 | else |
| 2009 | return 4 * 1024; |
| 2010 | } |
| 2011 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2012 | static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2013 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 2014 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2015 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 2016 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2017 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2018 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 2019 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2020 | return 4 * 1024; |
| 2021 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2022 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2023 | } |
| 2024 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2025 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2026 | int color_plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2027 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2028 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2029 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2030 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2031 | if (color_plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2032 | return 4096; |
| 2033 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2034 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2035 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2036 | return intel_linear_alignment(dev_priv); |
| 2037 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2038 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2039 | return 256 * 1024; |
| 2040 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2041 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2042 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2043 | case I915_FORMAT_MOD_Y_TILED: |
| 2044 | case I915_FORMAT_MOD_Yf_TILED: |
| 2045 | return 1 * 1024 * 1024; |
| 2046 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2047 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2048 | return 0; |
| 2049 | } |
| 2050 | } |
| 2051 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2052 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2053 | { |
| 2054 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2055 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2056 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2057 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2060 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2061 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2062 | const struct i915_ggtt_view *view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2063 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2064 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2065 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2066 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2067 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2068 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2069 | intel_wakeref_t wakeref; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2070 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2071 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2072 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2073 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2074 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2075 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2076 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2077 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2078 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2079 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2080 | * we should always have valid PTE following the scanout preventing |
| 2081 | * the VT-d warning. |
| 2082 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2083 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2084 | alignment = 256 * 1024; |
| 2085 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2086 | /* |
| 2087 | * Global gtt pte registers are special registers which actually forward |
| 2088 | * writes to a chunk of system memory. Which means that there is no risk |
| 2089 | * that the register values disappear as soon as we call |
| 2090 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2091 | * pin/unpin/fence and not more. |
| 2092 | */ |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2093 | wakeref = intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2094 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2095 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2096 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2097 | pinctl = 0; |
| 2098 | |
| 2099 | /* Valleyview is definitely limited to scanning out the first |
| 2100 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2101 | * g4x display engine and that all earlier gen are similarly |
| 2102 | * limited. Testing suggests that it is a little more |
| 2103 | * complicated than this. For example, Cherryview appears quite |
| 2104 | * happy to scanout from anywhere within its global aperture. |
| 2105 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 2106 | if (HAS_GMCH(dev_priv)) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2107 | pinctl |= PIN_MAPPABLE; |
| 2108 | |
| 2109 | vma = i915_gem_object_pin_to_display_plane(obj, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2110 | alignment, view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2111 | if (IS_ERR(vma)) |
| 2112 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2113 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2114 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2115 | int ret; |
| 2116 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2117 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2118 | * fence, whereas 965+ only requires a fence if using |
| 2119 | * framebuffer compression. For simplicity, we always, when |
| 2120 | * possible, install a fence as the cost is not that onerous. |
| 2121 | * |
| 2122 | * If we fail to fence the tiled scanout, then either the |
| 2123 | * modeset will reject the change (which is highly unlikely as |
| 2124 | * the affected systems, all but one, do not have unmappable |
| 2125 | * space) or we will not be able to enable full powersaving |
| 2126 | * techniques (also likely not to apply due to various limits |
| 2127 | * FBC and the like impose on the size of the buffer, which |
| 2128 | * presumably we violated anyway with this unmappable buffer). |
| 2129 | * Anyway, it is presumably better to stumble onwards with |
| 2130 | * something and try to run the system in a "less than optimal" |
| 2131 | * mode that matches the user configuration. |
| 2132 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2133 | ret = i915_vma_pin_fence(vma); |
| 2134 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2135 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2136 | vma = ERR_PTR(ret); |
| 2137 | goto err; |
| 2138 | } |
| 2139 | |
| 2140 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2141 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2142 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2143 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2144 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2145 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2146 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2147 | |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2148 | intel_runtime_pm_put(dev_priv, wakeref); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2149 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2150 | } |
| 2151 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2152 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2153 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2154 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2155 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2156 | if (flags & PLANE_HAS_FENCE) |
| 2157 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2158 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2159 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2162 | static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane, |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2163 | unsigned int rotation) |
| 2164 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2165 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2166 | return to_intel_framebuffer(fb)->rotated[color_plane].pitch; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2167 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2168 | return fb->pitches[color_plane]; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2169 | } |
| 2170 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2171 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2172 | * Convert the x/y offsets into a linear offset. |
| 2173 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2174 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2175 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2176 | */ |
| 2177 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2178 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2179 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2180 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2181 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2182 | unsigned int cpp = fb->format->cpp[color_plane]; |
| 2183 | unsigned int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2184 | |
| 2185 | return y * pitch + x * cpp; |
| 2186 | } |
| 2187 | |
| 2188 | /* |
| 2189 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2190 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2191 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2192 | */ |
| 2193 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2194 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2195 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2196 | |
| 2197 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2198 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2199 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2200 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2201 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2202 | *x += intel_fb->rotated[color_plane].x; |
| 2203 | *y += intel_fb->rotated[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2204 | } else { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2205 | *x += intel_fb->normal[color_plane].x; |
| 2206 | *y += intel_fb->normal[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2210 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2211 | unsigned int tile_width, |
| 2212 | unsigned int tile_height, |
| 2213 | unsigned int tile_size, |
| 2214 | unsigned int pitch_tiles, |
| 2215 | u32 old_offset, |
| 2216 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2217 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2218 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2219 | unsigned int tiles; |
| 2220 | |
| 2221 | WARN_ON(old_offset & (tile_size - 1)); |
| 2222 | WARN_ON(new_offset & (tile_size - 1)); |
| 2223 | WARN_ON(new_offset > old_offset); |
| 2224 | |
| 2225 | tiles = (old_offset - new_offset) / tile_size; |
| 2226 | |
| 2227 | *y += tiles / pitch_tiles * tile_height; |
| 2228 | *x += tiles % pitch_tiles * tile_width; |
| 2229 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2230 | /* minimize x in case it got needlessly big */ |
| 2231 | *y += *x / pitch_pixels * tile_height; |
| 2232 | *x %= pitch_pixels; |
| 2233 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2234 | return new_offset; |
| 2235 | } |
| 2236 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2237 | static bool is_surface_linear(u64 modifier, int color_plane) |
| 2238 | { |
| 2239 | return modifier == DRM_FORMAT_MOD_LINEAR; |
| 2240 | } |
| 2241 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2242 | static u32 intel_adjust_aligned_offset(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2243 | const struct drm_framebuffer *fb, |
| 2244 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2245 | unsigned int rotation, |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2246 | unsigned int pitch, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2247 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2248 | { |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2249 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2250 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2251 | |
| 2252 | WARN_ON(new_offset > old_offset); |
| 2253 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2254 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2255 | unsigned int tile_size, tile_width, tile_height; |
| 2256 | unsigned int pitch_tiles; |
| 2257 | |
| 2258 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2259 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2260 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2261 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2262 | pitch_tiles = pitch / tile_height; |
| 2263 | swap(tile_width, tile_height); |
| 2264 | } else { |
| 2265 | pitch_tiles = pitch / (tile_width * cpp); |
| 2266 | } |
| 2267 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2268 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2269 | tile_size, pitch_tiles, |
| 2270 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2271 | } else { |
| 2272 | old_offset += *y * pitch + *x * cpp; |
| 2273 | |
| 2274 | *y = (old_offset - new_offset) / pitch; |
| 2275 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2276 | } |
| 2277 | |
| 2278 | return new_offset; |
| 2279 | } |
| 2280 | |
| 2281 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2282 | * Adjust the tile offset by moving the difference into |
| 2283 | * the x/y offsets. |
| 2284 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2285 | static u32 intel_plane_adjust_aligned_offset(int *x, int *y, |
| 2286 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2287 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2288 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2289 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2290 | return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2291 | state->base.rotation, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2292 | state->color_plane[color_plane].stride, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2293 | old_offset, new_offset); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /* |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2297 | * Computes the aligned offset to the base tile and adjusts |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2298 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2299 | * |
| 2300 | * In the 90/270 rotated case, x and y are assumed |
| 2301 | * to be already rotated to match the rotated GTT view, and |
| 2302 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2303 | * |
| 2304 | * This function is used when computing the derived information |
| 2305 | * under intel_framebuffer, so using any of that information |
| 2306 | * here is not allowed. Anything under drm_framebuffer can be |
| 2307 | * used. This is why the user has to pass in the pitch since it |
| 2308 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2309 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2310 | static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv, |
| 2311 | int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2312 | const struct drm_framebuffer *fb, |
| 2313 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2314 | unsigned int pitch, |
| 2315 | unsigned int rotation, |
| 2316 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2317 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2318 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2319 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2320 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2321 | if (alignment) |
| 2322 | alignment--; |
| 2323 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2324 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2325 | unsigned int tile_size, tile_width, tile_height; |
| 2326 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2327 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2328 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2329 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2330 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2331 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2332 | pitch_tiles = pitch / tile_height; |
| 2333 | swap(tile_width, tile_height); |
| 2334 | } else { |
| 2335 | pitch_tiles = pitch / (tile_width * cpp); |
| 2336 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2337 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2338 | tile_rows = *y / tile_height; |
| 2339 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2340 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2341 | tiles = *x / tile_width; |
| 2342 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2343 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2344 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2345 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2346 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2347 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2348 | tile_size, pitch_tiles, |
| 2349 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2350 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2351 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2352 | offset_aligned = offset & ~alignment; |
| 2353 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2354 | *y = (offset & alignment) / pitch; |
| 2355 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2356 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2357 | |
| 2358 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2359 | } |
| 2360 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2361 | static u32 intel_plane_compute_aligned_offset(int *x, int *y, |
| 2362 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2363 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2364 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2365 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2366 | struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev); |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2367 | const struct drm_framebuffer *fb = state->base.fb; |
| 2368 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2369 | int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2370 | u32 alignment; |
| 2371 | |
| 2372 | if (intel_plane->id == PLANE_CURSOR) |
| 2373 | alignment = intel_cursor_alignment(dev_priv); |
| 2374 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2375 | alignment = intel_surf_alignment(fb, color_plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2376 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2377 | return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2378 | pitch, rotation, alignment); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2379 | } |
| 2380 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2381 | /* Convert the fb->offset[] into x/y offsets */ |
| 2382 | static int intel_fb_offset_to_xy(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2383 | const struct drm_framebuffer *fb, |
| 2384 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2385 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2386 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2387 | unsigned int height; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2388 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2389 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2390 | fb->offsets[color_plane] % intel_tile_size(dev_priv)) { |
| 2391 | DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n", |
| 2392 | fb->offsets[color_plane], color_plane); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2393 | return -EINVAL; |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | height = drm_framebuffer_plane_height(fb->height, fb, color_plane); |
| 2397 | height = ALIGN(height, intel_tile_height(fb, color_plane)); |
| 2398 | |
| 2399 | /* Catch potential overflows early */ |
| 2400 | if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]), |
| 2401 | fb->offsets[color_plane])) { |
| 2402 | DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n", |
| 2403 | fb->offsets[color_plane], fb->pitches[color_plane], |
| 2404 | color_plane); |
| 2405 | return -ERANGE; |
| 2406 | } |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2407 | |
| 2408 | *x = 0; |
| 2409 | *y = 0; |
| 2410 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2411 | intel_adjust_aligned_offset(x, y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2412 | fb, color_plane, DRM_MODE_ROTATE_0, |
| 2413 | fb->pitches[color_plane], |
| 2414 | fb->offsets[color_plane], 0); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2415 | |
| 2416 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2417 | } |
| 2418 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 2419 | static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier) |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2420 | { |
| 2421 | switch (fb_modifier) { |
| 2422 | case I915_FORMAT_MOD_X_TILED: |
| 2423 | return I915_TILING_X; |
| 2424 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2425 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2426 | return I915_TILING_Y; |
| 2427 | default: |
| 2428 | return I915_TILING_NONE; |
| 2429 | } |
| 2430 | } |
| 2431 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2432 | /* |
| 2433 | * From the Sky Lake PRM: |
| 2434 | * "The Color Control Surface (CCS) contains the compression status of |
| 2435 | * the cache-line pairs. The compression state of the cache-line pair |
| 2436 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2437 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2438 | * cache-line-pairs. CCS is always Y tiled." |
| 2439 | * |
| 2440 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2441 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2442 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2443 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2444 | * main surface. |
| 2445 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2446 | static const struct drm_format_info ccs_formats[] = { |
| 2447 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2448 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2449 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2450 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2451 | }; |
| 2452 | |
| 2453 | static const struct drm_format_info * |
| 2454 | lookup_format_info(const struct drm_format_info formats[], |
| 2455 | int num_formats, u32 format) |
| 2456 | { |
| 2457 | int i; |
| 2458 | |
| 2459 | for (i = 0; i < num_formats; i++) { |
| 2460 | if (formats[i].format == format) |
| 2461 | return &formats[i]; |
| 2462 | } |
| 2463 | |
| 2464 | return NULL; |
| 2465 | } |
| 2466 | |
| 2467 | static const struct drm_format_info * |
| 2468 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2469 | { |
| 2470 | switch (cmd->modifier[0]) { |
| 2471 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2472 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2473 | return lookup_format_info(ccs_formats, |
| 2474 | ARRAY_SIZE(ccs_formats), |
| 2475 | cmd->pixel_format); |
| 2476 | default: |
| 2477 | return NULL; |
| 2478 | } |
| 2479 | } |
| 2480 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2481 | bool is_ccs_modifier(u64 modifier) |
| 2482 | { |
| 2483 | return modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2484 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 2485 | } |
| 2486 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2487 | static int |
| 2488 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2489 | struct drm_framebuffer *fb) |
| 2490 | { |
| 2491 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2492 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2493 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2494 | u32 gtt_offset_rotated = 0; |
| 2495 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2496 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2497 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2498 | |
| 2499 | for (i = 0; i < num_planes; i++) { |
| 2500 | unsigned int width, height; |
| 2501 | unsigned int cpp, size; |
| 2502 | u32 offset; |
| 2503 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2504 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2505 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2506 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2507 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2508 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2509 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2510 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2511 | if (ret) { |
| 2512 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2513 | i, fb->offsets[i]); |
| 2514 | return ret; |
| 2515 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2516 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2517 | if (is_ccs_modifier(fb->modifier) && i == 1) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2518 | int hsub = fb->format->hsub; |
| 2519 | int vsub = fb->format->vsub; |
| 2520 | int tile_width, tile_height; |
| 2521 | int main_x, main_y; |
| 2522 | int ccs_x, ccs_y; |
| 2523 | |
| 2524 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2525 | tile_width *= hsub; |
| 2526 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2527 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2528 | ccs_x = (x * hsub) % tile_width; |
| 2529 | ccs_y = (y * vsub) % tile_height; |
| 2530 | main_x = intel_fb->normal[0].x % tile_width; |
| 2531 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2532 | |
| 2533 | /* |
| 2534 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2535 | * x/y offsets must match between CCS and the main surface. |
| 2536 | */ |
| 2537 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2538 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2539 | main_x, main_y, |
| 2540 | ccs_x, ccs_y, |
| 2541 | intel_fb->normal[0].x, |
| 2542 | intel_fb->normal[0].y, |
| 2543 | x, y); |
| 2544 | return -EINVAL; |
| 2545 | } |
| 2546 | } |
| 2547 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2548 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2549 | * The fence (if used) is aligned to the start of the object |
| 2550 | * so having the framebuffer wrap around across the edge of the |
| 2551 | * fenced region doesn't really work. We have no API to configure |
| 2552 | * the fence start offset within the object (nor could we probably |
| 2553 | * on gen2/3). So it's just easier if we just require that the |
| 2554 | * fb layout agrees with the fence layout. We already check that the |
| 2555 | * fb stride matches the fence stride elsewhere. |
| 2556 | */ |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2557 | if (i == 0 && i915_gem_object_is_tiled(obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2558 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2559 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2560 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2561 | return -EINVAL; |
| 2562 | } |
| 2563 | |
| 2564 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2565 | * First pixel of the framebuffer from |
| 2566 | * the start of the normal gtt mapping. |
| 2567 | */ |
| 2568 | intel_fb->normal[i].x = x; |
| 2569 | intel_fb->normal[i].y = y; |
| 2570 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2571 | offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i, |
| 2572 | fb->pitches[i], |
| 2573 | DRM_MODE_ROTATE_0, |
| 2574 | tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2575 | offset /= tile_size; |
| 2576 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2577 | if (!is_surface_linear(fb->modifier, i)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2578 | unsigned int tile_width, tile_height; |
| 2579 | unsigned int pitch_tiles; |
| 2580 | struct drm_rect r; |
| 2581 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2582 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2583 | |
| 2584 | rot_info->plane[i].offset = offset; |
| 2585 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2586 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2587 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2588 | |
| 2589 | intel_fb->rotated[i].pitch = |
| 2590 | rot_info->plane[i].height * tile_height; |
| 2591 | |
| 2592 | /* how many tiles does this plane need */ |
| 2593 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2594 | /* |
| 2595 | * If the plane isn't horizontally tile aligned, |
| 2596 | * we need one more tile. |
| 2597 | */ |
| 2598 | if (x != 0) |
| 2599 | size++; |
| 2600 | |
| 2601 | /* rotate the x/y offsets to match the GTT view */ |
| 2602 | r.x1 = x; |
| 2603 | r.y1 = y; |
| 2604 | r.x2 = x + width; |
| 2605 | r.y2 = y + height; |
| 2606 | drm_rect_rotate(&r, |
| 2607 | rot_info->plane[i].width * tile_width, |
| 2608 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2609 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2610 | x = r.x1; |
| 2611 | y = r.y1; |
| 2612 | |
| 2613 | /* rotate the tile dimensions to match the GTT view */ |
| 2614 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2615 | swap(tile_width, tile_height); |
| 2616 | |
| 2617 | /* |
| 2618 | * We only keep the x/y offsets, so push all of the |
| 2619 | * gtt offset into the x/y offsets. |
| 2620 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2621 | intel_adjust_tile_offset(&x, &y, |
| 2622 | tile_width, tile_height, |
| 2623 | tile_size, pitch_tiles, |
| 2624 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2625 | |
| 2626 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2627 | |
| 2628 | /* |
| 2629 | * First pixel of the framebuffer from |
| 2630 | * the start of the rotated gtt mapping. |
| 2631 | */ |
| 2632 | intel_fb->rotated[i].x = x; |
| 2633 | intel_fb->rotated[i].y = y; |
| 2634 | } else { |
| 2635 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2636 | x * cpp, tile_size); |
| 2637 | } |
| 2638 | |
| 2639 | /* how many tiles in total needed in the bo */ |
| 2640 | max_size = max(max_size, offset + size); |
| 2641 | } |
| 2642 | |
Ville Syrjälä | 4e05047 | 2018-09-12 21:04:43 +0300 | [diff] [blame] | 2643 | if (mul_u32_u32(max_size, tile_size) > obj->base.size) { |
| 2644 | DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n", |
| 2645 | mul_u32_u32(max_size, tile_size), obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2646 | return -EINVAL; |
| 2647 | } |
| 2648 | |
| 2649 | return 0; |
| 2650 | } |
| 2651 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2652 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2653 | { |
| 2654 | switch (format) { |
| 2655 | case DISPPLANE_8BPP: |
| 2656 | return DRM_FORMAT_C8; |
| 2657 | case DISPPLANE_BGRX555: |
| 2658 | return DRM_FORMAT_XRGB1555; |
| 2659 | case DISPPLANE_BGRX565: |
| 2660 | return DRM_FORMAT_RGB565; |
| 2661 | default: |
| 2662 | case DISPPLANE_BGRX888: |
| 2663 | return DRM_FORMAT_XRGB8888; |
| 2664 | case DISPPLANE_RGBX888: |
| 2665 | return DRM_FORMAT_XBGR8888; |
| 2666 | case DISPPLANE_BGRX101010: |
| 2667 | return DRM_FORMAT_XRGB2101010; |
| 2668 | case DISPPLANE_RGBX101010: |
| 2669 | return DRM_FORMAT_XBGR2101010; |
| 2670 | } |
| 2671 | } |
| 2672 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2673 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2674 | { |
| 2675 | switch (format) { |
| 2676 | case PLANE_CTL_FORMAT_RGB_565: |
| 2677 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2678 | case PLANE_CTL_FORMAT_NV12: |
| 2679 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2680 | default: |
| 2681 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2682 | if (rgb_order) { |
| 2683 | if (alpha) |
| 2684 | return DRM_FORMAT_ABGR8888; |
| 2685 | else |
| 2686 | return DRM_FORMAT_XBGR8888; |
| 2687 | } else { |
| 2688 | if (alpha) |
| 2689 | return DRM_FORMAT_ARGB8888; |
| 2690 | else |
| 2691 | return DRM_FORMAT_XRGB8888; |
| 2692 | } |
| 2693 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2694 | if (rgb_order) |
| 2695 | return DRM_FORMAT_XBGR2101010; |
| 2696 | else |
| 2697 | return DRM_FORMAT_XRGB2101010; |
| 2698 | } |
| 2699 | } |
| 2700 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2701 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2702 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2703 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2704 | { |
| 2705 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2706 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2707 | struct drm_i915_gem_object *obj = NULL; |
| 2708 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2709 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2710 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2711 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2712 | PAGE_SIZE); |
| 2713 | |
| 2714 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2715 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2716 | if (plane_config->size == 0) |
| 2717 | return false; |
| 2718 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2719 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2720 | * important and we should probably use that space with FBC or other |
| 2721 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2722 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2723 | return false; |
| 2724 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2725 | switch (fb->modifier) { |
| 2726 | case DRM_FORMAT_MOD_LINEAR: |
| 2727 | case I915_FORMAT_MOD_X_TILED: |
| 2728 | case I915_FORMAT_MOD_Y_TILED: |
| 2729 | break; |
| 2730 | default: |
| 2731 | DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n", |
| 2732 | fb->modifier); |
| 2733 | return false; |
| 2734 | } |
| 2735 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2736 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2737 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2738 | base_aligned, |
| 2739 | base_aligned, |
| 2740 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2741 | mutex_unlock(&dev->struct_mutex); |
| 2742 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2743 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2744 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2745 | switch (plane_config->tiling) { |
| 2746 | case I915_TILING_NONE: |
| 2747 | break; |
| 2748 | case I915_TILING_X: |
| 2749 | case I915_TILING_Y: |
| 2750 | obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling; |
| 2751 | break; |
| 2752 | default: |
| 2753 | MISSING_CASE(plane_config->tiling); |
| 2754 | return false; |
| 2755 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2756 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2757 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2758 | mode_cmd.width = fb->width; |
| 2759 | mode_cmd.height = fb->height; |
| 2760 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2761 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2762 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2763 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2764 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2765 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2766 | goto out_unref_obj; |
| 2767 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2768 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2769 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2770 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2771 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2772 | |
| 2773 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2774 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2775 | return false; |
| 2776 | } |
| 2777 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2778 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2779 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2780 | struct intel_plane_state *plane_state, |
| 2781 | bool visible) |
| 2782 | { |
| 2783 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2784 | |
| 2785 | plane_state->base.visible = visible; |
| 2786 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2787 | if (visible) |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2788 | crtc_state->base.plane_mask |= drm_plane_mask(&plane->base); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2789 | else |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2790 | crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2791 | } |
| 2792 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2793 | static void fixup_active_planes(struct intel_crtc_state *crtc_state) |
| 2794 | { |
| 2795 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2796 | struct drm_plane *plane; |
| 2797 | |
| 2798 | /* |
| 2799 | * Active_planes aliases if multiple "primary" or cursor planes |
| 2800 | * have been used on the same (or wrong) pipe. plane_mask uses |
| 2801 | * unique ids, hence we can use that to reconstruct active_planes. |
| 2802 | */ |
| 2803 | crtc_state->active_planes = 0; |
| 2804 | |
| 2805 | drm_for_each_plane_mask(plane, &dev_priv->drm, |
| 2806 | crtc_state->base.plane_mask) |
| 2807 | crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); |
| 2808 | } |
| 2809 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2810 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2811 | struct intel_plane *plane) |
| 2812 | { |
| 2813 | struct intel_crtc_state *crtc_state = |
| 2814 | to_intel_crtc_state(crtc->base.state); |
| 2815 | struct intel_plane_state *plane_state = |
| 2816 | to_intel_plane_state(plane->base.state); |
| 2817 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 2818 | DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", |
| 2819 | plane->base.base.id, plane->base.name, |
| 2820 | crtc->base.base.id, crtc->base.name); |
| 2821 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2822 | intel_set_plane_visible(crtc_state, plane_state, false); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2823 | fixup_active_planes(crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2824 | |
| 2825 | if (plane->id == PLANE_PRIMARY) |
| 2826 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2827 | |
| 2828 | trace_intel_disable_plane(&plane->base, crtc); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 2829 | plane->disable_plane(plane, crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2830 | } |
| 2831 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2832 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2833 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2834 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2835 | { |
| 2836 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2837 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2838 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2839 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2840 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2841 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2842 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2843 | struct intel_plane_state *intel_state = |
| 2844 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2845 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2846 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2847 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2848 | return; |
| 2849 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2850 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2851 | fb = &plane_config->fb->base; |
| 2852 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2853 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2854 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2855 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2856 | |
| 2857 | /* |
| 2858 | * Failed to alloc the obj, check to see if we should share |
| 2859 | * an fb with another CRTC instead |
| 2860 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2861 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2862 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2863 | |
| 2864 | if (c == &intel_crtc->base) |
| 2865 | continue; |
| 2866 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2867 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2868 | continue; |
| 2869 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2870 | state = to_intel_plane_state(c->primary->state); |
| 2871 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2872 | continue; |
| 2873 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2874 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2875 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2876 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2877 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2878 | } |
| 2879 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2880 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2881 | /* |
| 2882 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2883 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2884 | * which will lead to problems later if we don't fix it up. The |
| 2885 | * simplest solution is to just disable the primary plane now and |
| 2886 | * pretend the BIOS never had it enabled. |
| 2887 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2888 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2889 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2890 | return; |
| 2891 | |
| 2892 | valid_fb: |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 2893 | intel_state->base.rotation = plane_config->rotation; |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2894 | intel_fill_fb_ggtt_view(&intel_state->view, fb, |
| 2895 | intel_state->base.rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2896 | intel_state->color_plane[0].stride = |
| 2897 | intel_fb_pitch(fb, 0, intel_state->base.rotation); |
| 2898 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2899 | mutex_lock(&dev->struct_mutex); |
| 2900 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2901 | intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2902 | &intel_state->view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2903 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2904 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2905 | mutex_unlock(&dev->struct_mutex); |
| 2906 | if (IS_ERR(intel_state->vma)) { |
| 2907 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2908 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2909 | |
| 2910 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2911 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2912 | return; |
| 2913 | } |
| 2914 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2915 | obj = intel_fb_obj(fb); |
| 2916 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2917 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2918 | plane_state->src_x = 0; |
| 2919 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2920 | plane_state->src_w = fb->width << 16; |
| 2921 | plane_state->src_h = fb->height << 16; |
| 2922 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2923 | plane_state->crtc_x = 0; |
| 2924 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2925 | plane_state->crtc_w = fb->width; |
| 2926 | plane_state->crtc_h = fb->height; |
| 2927 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2928 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2929 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2930 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2931 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2932 | dev_priv->preserve_bios_swizzle = true; |
| 2933 | |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 2934 | plane_state->fb = fb; |
| 2935 | plane_state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2936 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2937 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2938 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2939 | } |
| 2940 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2941 | static int skl_max_plane_width(const struct drm_framebuffer *fb, |
| 2942 | int color_plane, |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2943 | unsigned int rotation) |
| 2944 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2945 | int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2946 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2947 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2948 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2949 | case I915_FORMAT_MOD_X_TILED: |
| 2950 | switch (cpp) { |
| 2951 | case 8: |
| 2952 | return 4096; |
| 2953 | case 4: |
| 2954 | case 2: |
| 2955 | case 1: |
| 2956 | return 8192; |
| 2957 | default: |
| 2958 | MISSING_CASE(cpp); |
| 2959 | break; |
| 2960 | } |
| 2961 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2962 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2963 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2964 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2965 | case I915_FORMAT_MOD_Y_TILED: |
| 2966 | case I915_FORMAT_MOD_Yf_TILED: |
| 2967 | switch (cpp) { |
| 2968 | case 8: |
| 2969 | return 2048; |
| 2970 | case 4: |
| 2971 | return 4096; |
| 2972 | case 2: |
| 2973 | case 1: |
| 2974 | return 8192; |
| 2975 | default: |
| 2976 | MISSING_CASE(cpp); |
| 2977 | break; |
| 2978 | } |
| 2979 | break; |
| 2980 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2981 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | return 2048; |
| 2985 | } |
| 2986 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2987 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2988 | int main_x, int main_y, u32 main_offset) |
| 2989 | { |
| 2990 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2991 | int hsub = fb->format->hsub; |
| 2992 | int vsub = fb->format->vsub; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2993 | int aux_x = plane_state->color_plane[1].x; |
| 2994 | int aux_y = plane_state->color_plane[1].y; |
| 2995 | u32 aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2996 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2997 | |
| 2998 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2999 | int x, y; |
| 3000 | |
| 3001 | if (aux_x == main_x && aux_y == main_y) |
| 3002 | break; |
| 3003 | |
| 3004 | if (aux_offset == 0) |
| 3005 | break; |
| 3006 | |
| 3007 | x = aux_x / hsub; |
| 3008 | y = aux_y / vsub; |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3009 | aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1, |
| 3010 | aux_offset, aux_offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3011 | aux_x = x * hsub + aux_x % hsub; |
| 3012 | aux_y = y * vsub + aux_y % vsub; |
| 3013 | } |
| 3014 | |
| 3015 | if (aux_x != main_x || aux_y != main_y) |
| 3016 | return false; |
| 3017 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3018 | plane_state->color_plane[1].offset = aux_offset; |
| 3019 | plane_state->color_plane[1].x = aux_x; |
| 3020 | plane_state->color_plane[1].y = aux_y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3021 | |
| 3022 | return true; |
| 3023 | } |
| 3024 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3025 | static int skl_check_main_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3026 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3027 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3028 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3029 | int x = plane_state->base.src.x1 >> 16; |
| 3030 | int y = plane_state->base.src.y1 >> 16; |
| 3031 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3032 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3033 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 3034 | int max_height = 4096; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3035 | u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3036 | |
| 3037 | if (w > max_width || h > max_height) { |
| 3038 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 3039 | w, h, max_width, max_height); |
| 3040 | return -EINVAL; |
| 3041 | } |
| 3042 | |
| 3043 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3044 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3045 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3046 | |
| 3047 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3048 | * AUX surface offset is specified as the distance from the |
| 3049 | * main surface offset, and it must be non-negative. Make |
| 3050 | * sure that is what we will get. |
| 3051 | */ |
| 3052 | if (offset > aux_offset) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3053 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3054 | offset, aux_offset & ~(alignment - 1)); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3055 | |
| 3056 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3057 | * When using an X-tiled surface, the plane blows up |
| 3058 | * if the x offset + width exceed the stride. |
| 3059 | * |
| 3060 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 3061 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3062 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3063 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3064 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3065 | while ((x + w) * cpp > plane_state->color_plane[0].stride) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3066 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3067 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n"); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3068 | return -EINVAL; |
| 3069 | } |
| 3070 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3071 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3072 | offset, offset - alignment); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3073 | } |
| 3074 | } |
| 3075 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3076 | /* |
| 3077 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3078 | * they match with the main surface x/y offsets. |
| 3079 | */ |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3080 | if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3081 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3082 | if (offset == 0) |
| 3083 | break; |
| 3084 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3085 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3086 | offset, offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3089 | if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3090 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3091 | return -EINVAL; |
| 3092 | } |
| 3093 | } |
| 3094 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3095 | plane_state->color_plane[0].offset = offset; |
| 3096 | plane_state->color_plane[0].x = x; |
| 3097 | plane_state->color_plane[0].y = y; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3098 | |
| 3099 | return 0; |
| 3100 | } |
| 3101 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3102 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3103 | { |
| 3104 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3105 | unsigned int rotation = plane_state->base.rotation; |
| 3106 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3107 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3108 | int x = plane_state->base.src.x1 >> 17; |
| 3109 | int y = plane_state->base.src.y1 >> 17; |
| 3110 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3111 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3112 | u32 offset; |
| 3113 | |
| 3114 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3115 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3116 | |
| 3117 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3118 | if (w > max_width || h > max_height) { |
| 3119 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3120 | w, h, max_width, max_height); |
| 3121 | return -EINVAL; |
| 3122 | } |
| 3123 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3124 | plane_state->color_plane[1].offset = offset; |
| 3125 | plane_state->color_plane[1].x = x; |
| 3126 | plane_state->color_plane[1].y = y; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3127 | |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3131 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3132 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3133 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3134 | int src_x = plane_state->base.src.x1 >> 16; |
| 3135 | int src_y = plane_state->base.src.y1 >> 16; |
| 3136 | int hsub = fb->format->hsub; |
| 3137 | int vsub = fb->format->vsub; |
| 3138 | int x = src_x / hsub; |
| 3139 | int y = src_y / vsub; |
| 3140 | u32 offset; |
| 3141 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3142 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3143 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3144 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3145 | plane_state->color_plane[1].offset = offset; |
| 3146 | plane_state->color_plane[1].x = x * hsub + src_x % hsub; |
| 3147 | plane_state->color_plane[1].y = y * vsub + src_y % vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3148 | |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3152 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3153 | { |
| 3154 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3155 | unsigned int rotation = plane_state->base.rotation; |
| 3156 | int ret; |
| 3157 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3158 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3159 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3160 | plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation); |
| 3161 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3162 | ret = intel_plane_check_stride(plane_state); |
| 3163 | if (ret) |
| 3164 | return ret; |
| 3165 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3166 | if (!plane_state->base.visible) |
| 3167 | return 0; |
| 3168 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3169 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3170 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3171 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3172 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3173 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3174 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3175 | /* |
| 3176 | * Handle the AUX surface first since |
| 3177 | * the main surface setup depends on it. |
| 3178 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3179 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3180 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3181 | if (ret) |
| 3182 | return ret; |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3183 | } else if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3184 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3185 | if (ret) |
| 3186 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3187 | } else { |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3188 | plane_state->color_plane[1].offset = ~0xfff; |
| 3189 | plane_state->color_plane[1].x = 0; |
| 3190 | plane_state->color_plane[1].y = 0; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3193 | ret = skl_check_main_surface(plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3194 | if (ret) |
| 3195 | return ret; |
| 3196 | |
| 3197 | return 0; |
| 3198 | } |
| 3199 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3200 | unsigned int |
| 3201 | i9xx_plane_max_stride(struct intel_plane *plane, |
| 3202 | u32 pixel_format, u64 modifier, |
| 3203 | unsigned int rotation) |
| 3204 | { |
| 3205 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3206 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 3207 | if (!HAS_GMCH(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3208 | return 32*1024; |
| 3209 | } else if (INTEL_GEN(dev_priv) >= 4) { |
| 3210 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3211 | return 16*1024; |
| 3212 | else |
| 3213 | return 32*1024; |
| 3214 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 3215 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3216 | return 8*1024; |
| 3217 | else |
| 3218 | return 16*1024; |
| 3219 | } else { |
| 3220 | if (plane->i9xx_plane == PLANE_C) |
| 3221 | return 4*1024; |
| 3222 | else |
| 3223 | return 8*1024; |
| 3224 | } |
| 3225 | } |
| 3226 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3227 | static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3228 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3229 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3230 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3231 | u32 dspcntr = 0; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3232 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3233 | dspcntr |= DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3234 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3235 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 3236 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3237 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3238 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3239 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3240 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3241 | return dspcntr; |
| 3242 | } |
| 3243 | |
| 3244 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3245 | const struct intel_plane_state *plane_state) |
| 3246 | { |
| 3247 | struct drm_i915_private *dev_priv = |
| 3248 | to_i915(plane_state->base.plane->dev); |
| 3249 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3250 | unsigned int rotation = plane_state->base.rotation; |
| 3251 | u32 dspcntr; |
| 3252 | |
| 3253 | dspcntr = DISPLAY_PLANE_ENABLE; |
| 3254 | |
| 3255 | if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) || |
| 3256 | IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
| 3257 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 3258 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3259 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3260 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3261 | dspcntr |= DISPPLANE_8BPP; |
| 3262 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3263 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3264 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3265 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3266 | case DRM_FORMAT_RGB565: |
| 3267 | dspcntr |= DISPPLANE_BGRX565; |
| 3268 | break; |
| 3269 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3270 | dspcntr |= DISPPLANE_BGRX888; |
| 3271 | break; |
| 3272 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3273 | dspcntr |= DISPPLANE_RGBX888; |
| 3274 | break; |
| 3275 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3276 | dspcntr |= DISPPLANE_BGRX101010; |
| 3277 | break; |
| 3278 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3279 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3280 | break; |
| 3281 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3282 | MISSING_CASE(fb->format->format); |
| 3283 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3284 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3285 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3286 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3287 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3288 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3289 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3290 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3291 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3292 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3293 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3294 | dspcntr |= DISPPLANE_MIRROR; |
| 3295 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3296 | return dspcntr; |
| 3297 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3298 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3299 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3300 | { |
| 3301 | struct drm_i915_private *dev_priv = |
| 3302 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3303 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3304 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3305 | int src_x = plane_state->base.src.x1 >> 16; |
| 3306 | int src_y = plane_state->base.src.y1 >> 16; |
| 3307 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3308 | int ret; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3309 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3310 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3311 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3312 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3313 | ret = intel_plane_check_stride(plane_state); |
| 3314 | if (ret) |
| 3315 | return ret; |
| 3316 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3317 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3318 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3319 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3320 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 3321 | plane_state, 0); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3322 | else |
| 3323 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3324 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3325 | /* HSW/BDW do this automagically in hardware */ |
| 3326 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3327 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3328 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3329 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3330 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3331 | src_x += src_w - 1; |
| 3332 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3333 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3334 | src_x += src_w - 1; |
| 3335 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3336 | } |
| 3337 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3338 | plane_state->color_plane[0].offset = offset; |
| 3339 | plane_state->color_plane[0].x = src_x; |
| 3340 | plane_state->color_plane[0].y = src_y; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3341 | |
| 3342 | return 0; |
| 3343 | } |
| 3344 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3345 | static int |
| 3346 | i9xx_plane_check(struct intel_crtc_state *crtc_state, |
| 3347 | struct intel_plane_state *plane_state) |
| 3348 | { |
| 3349 | int ret; |
| 3350 | |
Ville Syrjälä | 25721f8 | 2018-09-07 18:24:12 +0300 | [diff] [blame] | 3351 | ret = chv_plane_check_rotation(plane_state); |
| 3352 | if (ret) |
| 3353 | return ret; |
| 3354 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3355 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 3356 | &crtc_state->base, |
| 3357 | DRM_PLANE_HELPER_NO_SCALING, |
| 3358 | DRM_PLANE_HELPER_NO_SCALING, |
| 3359 | false, true); |
| 3360 | if (ret) |
| 3361 | return ret; |
| 3362 | |
| 3363 | if (!plane_state->base.visible) |
| 3364 | return 0; |
| 3365 | |
| 3366 | ret = intel_plane_check_src_coordinates(plane_state); |
| 3367 | if (ret) |
| 3368 | return ret; |
| 3369 | |
| 3370 | ret = i9xx_check_plane_surface(plane_state); |
| 3371 | if (ret) |
| 3372 | return ret; |
| 3373 | |
| 3374 | plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state); |
| 3375 | |
| 3376 | return 0; |
| 3377 | } |
| 3378 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3379 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3380 | const struct intel_crtc_state *crtc_state, |
| 3381 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3382 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3383 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3384 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3385 | u32 linear_offset; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3386 | int x = plane_state->color_plane[0].x; |
| 3387 | int y = plane_state->color_plane[0].y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3388 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3389 | u32 dspaddr_offset; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3390 | u32 dspcntr; |
| 3391 | |
| 3392 | dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state); |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3393 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3394 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3395 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3396 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3397 | dspaddr_offset = plane_state->color_plane[0].offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3398 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3399 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3400 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3401 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3402 | |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3403 | I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride); |
| 3404 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3405 | if (INTEL_GEN(dev_priv) < 4) { |
| 3406 | /* pipesrc and dspsize control the size that is scaled from, |
| 3407 | * which should always be the user's requested size. |
| 3408 | */ |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3409 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3410 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3411 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3412 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3413 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3414 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3415 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3416 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3417 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3418 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3419 | } |
| 3420 | |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3421 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3422 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3423 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3424 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
| 3425 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3426 | } |
| 3427 | |
| 3428 | /* |
| 3429 | * The control register self-arms if the plane was previously |
| 3430 | * disabled. Try to make the plane enable atomic by writing |
| 3431 | * the control register just before the surface register. |
| 3432 | */ |
| 3433 | I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr); |
| 3434 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3435 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3436 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3437 | dspaddr_offset); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3438 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3439 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3440 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3441 | dspaddr_offset); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3442 | |
| 3443 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3444 | } |
| 3445 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3446 | static void i9xx_disable_plane(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 3447 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3448 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3449 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3450 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3451 | unsigned long irqflags; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3452 | u32 dspcntr; |
| 3453 | |
| 3454 | /* |
| 3455 | * DSPCNTR pipe gamma enable on g4x+ and pipe csc |
| 3456 | * enable on ilk+ affect the pipe bottom color as |
| 3457 | * well, so we must configure them even if the plane |
| 3458 | * is disabled. |
| 3459 | * |
| 3460 | * On pre-g4x there is no way to gamma correct the |
| 3461 | * pipe bottom color but we'll keep on doing this |
| 3462 | * anyway. |
| 3463 | */ |
| 3464 | dspcntr = i9xx_plane_ctl_crtc(crtc_state); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3465 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3466 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3467 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3468 | I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3469 | if (INTEL_GEN(dev_priv) >= 4) |
| 3470 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3471 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3472 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3473 | |
| 3474 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3477 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane, |
| 3478 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3479 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3480 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3481 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3482 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3483 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3484 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3485 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3486 | |
| 3487 | /* |
| 3488 | * Not 100% correct for planes that can move between pipes, |
| 3489 | * but that's only the case for gen2-4 which don't have any |
| 3490 | * display power wells. |
| 3491 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3492 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3493 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 3494 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3495 | return false; |
| 3496 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3497 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 3498 | |
| 3499 | ret = val & DISPLAY_PLANE_ENABLE; |
| 3500 | |
| 3501 | if (INTEL_GEN(dev_priv) >= 5) |
| 3502 | *pipe = plane->pipe; |
| 3503 | else |
| 3504 | *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 3505 | DISPPLANE_SEL_PIPE_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3506 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3507 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3508 | |
| 3509 | return ret; |
| 3510 | } |
| 3511 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3512 | static u32 |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3513 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3514 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3515 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3516 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3517 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3518 | return intel_tile_width_bytes(fb, color_plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3521 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3522 | { |
| 3523 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3524 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3525 | |
| 3526 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3527 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3528 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3529 | } |
| 3530 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3531 | /* |
| 3532 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3533 | */ |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3534 | static void skl_detach_scalers(const struct intel_crtc_state *crtc_state) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3535 | { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3536 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3537 | const struct intel_crtc_scaler_state *scaler_state = |
| 3538 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3539 | int i; |
| 3540 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3541 | /* loop through and disable scalers that aren't in use */ |
| 3542 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3543 | if (!scaler_state->scalers[i].in_use) |
| 3544 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3548 | static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb, |
| 3549 | int color_plane, unsigned int rotation) |
| 3550 | { |
| 3551 | /* |
| 3552 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3553 | * linear buffers or in number of tiles for tiled buffers. |
| 3554 | */ |
| 3555 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
| 3556 | return 64; |
| 3557 | else if (drm_rotation_90_or_270(rotation)) |
| 3558 | return intel_tile_height(fb, color_plane); |
| 3559 | else |
| 3560 | return intel_tile_width_bytes(fb, color_plane); |
| 3561 | } |
| 3562 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3563 | u32 skl_plane_stride(const struct intel_plane_state *plane_state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3564 | int color_plane) |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3565 | { |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3566 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3567 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3568 | u32 stride = plane_state->color_plane[color_plane].stride; |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3569 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3570 | if (color_plane >= fb->format->num_planes) |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3571 | return 0; |
| 3572 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3573 | return stride / skl_plane_stride_mult(fb, color_plane, rotation); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3574 | } |
| 3575 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 3576 | static u32 skl_plane_ctl_format(u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3577 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3578 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3579 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3580 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3581 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3582 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3583 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3584 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3585 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3586 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3587 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3588 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3589 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3590 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3591 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3592 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3593 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3594 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3595 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3596 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3597 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3598 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3599 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3600 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3601 | case DRM_FORMAT_NV12: |
| 3602 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3603 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3604 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3605 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3606 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3607 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3610 | static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state) |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3611 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3612 | if (!plane_state->base.fb->format->has_alpha) |
| 3613 | return PLANE_CTL_ALPHA_DISABLE; |
| 3614 | |
| 3615 | switch (plane_state->base.pixel_blend_mode) { |
| 3616 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3617 | return PLANE_CTL_ALPHA_DISABLE; |
| 3618 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3619 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3620 | case DRM_MODE_BLEND_COVERAGE: |
| 3621 | return PLANE_CTL_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3622 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3623 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3624 | return PLANE_CTL_ALPHA_DISABLE; |
| 3625 | } |
| 3626 | } |
| 3627 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3628 | static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state) |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3629 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3630 | if (!plane_state->base.fb->format->has_alpha) |
| 3631 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3632 | |
| 3633 | switch (plane_state->base.pixel_blend_mode) { |
| 3634 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3635 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3636 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3637 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3638 | case DRM_MODE_BLEND_COVERAGE: |
| 3639 | return PLANE_COLOR_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3640 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3641 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3642 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3643 | } |
| 3644 | } |
| 3645 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 3646 | static u32 skl_plane_ctl_tiling(u64 fb_modifier) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3647 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3648 | switch (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3649 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3650 | break; |
| 3651 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3652 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3653 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3654 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3655 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3656 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3657 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3658 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3659 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3660 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3661 | default: |
| 3662 | MISSING_CASE(fb_modifier); |
| 3663 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3664 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3665 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3668 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3669 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3670 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3671 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3672 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3673 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3674 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3675 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3676 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3677 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3678 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3679 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3680 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3681 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3682 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3683 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3684 | MISSING_CASE(rotate); |
| 3685 | } |
| 3686 | |
| 3687 | return 0; |
| 3688 | } |
| 3689 | |
| 3690 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3691 | { |
| 3692 | switch (reflect) { |
| 3693 | case 0: |
| 3694 | break; |
| 3695 | case DRM_MODE_REFLECT_X: |
| 3696 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3697 | case DRM_MODE_REFLECT_Y: |
| 3698 | default: |
| 3699 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3702 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3705 | u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 3706 | { |
| 3707 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3708 | u32 plane_ctl = 0; |
| 3709 | |
| 3710 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 3711 | return plane_ctl; |
| 3712 | |
| 3713 | plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE; |
| 3714 | plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE; |
| 3715 | |
| 3716 | return plane_ctl; |
| 3717 | } |
| 3718 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3719 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3720 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3721 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3722 | struct drm_i915_private *dev_priv = |
| 3723 | to_i915(plane_state->base.plane->dev); |
| 3724 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3725 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3726 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3727 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3728 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3729 | plane_ctl = PLANE_CTL_ENABLE; |
| 3730 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3731 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3732 | plane_ctl |= skl_plane_ctl_alpha(plane_state); |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3733 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3734 | |
| 3735 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3736 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3737 | |
| 3738 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3739 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3740 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3741 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3742 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3743 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3744 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3745 | |
| 3746 | if (INTEL_GEN(dev_priv) >= 10) |
| 3747 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3748 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3749 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3750 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3751 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3752 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3753 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3754 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3755 | return plane_ctl; |
| 3756 | } |
| 3757 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3758 | u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 3759 | { |
| 3760 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3761 | u32 plane_color_ctl = 0; |
| 3762 | |
| 3763 | if (INTEL_GEN(dev_priv) >= 11) |
| 3764 | return plane_color_ctl; |
| 3765 | |
| 3766 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3767 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
| 3768 | |
| 3769 | return plane_color_ctl; |
| 3770 | } |
| 3771 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3772 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3773 | const struct intel_plane_state *plane_state) |
| 3774 | { |
| 3775 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3776 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3777 | u32 plane_color_ctl = 0; |
| 3778 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3779 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3780 | plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3781 | |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3782 | if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) { |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3783 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3784 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3785 | else |
| 3786 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3787 | |
| 3788 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3789 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3790 | } else if (fb->format->is_yuv) { |
| 3791 | plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3792 | } |
Ville Syrjälä | 012d79e | 2018-05-21 21:56:12 +0300 | [diff] [blame] | 3793 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3794 | return plane_color_ctl; |
| 3795 | } |
| 3796 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3797 | static int |
| 3798 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3799 | struct drm_atomic_state *state, |
| 3800 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3801 | { |
| 3802 | struct drm_crtc_state *crtc_state; |
| 3803 | struct drm_crtc *crtc; |
| 3804 | int i, ret; |
| 3805 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3806 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3807 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3808 | |
| 3809 | if (!state) |
| 3810 | return 0; |
| 3811 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3812 | /* |
| 3813 | * We've duplicated the state, pointers to the old state are invalid. |
| 3814 | * |
| 3815 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3816 | */ |
| 3817 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3818 | /* |
| 3819 | * Force recalculation even if we restore |
| 3820 | * current state. With fast modeset this may not result |
| 3821 | * in a modeset when the state is compatible. |
| 3822 | */ |
| 3823 | crtc_state->mode_changed = true; |
| 3824 | } |
| 3825 | |
| 3826 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 3827 | if (!HAS_GMCH(to_i915(dev))) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3828 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3829 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3830 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3831 | |
| 3832 | WARN_ON(ret == -EDEADLK); |
| 3833 | return ret; |
| 3834 | } |
| 3835 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3836 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3837 | { |
Chris Wilson | 55277e1 | 2019-01-03 11:21:04 +0000 | [diff] [blame] | 3838 | return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display && |
| 3839 | intel_has_gpu_reset(dev_priv)); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3840 | } |
| 3841 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3842 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3843 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3844 | struct drm_device *dev = &dev_priv->drm; |
| 3845 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3846 | struct drm_atomic_state *state; |
| 3847 | int ret; |
| 3848 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3849 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3850 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3851 | !gpu_reset_clobbers_display(dev_priv)) |
| 3852 | return; |
| 3853 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3854 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3855 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3856 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3857 | |
| 3858 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3859 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3860 | i915_gem_set_wedged(dev_priv); |
| 3861 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3862 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3863 | /* |
| 3864 | * Need mode_config.mutex so that we don't |
| 3865 | * trample ongoing ->detect() and whatnot. |
| 3866 | */ |
| 3867 | mutex_lock(&dev->mode_config.mutex); |
| 3868 | drm_modeset_acquire_init(ctx, 0); |
| 3869 | while (1) { |
| 3870 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3871 | if (ret != -EDEADLK) |
| 3872 | break; |
| 3873 | |
| 3874 | drm_modeset_backoff(ctx); |
| 3875 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3876 | /* |
| 3877 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3878 | * g33 docs say we should at least disable all the planes. |
| 3879 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3880 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3881 | if (IS_ERR(state)) { |
| 3882 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3883 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3884 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3888 | if (ret) { |
| 3889 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3890 | drm_atomic_state_put(state); |
| 3891 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | dev_priv->modeset_restore_state = state; |
| 3895 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3896 | } |
| 3897 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3898 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3899 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3900 | struct drm_device *dev = &dev_priv->drm; |
| 3901 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3902 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3903 | int ret; |
| 3904 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3905 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3906 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3907 | return; |
| 3908 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3909 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3910 | if (!state) |
| 3911 | goto unlock; |
| 3912 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3913 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3914 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3915 | /* for testing only restore the display */ |
| 3916 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3917 | if (ret) |
| 3918 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3919 | } else { |
| 3920 | /* |
| 3921 | * The display has been reset as well, |
| 3922 | * so need a full re-initialization. |
| 3923 | */ |
| 3924 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3925 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3926 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3927 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3928 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3929 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3930 | |
| 3931 | spin_lock_irq(&dev_priv->irq_lock); |
| 3932 | if (dev_priv->display.hpd_irq_setup) |
| 3933 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3934 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3935 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3936 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3937 | if (ret) |
| 3938 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3939 | |
| 3940 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3941 | } |
| 3942 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3943 | drm_atomic_state_put(state); |
| 3944 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3945 | drm_modeset_drop_locks(ctx); |
| 3946 | drm_modeset_acquire_fini(ctx); |
| 3947 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3948 | |
| 3949 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3950 | } |
| 3951 | |
Ville Syrjälä | d162211 | 2019-02-04 22:21:39 +0200 | [diff] [blame] | 3952 | static void icl_set_pipe_chicken(struct intel_crtc *crtc) |
| 3953 | { |
| 3954 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3955 | enum pipe pipe = crtc->pipe; |
| 3956 | u32 tmp; |
| 3957 | |
| 3958 | tmp = I915_READ(PIPE_CHICKEN(pipe)); |
| 3959 | |
| 3960 | /* |
| 3961 | * Display WA #1153: icl |
| 3962 | * enable hardware to bypass the alpha math |
| 3963 | * and rounding for per-pixel values 00 and 0xff |
| 3964 | */ |
| 3965 | tmp |= PER_PIXEL_ALPHA_BYPASS_EN; |
| 3966 | |
Ville Syrjälä | bf002c1 | 2019-02-04 22:22:32 +0200 | [diff] [blame] | 3967 | /* |
| 3968 | * W/A for underruns with linear/X-tiled with |
| 3969 | * WM1+ disabled. |
| 3970 | */ |
| 3971 | tmp |= PM_FILL_MAINTAIN_DBUF_FULLNESS; |
| 3972 | |
Ville Syrjälä | d162211 | 2019-02-04 22:21:39 +0200 | [diff] [blame] | 3973 | I915_WRITE(PIPE_CHICKEN(pipe), tmp); |
| 3974 | } |
| 3975 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3976 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3977 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3978 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3979 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3980 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3981 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3982 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3983 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3984 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3985 | /* |
| 3986 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3987 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3988 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3989 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3990 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3991 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3992 | */ |
| 3993 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3994 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3995 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3996 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3997 | |
| 3998 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3999 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 4000 | skl_detach_scalers(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4001 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 4002 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4003 | skylake_pfit_enable(new_crtc_state); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4004 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 4005 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4006 | ironlake_pfit_enable(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4007 | else if (old_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4008 | ironlake_pfit_disable(old_crtc_state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 4009 | } |
Matt Roper | c055030 | 2019-01-30 10:51:20 -0800 | [diff] [blame] | 4010 | |
| 4011 | /* |
| 4012 | * We don't (yet) allow userspace to control the pipe background color, |
| 4013 | * so force it to black, but apply pipe gamma and CSC so that its |
| 4014 | * handling will match how we program our planes. |
| 4015 | */ |
| 4016 | if (INTEL_GEN(dev_priv) >= 9) |
| 4017 | I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe), |
| 4018 | SKL_BOTTOM_COLOR_GAMMA_ENABLE | |
| 4019 | SKL_BOTTOM_COLOR_CSC_ENABLE); |
Ville Syrjälä | 108d14b | 2019-02-04 22:22:14 +0200 | [diff] [blame] | 4020 | |
| 4021 | if (INTEL_GEN(dev_priv) >= 11) |
| 4022 | icl_set_pipe_chicken(crtc); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 4023 | } |
| 4024 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4025 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4026 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4027 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4028 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4029 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4030 | i915_reg_t reg; |
| 4031 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4032 | |
| 4033 | /* enable normal train */ |
| 4034 | reg = FDI_TX_CTL(pipe); |
| 4035 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4036 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4037 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4038 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 4039 | } else { |
| 4040 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4041 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4042 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4043 | I915_WRITE(reg, temp); |
| 4044 | |
| 4045 | reg = FDI_RX_CTL(pipe); |
| 4046 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4047 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4048 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4049 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 4050 | } else { |
| 4051 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4052 | temp |= FDI_LINK_TRAIN_NONE; |
| 4053 | } |
| 4054 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 4055 | |
| 4056 | /* wait one idle pattern time */ |
| 4057 | POSTING_READ(reg); |
| 4058 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4059 | |
| 4060 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4061 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4062 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 4063 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4064 | } |
| 4065 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4066 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4067 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 4068 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4069 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4070 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4071 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4072 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4073 | i915_reg_t reg; |
| 4074 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4075 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 4076 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4077 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4078 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4079 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4080 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4081 | reg = FDI_RX_IMR(pipe); |
| 4082 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4083 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4084 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4085 | I915_WRITE(reg, temp); |
| 4086 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4087 | udelay(150); |
| 4088 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4089 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4090 | reg = FDI_TX_CTL(pipe); |
| 4091 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4092 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4093 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4094 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4095 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4096 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4097 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4098 | reg = FDI_RX_CTL(pipe); |
| 4099 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4100 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4101 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4102 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4103 | |
| 4104 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4105 | udelay(150); |
| 4106 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 4107 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 4108 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 4109 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 4110 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 4111 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4112 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4113 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4114 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4115 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4116 | |
| 4117 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 4118 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4119 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4120 | break; |
| 4121 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4122 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4123 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4124 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4125 | |
| 4126 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4127 | reg = FDI_TX_CTL(pipe); |
| 4128 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4129 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4130 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4131 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4132 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4133 | reg = FDI_RX_CTL(pipe); |
| 4134 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4135 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4136 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4137 | I915_WRITE(reg, temp); |
| 4138 | |
| 4139 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4140 | udelay(150); |
| 4141 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4142 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4143 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4144 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4145 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4146 | |
| 4147 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4148 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4149 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4150 | break; |
| 4151 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4152 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4153 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4154 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4155 | |
| 4156 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4157 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4158 | } |
| 4159 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4160 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4161 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 4162 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 4163 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 4164 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 4165 | }; |
| 4166 | |
| 4167 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4168 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
| 4169 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4170 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4171 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4172 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4173 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4174 | i915_reg_t reg; |
| 4175 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4176 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4177 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4178 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4179 | reg = FDI_RX_IMR(pipe); |
| 4180 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4181 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4182 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4183 | I915_WRITE(reg, temp); |
| 4184 | |
| 4185 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4186 | udelay(150); |
| 4187 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4188 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4189 | reg = FDI_TX_CTL(pipe); |
| 4190 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4191 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4192 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4193 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4194 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4195 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4196 | /* SNB-B */ |
| 4197 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4198 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4199 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4200 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4201 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4202 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4203 | reg = FDI_RX_CTL(pipe); |
| 4204 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4205 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4206 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4207 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4208 | } else { |
| 4209 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4210 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4211 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4212 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4213 | |
| 4214 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4215 | udelay(150); |
| 4216 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4217 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4218 | reg = FDI_TX_CTL(pipe); |
| 4219 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4220 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4221 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4222 | I915_WRITE(reg, temp); |
| 4223 | |
| 4224 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4225 | udelay(500); |
| 4226 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4227 | for (retry = 0; retry < 5; retry++) { |
| 4228 | reg = FDI_RX_IIR(pipe); |
| 4229 | temp = I915_READ(reg); |
| 4230 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4231 | if (temp & FDI_RX_BIT_LOCK) { |
| 4232 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4233 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4234 | break; |
| 4235 | } |
| 4236 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4237 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4238 | if (retry < 5) |
| 4239 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4240 | } |
| 4241 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4242 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4243 | |
| 4244 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4245 | reg = FDI_TX_CTL(pipe); |
| 4246 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4247 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4248 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4249 | if (IS_GEN(dev_priv, 6)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4250 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4251 | /* SNB-B */ |
| 4252 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4253 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4254 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4255 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4256 | reg = FDI_RX_CTL(pipe); |
| 4257 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4258 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4259 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4260 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4261 | } else { |
| 4262 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4263 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4264 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4265 | I915_WRITE(reg, temp); |
| 4266 | |
| 4267 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4268 | udelay(150); |
| 4269 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4270 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4271 | reg = FDI_TX_CTL(pipe); |
| 4272 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4273 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4274 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4275 | I915_WRITE(reg, temp); |
| 4276 | |
| 4277 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4278 | udelay(500); |
| 4279 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4280 | for (retry = 0; retry < 5; retry++) { |
| 4281 | reg = FDI_RX_IIR(pipe); |
| 4282 | temp = I915_READ(reg); |
| 4283 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4284 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4285 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4286 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4287 | break; |
| 4288 | } |
| 4289 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4290 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4291 | if (retry < 5) |
| 4292 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4293 | } |
| 4294 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4295 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4296 | |
| 4297 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4298 | } |
| 4299 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4300 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4301 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4302 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4303 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4304 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4305 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4306 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4307 | i915_reg_t reg; |
| 4308 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4309 | |
| 4310 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4311 | for train result */ |
| 4312 | reg = FDI_RX_IMR(pipe); |
| 4313 | temp = I915_READ(reg); |
| 4314 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4315 | temp &= ~FDI_RX_BIT_LOCK; |
| 4316 | I915_WRITE(reg, temp); |
| 4317 | |
| 4318 | POSTING_READ(reg); |
| 4319 | udelay(150); |
| 4320 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4321 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4322 | I915_READ(FDI_RX_IIR(pipe))); |
| 4323 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4324 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4325 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4326 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4327 | reg = FDI_TX_CTL(pipe); |
| 4328 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4329 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4330 | temp &= ~FDI_TX_ENABLE; |
| 4331 | I915_WRITE(reg, temp); |
| 4332 | |
| 4333 | reg = FDI_RX_CTL(pipe); |
| 4334 | temp = I915_READ(reg); |
| 4335 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4336 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4337 | temp &= ~FDI_RX_ENABLE; |
| 4338 | I915_WRITE(reg, temp); |
| 4339 | |
| 4340 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4341 | reg = FDI_TX_CTL(pipe); |
| 4342 | temp = I915_READ(reg); |
| 4343 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4344 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4345 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4346 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4347 | temp |= snb_b_fdi_train_param[j/2]; |
| 4348 | temp |= FDI_COMPOSITE_SYNC; |
| 4349 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4350 | |
| 4351 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4352 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4353 | |
| 4354 | reg = FDI_RX_CTL(pipe); |
| 4355 | temp = I915_READ(reg); |
| 4356 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4357 | temp |= FDI_COMPOSITE_SYNC; |
| 4358 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4359 | |
| 4360 | POSTING_READ(reg); |
| 4361 | udelay(1); /* should be 0.5us */ |
| 4362 | |
| 4363 | for (i = 0; i < 4; i++) { |
| 4364 | reg = FDI_RX_IIR(pipe); |
| 4365 | temp = I915_READ(reg); |
| 4366 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4367 | |
| 4368 | if (temp & FDI_RX_BIT_LOCK || |
| 4369 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4370 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4371 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4372 | i); |
| 4373 | break; |
| 4374 | } |
| 4375 | udelay(1); /* should be 0.5us */ |
| 4376 | } |
| 4377 | if (i == 4) { |
| 4378 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4379 | continue; |
| 4380 | } |
| 4381 | |
| 4382 | /* Train 2 */ |
| 4383 | reg = FDI_TX_CTL(pipe); |
| 4384 | temp = I915_READ(reg); |
| 4385 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4386 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4387 | I915_WRITE(reg, temp); |
| 4388 | |
| 4389 | reg = FDI_RX_CTL(pipe); |
| 4390 | temp = I915_READ(reg); |
| 4391 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4392 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4393 | I915_WRITE(reg, temp); |
| 4394 | |
| 4395 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4396 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4397 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4398 | for (i = 0; i < 4; i++) { |
| 4399 | reg = FDI_RX_IIR(pipe); |
| 4400 | temp = I915_READ(reg); |
| 4401 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4402 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4403 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4404 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4405 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4406 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4407 | i); |
| 4408 | goto train_done; |
| 4409 | } |
| 4410 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4411 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4412 | if (i == 4) |
| 4413 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4414 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4415 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4416 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4417 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4418 | } |
| 4419 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4420 | static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4421 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4422 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4423 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4424 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4425 | i915_reg_t reg; |
| 4426 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4427 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4428 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4429 | reg = FDI_RX_CTL(pipe); |
| 4430 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4431 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4432 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4433 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4434 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4435 | |
| 4436 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4437 | udelay(200); |
| 4438 | |
| 4439 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4440 | temp = I915_READ(reg); |
| 4441 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4442 | |
| 4443 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4444 | udelay(200); |
| 4445 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4446 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4447 | reg = FDI_TX_CTL(pipe); |
| 4448 | temp = I915_READ(reg); |
| 4449 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4450 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4451 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4452 | POSTING_READ(reg); |
| 4453 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4457 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4458 | { |
| 4459 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4460 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4461 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4462 | i915_reg_t reg; |
| 4463 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4464 | |
| 4465 | /* Switch from PCDclk to Rawclk */ |
| 4466 | reg = FDI_RX_CTL(pipe); |
| 4467 | temp = I915_READ(reg); |
| 4468 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4469 | |
| 4470 | /* Disable CPU FDI TX PLL */ |
| 4471 | reg = FDI_TX_CTL(pipe); |
| 4472 | temp = I915_READ(reg); |
| 4473 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4474 | |
| 4475 | POSTING_READ(reg); |
| 4476 | udelay(100); |
| 4477 | |
| 4478 | reg = FDI_RX_CTL(pipe); |
| 4479 | temp = I915_READ(reg); |
| 4480 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4481 | |
| 4482 | /* Wait for the clocks to turn off. */ |
| 4483 | POSTING_READ(reg); |
| 4484 | udelay(100); |
| 4485 | } |
| 4486 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4487 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4488 | { |
| 4489 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4490 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4491 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4492 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4493 | i915_reg_t reg; |
| 4494 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4495 | |
| 4496 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4497 | reg = FDI_TX_CTL(pipe); |
| 4498 | temp = I915_READ(reg); |
| 4499 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4500 | POSTING_READ(reg); |
| 4501 | |
| 4502 | reg = FDI_RX_CTL(pipe); |
| 4503 | temp = I915_READ(reg); |
| 4504 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4505 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4506 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4507 | |
| 4508 | POSTING_READ(reg); |
| 4509 | udelay(100); |
| 4510 | |
| 4511 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4512 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4513 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4514 | |
| 4515 | /* still set train pattern 1 */ |
| 4516 | reg = FDI_TX_CTL(pipe); |
| 4517 | temp = I915_READ(reg); |
| 4518 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4519 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4520 | I915_WRITE(reg, temp); |
| 4521 | |
| 4522 | reg = FDI_RX_CTL(pipe); |
| 4523 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4524 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4525 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4526 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4527 | } else { |
| 4528 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4529 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4530 | } |
| 4531 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4532 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4533 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4534 | I915_WRITE(reg, temp); |
| 4535 | |
| 4536 | POSTING_READ(reg); |
| 4537 | udelay(100); |
| 4538 | } |
| 4539 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4540 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4541 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4542 | struct drm_crtc *crtc; |
| 4543 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4544 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4545 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4546 | struct drm_crtc_commit *commit; |
| 4547 | spin_lock(&crtc->commit_lock); |
| 4548 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4549 | struct drm_crtc_commit, commit_entry); |
| 4550 | cleanup_done = commit ? |
| 4551 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4552 | spin_unlock(&crtc->commit_lock); |
| 4553 | |
| 4554 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4555 | continue; |
| 4556 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4557 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4558 | |
| 4559 | return true; |
| 4560 | } |
| 4561 | |
| 4562 | return false; |
| 4563 | } |
| 4564 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4565 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4566 | { |
| 4567 | u32 temp; |
| 4568 | |
| 4569 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4570 | |
| 4571 | mutex_lock(&dev_priv->sb_lock); |
| 4572 | |
| 4573 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4574 | temp |= SBI_SSCCTL_DISABLE; |
| 4575 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4576 | |
| 4577 | mutex_unlock(&dev_priv->sb_lock); |
| 4578 | } |
| 4579 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4580 | /* Program iCLKIP clock to the desired frequency */ |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4581 | static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4582 | { |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4583 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4584 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4585 | int clock = crtc_state->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4586 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4587 | u32 temp; |
| 4588 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4589 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4590 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4591 | /* The iCLK virtual clock root frequency is in MHz, |
| 4592 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4593 | * divisors, it is necessary to divide one by another, so we |
| 4594 | * convert the virtual clock precision to KHz here for higher |
| 4595 | * precision. |
| 4596 | */ |
| 4597 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4598 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4599 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4600 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4601 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4602 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4603 | clock << auxdiv); |
| 4604 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4605 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4606 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4607 | /* |
| 4608 | * Near 20MHz is a corner case which is |
| 4609 | * out of range for the 7-bit divisor |
| 4610 | */ |
| 4611 | if (divsel <= 0x7f) |
| 4612 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /* This should not happen with any sane values */ |
| 4616 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4617 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4618 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4619 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4620 | |
| 4621 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 4622 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4623 | auxdiv, |
| 4624 | divsel, |
| 4625 | phasedir, |
| 4626 | phaseinc); |
| 4627 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4628 | mutex_lock(&dev_priv->sb_lock); |
| 4629 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4630 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4631 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4632 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4633 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4634 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4635 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4636 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4637 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4638 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4639 | |
| 4640 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4641 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4642 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4643 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4644 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4645 | |
| 4646 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4647 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4648 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4649 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4650 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4651 | mutex_unlock(&dev_priv->sb_lock); |
| 4652 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4653 | /* Wait for initialization time */ |
| 4654 | udelay(24); |
| 4655 | |
| 4656 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4657 | } |
| 4658 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4659 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4660 | { |
| 4661 | u32 divsel, phaseinc, auxdiv; |
| 4662 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4663 | u32 iclk_pi_range = 64; |
| 4664 | u32 desired_divisor; |
| 4665 | u32 temp; |
| 4666 | |
| 4667 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4668 | return 0; |
| 4669 | |
| 4670 | mutex_lock(&dev_priv->sb_lock); |
| 4671 | |
| 4672 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4673 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4674 | mutex_unlock(&dev_priv->sb_lock); |
| 4675 | return 0; |
| 4676 | } |
| 4677 | |
| 4678 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4679 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4680 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4681 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4682 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4683 | |
| 4684 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4685 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4686 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4687 | |
| 4688 | mutex_unlock(&dev_priv->sb_lock); |
| 4689 | |
| 4690 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4691 | |
| 4692 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4693 | desired_divisor << auxdiv); |
| 4694 | } |
| 4695 | |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4696 | static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state, |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4697 | enum pipe pch_transcoder) |
| 4698 | { |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4699 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4700 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4701 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4702 | |
| 4703 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4704 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4705 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4706 | I915_READ(HBLANK(cpu_transcoder))); |
| 4707 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4708 | I915_READ(HSYNC(cpu_transcoder))); |
| 4709 | |
| 4710 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4711 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4712 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4713 | I915_READ(VBLANK(cpu_transcoder))); |
| 4714 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4715 | I915_READ(VSYNC(cpu_transcoder))); |
| 4716 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4717 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4718 | } |
| 4719 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4720 | static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4721 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 4722 | u32 temp; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4723 | |
| 4724 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4725 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4726 | return; |
| 4727 | |
| 4728 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4729 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4730 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4731 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4732 | if (enable) |
| 4733 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4734 | |
| 4735 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4736 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4737 | POSTING_READ(SOUTH_CHICKEN1); |
| 4738 | } |
| 4739 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4740 | static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4741 | { |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4742 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4743 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4744 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4745 | switch (crtc->pipe) { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4746 | case PIPE_A: |
| 4747 | break; |
| 4748 | case PIPE_B: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4749 | if (crtc_state->fdi_lanes > 2) |
| 4750 | cpt_set_fdi_bc_bifurcation(dev_priv, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4751 | else |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4752 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4753 | |
| 4754 | break; |
| 4755 | case PIPE_C: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4756 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4757 | |
| 4758 | break; |
| 4759 | default: |
| 4760 | BUG(); |
| 4761 | } |
| 4762 | } |
| 4763 | |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4764 | /* |
| 4765 | * Finds the encoder associated with the given CRTC. This can only be |
| 4766 | * used when we know that the CRTC isn't feeding multiple encoders! |
| 4767 | */ |
| 4768 | static struct intel_encoder * |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4769 | intel_get_crtc_new_encoder(const struct intel_atomic_state *state, |
| 4770 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4771 | { |
| 4772 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4773 | const struct drm_connector_state *connector_state; |
| 4774 | const struct drm_connector *connector; |
| 4775 | struct intel_encoder *encoder = NULL; |
| 4776 | int num_encoders = 0; |
| 4777 | int i; |
| 4778 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4779 | for_each_new_connector_in_state(&state->base, connector, connector_state, i) { |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4780 | if (connector_state->crtc != &crtc->base) |
| 4781 | continue; |
| 4782 | |
| 4783 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 4784 | num_encoders++; |
| 4785 | } |
| 4786 | |
| 4787 | WARN(num_encoders != 1, "%d encoders for pipe %c\n", |
| 4788 | num_encoders, pipe_name(crtc->pipe)); |
| 4789 | |
| 4790 | return encoder; |
| 4791 | } |
| 4792 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4793 | /* |
| 4794 | * Enable PCH resources required for PCH ports: |
| 4795 | * - PCH PLLs |
| 4796 | * - FDI training & RX/TX |
| 4797 | * - update transcoder timings |
| 4798 | * - DP transcoding bits |
| 4799 | * - transcoder |
| 4800 | */ |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4801 | static void ironlake_pch_enable(const struct intel_atomic_state *state, |
| 4802 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4803 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4804 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4805 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4806 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4807 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4808 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4809 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4810 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4811 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4812 | if (IS_IVYBRIDGE(dev_priv)) |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4813 | ivybridge_update_fdi_bc_bifurcation(crtc_state); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4814 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4815 | /* Write the TU size bits before fdi link training, so that error |
| 4816 | * detection works. */ |
| 4817 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4818 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4819 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4820 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4821 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4822 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4823 | /* We need to program the right clock selection before writing the pixel |
| 4824 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4825 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4826 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4827 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4828 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4829 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4830 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4831 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4832 | intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4833 | temp |= sel; |
| 4834 | else |
| 4835 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4836 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4837 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4838 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4839 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4840 | * transcoder, and we actually should do this to not upset any PCH |
| 4841 | * transcoder that already use the clock when we share it. |
| 4842 | * |
| 4843 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4844 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4845 | * the right LVDS enable sequence. */ |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 4846 | intel_enable_shared_dpll(crtc_state); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4847 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4848 | /* set transcoder timing, panel must allow it */ |
| 4849 | assert_panel_unlocked(dev_priv, pipe); |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4850 | ironlake_pch_transcoder_set_timings(crtc_state, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4851 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4852 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4853 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4854 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4855 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4856 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4857 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4858 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4859 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4860 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4861 | enum port port; |
| 4862 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4863 | temp = I915_READ(reg); |
| 4864 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4865 | TRANS_DP_SYNC_MASK | |
| 4866 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4867 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4868 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4869 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4870 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4871 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4872 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4873 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4874 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4875 | port = intel_get_crtc_new_encoder(state, crtc_state)->port; |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4876 | WARN_ON(port < PORT_B || port > PORT_D); |
| 4877 | temp |= TRANS_DP_PORT_SEL(port); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4878 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4879 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 4882 | ironlake_enable_pch_transcoder(crtc_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4885 | static void lpt_pch_enable(const struct intel_atomic_state *state, |
| 4886 | const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4887 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4888 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4889 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4890 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4891 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4892 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4893 | |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4894 | lpt_program_iclkip(crtc_state); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4895 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4896 | /* Set transcoder timing. */ |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4897 | ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4898 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4899 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4900 | } |
| 4901 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4902 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4903 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4904 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4905 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4906 | u32 temp; |
| 4907 | |
| 4908 | temp = I915_READ(dslreg); |
| 4909 | udelay(500); |
| 4910 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4911 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4912 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4913 | } |
| 4914 | } |
| 4915 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4916 | /* |
| 4917 | * The hardware phase 0.0 refers to the center of the pixel. |
| 4918 | * We want to start from the top/left edge which is phase |
| 4919 | * -0.5. That matches how the hardware calculates the scaling |
| 4920 | * factors (from top-left of the first pixel to bottom-right |
| 4921 | * of the last pixel, as opposed to the pixel centers). |
| 4922 | * |
| 4923 | * For 4:2:0 subsampled chroma planes we obviously have to |
| 4924 | * adjust that so that the chroma sample position lands in |
| 4925 | * the right spot. |
| 4926 | * |
| 4927 | * Note that for packed YCbCr 4:2:2 formats there is no way to |
| 4928 | * control chroma siting. The hardware simply replicates the |
| 4929 | * chroma samples for both of the luma samples, and thus we don't |
| 4930 | * actually get the expected MPEG2 chroma siting convention :( |
| 4931 | * The same behaviour is observed on pre-SKL platforms as well. |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4932 | * |
| 4933 | * Theory behind the formula (note that we ignore sub-pixel |
| 4934 | * source coordinates): |
| 4935 | * s = source sample position |
| 4936 | * d = destination sample position |
| 4937 | * |
| 4938 | * Downscaling 4:1: |
| 4939 | * -0.5 |
| 4940 | * | 0.0 |
| 4941 | * | | 1.5 (initial phase) |
| 4942 | * | | | |
| 4943 | * v v v |
| 4944 | * | s | s | s | s | |
| 4945 | * | d | |
| 4946 | * |
| 4947 | * Upscaling 1:4: |
| 4948 | * -0.5 |
| 4949 | * | -0.375 (initial phase) |
| 4950 | * | | 0.0 |
| 4951 | * | | | |
| 4952 | * v v v |
| 4953 | * | s | |
| 4954 | * | d | d | d | d | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4955 | */ |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4956 | u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited) |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4957 | { |
| 4958 | int phase = -0x8000; |
| 4959 | u16 trip = 0; |
| 4960 | |
| 4961 | if (chroma_cosited) |
| 4962 | phase += (sub - 1) * 0x8000 / sub; |
| 4963 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4964 | phase += scale / (2 * sub); |
| 4965 | |
| 4966 | /* |
| 4967 | * Hardware initial phase limited to [-0.5:1.5]. |
| 4968 | * Since the max hardware scale factor is 3.0, we |
| 4969 | * should never actually excdeed 1.0 here. |
| 4970 | */ |
| 4971 | WARN_ON(phase < -0x8000 || phase > 0x18000); |
| 4972 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4973 | if (phase < 0) |
| 4974 | phase = 0x10000 + phase; |
| 4975 | else |
| 4976 | trip = PS_PHASE_TRIP; |
| 4977 | |
| 4978 | return ((phase >> 2) & PS_PHASE_MASK) | trip; |
| 4979 | } |
| 4980 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4981 | static int |
| 4982 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4983 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4984 | int src_w, int src_h, int dst_w, int dst_h, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4985 | const struct drm_format_info *format, bool need_scaler) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4986 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4987 | struct intel_crtc_scaler_state *scaler_state = |
| 4988 | &crtc_state->scaler_state; |
| 4989 | struct intel_crtc *intel_crtc = |
| 4990 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4991 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4992 | const struct drm_display_mode *adjusted_mode = |
| 4993 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4994 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4995 | /* |
| 4996 | * Src coordinates are already rotated by 270 degrees for |
| 4997 | * the 90/270 degree plane rotation cases (to match the |
| 4998 | * GTT mapping), hence no need to account for rotation here. |
| 4999 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5000 | if (src_w != dst_w || src_h != dst_h) |
| 5001 | need_scaler = true; |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 5002 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5003 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 5004 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 5005 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 5006 | * Once NV12 is enabled, handle it here while allocating scaler |
| 5007 | * for NV12. |
| 5008 | */ |
| 5009 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5010 | need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 5011 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 5012 | return -EINVAL; |
| 5013 | } |
| 5014 | |
| 5015 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5016 | * if plane is being disabled or scaler is no more required or force detach |
| 5017 | * - free scaler binded to this plane/crtc |
| 5018 | * - in order to do this, update crtc->scaler_usage |
| 5019 | * |
| 5020 | * Here scaler state in crtc_state is set free so that |
| 5021 | * scaler can be assigned to other user. Actual register |
| 5022 | * update to free the scaler is done in plane/panel-fit programming. |
| 5023 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 5024 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5025 | if (force_detach || !need_scaler) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5026 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5027 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5028 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 5029 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5030 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 5031 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 5032 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5033 | scaler_state->scaler_users); |
| 5034 | *scaler_id = -1; |
| 5035 | } |
| 5036 | return 0; |
| 5037 | } |
| 5038 | |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5039 | if (format && format->format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 5040 | (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) { |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5041 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 5042 | return -EINVAL; |
| 5043 | } |
| 5044 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5045 | /* range checks */ |
| 5046 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 5047 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5048 | (IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 5049 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 5050 | dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) || |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5051 | (!IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 5052 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 5053 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5054 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5055 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5056 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5057 | return -EINVAL; |
| 5058 | } |
| 5059 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5060 | /* mark this plane as a scaler user in crtc_state */ |
| 5061 | scaler_state->scaler_users |= (1 << scaler_user); |
| 5062 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 5063 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 5064 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 5065 | scaler_state->scaler_users); |
| 5066 | |
| 5067 | return 0; |
| 5068 | } |
| 5069 | |
| 5070 | /** |
| 5071 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 5072 | * |
| 5073 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5074 | * |
| 5075 | * Return |
| 5076 | * 0 - scaler_usage updated successfully |
| 5077 | * error - requested scaling cannot be supported or other error condition |
| 5078 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5079 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5080 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 5081 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5082 | bool need_scaler = false; |
| 5083 | |
| 5084 | if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
| 5085 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5086 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5087 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5088 | &state->scaler_state.scaler_id, |
| 5089 | state->pipe_src_w, state->pipe_src_h, |
| 5090 | adjusted_mode->crtc_hdisplay, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5091 | adjusted_mode->crtc_vdisplay, NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5092 | } |
| 5093 | |
| 5094 | /** |
| 5095 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5096 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5097 | * @plane_state: atomic plane state to update |
| 5098 | * |
| 5099 | * Return |
| 5100 | * 0 - scaler_usage updated successfully |
| 5101 | * error - requested scaling cannot be supported or other error condition |
| 5102 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 5103 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 5104 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5105 | { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 5106 | struct intel_plane *intel_plane = |
| 5107 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5108 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 5109 | int ret; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5110 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5111 | bool need_scaler = false; |
| 5112 | |
| 5113 | /* Pre-gen11 and SDR planes always need a scaler for planar formats. */ |
| 5114 | if (!icl_is_hdr_plane(intel_plane) && |
| 5115 | fb && fb->format->format == DRM_FORMAT_NV12) |
| 5116 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5117 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5118 | ret = skl_update_scaler(crtc_state, force_detach, |
| 5119 | drm_plane_index(&intel_plane->base), |
| 5120 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5121 | drm_rect_width(&plane_state->base.src) >> 16, |
| 5122 | drm_rect_height(&plane_state->base.src) >> 16, |
| 5123 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5124 | drm_rect_height(&plane_state->base.dst), |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5125 | fb ? fb->format : NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5126 | |
| 5127 | if (ret || plane_state->scaler_id < 0) |
| 5128 | return ret; |
| 5129 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5130 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 5131 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5132 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 5133 | intel_plane->base.base.id, |
| 5134 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5135 | return -EINVAL; |
| 5136 | } |
| 5137 | |
| 5138 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5139 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5140 | case DRM_FORMAT_RGB565: |
| 5141 | case DRM_FORMAT_XBGR8888: |
| 5142 | case DRM_FORMAT_XRGB8888: |
| 5143 | case DRM_FORMAT_ABGR8888: |
| 5144 | case DRM_FORMAT_ARGB8888: |
| 5145 | case DRM_FORMAT_XRGB2101010: |
| 5146 | case DRM_FORMAT_XBGR2101010: |
| 5147 | case DRM_FORMAT_YUYV: |
| 5148 | case DRM_FORMAT_YVYU: |
| 5149 | case DRM_FORMAT_UYVY: |
| 5150 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5151 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5152 | break; |
| 5153 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5154 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 5155 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5156 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5157 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5160 | return 0; |
| 5161 | } |
| 5162 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5163 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 5164 | { |
| 5165 | int i; |
| 5166 | |
| 5167 | for (i = 0; i < crtc->num_scalers; i++) |
| 5168 | skl_detach_scaler(crtc, i); |
| 5169 | } |
| 5170 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5171 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5172 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5173 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5174 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5175 | enum pipe pipe = crtc->pipe; |
| 5176 | const struct intel_crtc_scaler_state *scaler_state = |
| 5177 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5178 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5179 | if (crtc_state->pch_pfit.enabled) { |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5180 | u16 uv_rgb_hphase, uv_rgb_vphase; |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5181 | int pfit_w, pfit_h, hscale, vscale; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5182 | int id; |
| 5183 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5184 | if (WARN_ON(crtc_state->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5185 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5186 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5187 | pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF; |
| 5188 | pfit_h = crtc_state->pch_pfit.size & 0xFFFF; |
| 5189 | |
| 5190 | hscale = (crtc_state->pipe_src_w << 16) / pfit_w; |
| 5191 | vscale = (crtc_state->pipe_src_h << 16) / pfit_h; |
| 5192 | |
| 5193 | uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false); |
| 5194 | uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5195 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5196 | id = scaler_state->scaler_id; |
| 5197 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 5198 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5199 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, id), |
| 5200 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase)); |
| 5201 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, id), |
| 5202 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase)); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5203 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos); |
| 5204 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5205 | } |
| 5206 | } |
| 5207 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5208 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5209 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5210 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5211 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5212 | int pipe = crtc->pipe; |
| 5213 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5214 | if (crtc_state->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5215 | /* Force use of hard-coded filter coefficients |
| 5216 | * as some pre-programmed values are broken, |
| 5217 | * e.g. x201. |
| 5218 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5219 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5220 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 5221 | PF_PIPE_SEL_IVB(pipe)); |
| 5222 | else |
| 5223 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5224 | I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos); |
| 5225 | I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 5226 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5227 | } |
| 5228 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5229 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5230 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5231 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 5232 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5233 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5234 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5235 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5236 | return; |
| 5237 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 5238 | /* |
| 5239 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 5240 | * This function is called from post_plane_update, which is run after |
| 5241 | * a vblank wait. |
| 5242 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5243 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 5244 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5245 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5246 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 5247 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 5248 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5249 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5250 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 5251 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5252 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 5253 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5254 | */ |
| 5255 | } else { |
| 5256 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 5257 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 5258 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5259 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5260 | * the HW state readout code will complain that the expected |
| 5261 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5262 | if (intel_wait_for_register(dev_priv, |
| 5263 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5264 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5265 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5266 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5267 | } |
| 5268 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5269 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5270 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5271 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5272 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5273 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5274 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5275 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5276 | return; |
| 5277 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5278 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5279 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5280 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5281 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5282 | /* |
| 5283 | * Wait for PCODE to finish disabling IPS. The BSpec specified |
| 5284 | * 42ms timeout value leads to occasional timeouts so use 100ms |
| 5285 | * instead. |
| 5286 | */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5287 | if (intel_wait_for_register(dev_priv, |
| 5288 | IPS_CTL, IPS_ENABLE, 0, |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5289 | 100)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5290 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5291 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5292 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5293 | POSTING_READ(IPS_CTL); |
| 5294 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5295 | |
| 5296 | /* We need to wait for a vblank before we can disable the plane. */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5297 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5298 | } |
| 5299 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5300 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5301 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5302 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5303 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5304 | |
| 5305 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5306 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5307 | mutex_unlock(&dev->struct_mutex); |
| 5308 | } |
| 5309 | |
| 5310 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5311 | * has to recompute where to put it anyway. |
| 5312 | */ |
| 5313 | } |
| 5314 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5315 | /** |
| 5316 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5317 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5318 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5319 | * |
| 5320 | * Performs potentially sleeping operations that must be done after the primary |
| 5321 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5322 | * called due to an explicit primary plane update, or due to an implicit |
| 5323 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5324 | * completely hide the primary plane. |
| 5325 | */ |
| 5326 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5327 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5328 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5329 | { |
| 5330 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5331 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5332 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5333 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5334 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5335 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5336 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5337 | * So don't enable underrun reporting before at least some planes |
| 5338 | * are enabled. |
| 5339 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5340 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5341 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5342 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5343 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5344 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5345 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5346 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5347 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5348 | } |
| 5349 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5350 | /* FIXME get rid of this and use pre_plane_update */ |
| 5351 | static void |
| 5352 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5353 | { |
| 5354 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5355 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5356 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5357 | int pipe = intel_crtc->pipe; |
| 5358 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5359 | /* |
| 5360 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5361 | * So disable underrun reporting before all the planes get disabled. |
| 5362 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5363 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5364 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5365 | |
| 5366 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5367 | |
| 5368 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5369 | * Vblank time updates from the shadow to live plane control register |
| 5370 | * are blocked if the memory self-refresh mode is active at that |
| 5371 | * moment. So to make sure the plane gets truly disabled, disable |
| 5372 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5373 | * will be checked/applied by the HW only at the next frame start |
| 5374 | * event which is after the vblank start event, so we need to have a |
| 5375 | * wait-for-vblank between disabling the plane and the pipe. |
| 5376 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 5377 | if (HAS_GMCH(dev_priv) && |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5378 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5379 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5380 | } |
| 5381 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5382 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5383 | const struct intel_crtc_state *new_crtc_state) |
| 5384 | { |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5385 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5386 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5387 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5388 | if (!old_crtc_state->ips_enabled) |
| 5389 | return false; |
| 5390 | |
| 5391 | if (needs_modeset(&new_crtc_state->base)) |
| 5392 | return true; |
| 5393 | |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5394 | /* |
| 5395 | * Workaround : Do not read or write the pipe palette/gamma data while |
| 5396 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 5397 | * |
| 5398 | * Disable IPS before we program the LUT. |
| 5399 | */ |
| 5400 | if (IS_HASWELL(dev_priv) && |
| 5401 | (new_crtc_state->base.color_mgmt_changed || |
| 5402 | new_crtc_state->update_pipe) && |
| 5403 | new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT) |
| 5404 | return true; |
| 5405 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5406 | return !new_crtc_state->ips_enabled; |
| 5407 | } |
| 5408 | |
| 5409 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5410 | const struct intel_crtc_state *new_crtc_state) |
| 5411 | { |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5412 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5413 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5414 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5415 | if (!new_crtc_state->ips_enabled) |
| 5416 | return false; |
| 5417 | |
| 5418 | if (needs_modeset(&new_crtc_state->base)) |
| 5419 | return true; |
| 5420 | |
| 5421 | /* |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5422 | * Workaround : Do not read or write the pipe palette/gamma data while |
| 5423 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 5424 | * |
| 5425 | * Re-enable IPS after the LUT has been programmed. |
| 5426 | */ |
| 5427 | if (IS_HASWELL(dev_priv) && |
| 5428 | (new_crtc_state->base.color_mgmt_changed || |
| 5429 | new_crtc_state->update_pipe) && |
| 5430 | new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT) |
| 5431 | return true; |
| 5432 | |
| 5433 | /* |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5434 | * We can't read out IPS on broadwell, assume the worst and |
| 5435 | * forcibly enable IPS on the first fastset. |
| 5436 | */ |
| 5437 | if (new_crtc_state->update_pipe && |
| 5438 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5439 | return true; |
| 5440 | |
| 5441 | return !old_crtc_state->ips_enabled; |
| 5442 | } |
| 5443 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5444 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5445 | const struct intel_crtc_state *crtc_state) |
| 5446 | { |
| 5447 | if (!crtc_state->nv12_planes) |
| 5448 | return false; |
| 5449 | |
Rodrigo Vivi | 1347d3c | 2018-10-31 09:28:45 -0700 | [diff] [blame] | 5450 | /* WA Display #0827: Gen9:all */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5451 | if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv)) |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5452 | return true; |
| 5453 | |
| 5454 | return false; |
| 5455 | } |
| 5456 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5457 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5458 | { |
| 5459 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5460 | struct drm_device *dev = crtc->base.dev; |
| 5461 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5462 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5463 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5464 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5465 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5466 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5467 | struct drm_plane_state *old_primary_state = |
| 5468 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5469 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5470 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5471 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5472 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5473 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5474 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5475 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5476 | hsw_enable_ips(pipe_config); |
| 5477 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5478 | if (old_primary_state) { |
| 5479 | struct drm_plane_state *new_primary_state = |
| 5480 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5481 | |
| 5482 | intel_fbc_post_update(crtc); |
| 5483 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5484 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5485 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5486 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5487 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5488 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5489 | |
| 5490 | /* Display WA 827 */ |
| 5491 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5492 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5493 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5494 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5495 | } |
| 5496 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5497 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5498 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5499 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5500 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5501 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5502 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5503 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5504 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5505 | struct drm_plane_state *old_primary_state = |
| 5506 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5507 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5508 | struct intel_atomic_state *old_intel_state = |
| 5509 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5510 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5511 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5512 | hsw_disable_ips(old_crtc_state); |
| 5513 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5514 | if (old_primary_state) { |
| 5515 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5516 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5517 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5518 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5519 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5520 | /* |
| 5521 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5522 | * So disable underrun reporting before all the planes get disabled. |
| 5523 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5524 | if (IS_GEN(dev_priv, 2) && old_primary_state->visible && |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5525 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5526 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5527 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5528 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5529 | /* Display WA 827 */ |
| 5530 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5531 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5532 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5533 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5534 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5535 | /* |
| 5536 | * Vblank time updates from the shadow to live plane control register |
| 5537 | * are blocked if the memory self-refresh mode is active at that |
| 5538 | * moment. So to make sure the plane gets truly disabled, disable |
| 5539 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5540 | * will be checked/applied by the HW only at the next frame start |
| 5541 | * event which is after the vblank start event, so we need to have a |
| 5542 | * wait-for-vblank between disabling the plane and the pipe. |
| 5543 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 5544 | if (HAS_GMCH(dev_priv) && old_crtc_state->base.active && |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5545 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5546 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5547 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5548 | /* |
| 5549 | * IVB workaround: must disable low power watermarks for at least |
| 5550 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5551 | * when scaling is disabled. |
| 5552 | * |
| 5553 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5554 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 5555 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) && |
| 5556 | old_crtc_state->base.active) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5557 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5558 | |
| 5559 | /* |
| 5560 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5561 | * watermark programming here. |
| 5562 | */ |
| 5563 | if (needs_modeset(&pipe_config->base)) |
| 5564 | return; |
| 5565 | |
| 5566 | /* |
| 5567 | * For platforms that support atomic watermarks, program the |
| 5568 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5569 | * will be the intermediate values that are safe for both pre- and |
| 5570 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5571 | * to the final 'target' values and we'll do this again to get the |
| 5572 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5573 | * will be the final target values which will get automatically latched |
| 5574 | * at vblank time; no further programming will be necessary. |
| 5575 | * |
| 5576 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5577 | * we'll continue to update watermarks the old way, if flags tell |
| 5578 | * us to. |
| 5579 | */ |
| 5580 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5581 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5582 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5583 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5584 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5585 | } |
| 5586 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5587 | static void intel_crtc_disable_planes(struct intel_atomic_state *state, |
| 5588 | struct intel_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5589 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5590 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5591 | const struct intel_crtc_state *new_crtc_state = |
| 5592 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5593 | unsigned int update_mask = new_crtc_state->update_planes; |
| 5594 | const struct intel_plane_state *old_plane_state; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5595 | struct intel_plane *plane; |
| 5596 | unsigned fb_bits = 0; |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5597 | int i; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5598 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5599 | intel_crtc_dpms_overlay_disable(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5600 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5601 | for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { |
| 5602 | if (crtc->pipe != plane->pipe || |
| 5603 | !(update_mask & BIT(plane->id))) |
| 5604 | continue; |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5605 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5606 | plane->disable_plane(plane, new_crtc_state); |
| 5607 | |
| 5608 | if (old_plane_state->base.visible) |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5609 | fb_bits |= plane->frontbuffer_bit; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5610 | } |
| 5611 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5612 | intel_frontbuffer_flip(dev_priv, fb_bits); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5613 | } |
| 5614 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5615 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5616 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5617 | struct drm_atomic_state *old_state) |
| 5618 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5619 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5620 | struct drm_connector *conn; |
| 5621 | int i; |
| 5622 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5623 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5624 | struct intel_encoder *encoder = |
| 5625 | to_intel_encoder(conn_state->best_encoder); |
| 5626 | |
| 5627 | if (conn_state->crtc != crtc) |
| 5628 | continue; |
| 5629 | |
| 5630 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5631 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5636 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5637 | struct drm_atomic_state *old_state) |
| 5638 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5639 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5640 | struct drm_connector *conn; |
| 5641 | int i; |
| 5642 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5643 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5644 | struct intel_encoder *encoder = |
| 5645 | to_intel_encoder(conn_state->best_encoder); |
| 5646 | |
| 5647 | if (conn_state->crtc != crtc) |
| 5648 | continue; |
| 5649 | |
| 5650 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5651 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5652 | } |
| 5653 | } |
| 5654 | |
| 5655 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5656 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5657 | struct drm_atomic_state *old_state) |
| 5658 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5659 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5660 | struct drm_connector *conn; |
| 5661 | int i; |
| 5662 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5663 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5664 | struct intel_encoder *encoder = |
| 5665 | to_intel_encoder(conn_state->best_encoder); |
| 5666 | |
| 5667 | if (conn_state->crtc != crtc) |
| 5668 | continue; |
| 5669 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5670 | if (encoder->enable) |
| 5671 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5672 | intel_opregion_notify_encoder(encoder, true); |
| 5673 | } |
| 5674 | } |
| 5675 | |
| 5676 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5677 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5678 | struct drm_atomic_state *old_state) |
| 5679 | { |
| 5680 | struct drm_connector_state *old_conn_state; |
| 5681 | struct drm_connector *conn; |
| 5682 | int i; |
| 5683 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5684 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5685 | struct intel_encoder *encoder = |
| 5686 | to_intel_encoder(old_conn_state->best_encoder); |
| 5687 | |
| 5688 | if (old_conn_state->crtc != crtc) |
| 5689 | continue; |
| 5690 | |
| 5691 | intel_opregion_notify_encoder(encoder, false); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5692 | if (encoder->disable) |
| 5693 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5694 | } |
| 5695 | } |
| 5696 | |
| 5697 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5698 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5699 | struct drm_atomic_state *old_state) |
| 5700 | { |
| 5701 | struct drm_connector_state *old_conn_state; |
| 5702 | struct drm_connector *conn; |
| 5703 | int i; |
| 5704 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5705 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5706 | struct intel_encoder *encoder = |
| 5707 | to_intel_encoder(old_conn_state->best_encoder); |
| 5708 | |
| 5709 | if (old_conn_state->crtc != crtc) |
| 5710 | continue; |
| 5711 | |
| 5712 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5713 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5714 | } |
| 5715 | } |
| 5716 | |
| 5717 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5718 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5719 | struct drm_atomic_state *old_state) |
| 5720 | { |
| 5721 | struct drm_connector_state *old_conn_state; |
| 5722 | struct drm_connector *conn; |
| 5723 | int i; |
| 5724 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5725 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5726 | struct intel_encoder *encoder = |
| 5727 | to_intel_encoder(old_conn_state->best_encoder); |
| 5728 | |
| 5729 | if (old_conn_state->crtc != crtc) |
| 5730 | continue; |
| 5731 | |
| 5732 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5733 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5734 | } |
| 5735 | } |
| 5736 | |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 5737 | static void intel_encoders_update_pipe(struct drm_crtc *crtc, |
| 5738 | struct intel_crtc_state *crtc_state, |
| 5739 | struct drm_atomic_state *old_state) |
| 5740 | { |
| 5741 | struct drm_connector_state *conn_state; |
| 5742 | struct drm_connector *conn; |
| 5743 | int i; |
| 5744 | |
| 5745 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
| 5746 | struct intel_encoder *encoder = |
| 5747 | to_intel_encoder(conn_state->best_encoder); |
| 5748 | |
| 5749 | if (conn_state->crtc != crtc) |
| 5750 | continue; |
| 5751 | |
| 5752 | if (encoder->update_pipe) |
| 5753 | encoder->update_pipe(encoder, crtc_state, conn_state); |
| 5754 | } |
| 5755 | } |
| 5756 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5757 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5758 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5759 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5760 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5761 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5762 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5763 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5764 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5765 | struct intel_atomic_state *old_intel_state = |
| 5766 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5767 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5768 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5769 | return; |
| 5770 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5771 | /* |
| 5772 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5773 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5774 | * |
| 5775 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5776 | * between eDP port A enable and vdd enable. Also PCH port |
| 5777 | * enable seems to result in the occasional CPU pipe underrun. |
| 5778 | * |
| 5779 | * Spurious PCH underruns also occur during PCH enabling. |
| 5780 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5781 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5782 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5783 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5784 | if (pipe_config->has_pch_encoder) |
| 5785 | intel_prepare_shared_dpll(pipe_config); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5786 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5787 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5788 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5789 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5790 | intel_set_pipe_timings(pipe_config); |
| 5791 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5792 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5793 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5794 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5795 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5796 | } |
| 5797 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5798 | ironlake_set_pipeconf(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5799 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5800 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5801 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5802 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5803 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5804 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5805 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5806 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5807 | * enabling. */ |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 5808 | ironlake_fdi_pll_enable(pipe_config); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5809 | } else { |
| 5810 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5811 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5812 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5813 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5814 | ironlake_pfit_enable(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5815 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5816 | /* |
| 5817 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5818 | * clocks enabled |
| 5819 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5820 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 5821 | intel_color_commit(pipe_config); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5822 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5823 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5824 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5825 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5826 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5827 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5828 | ironlake_pch_enable(old_intel_state, pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5829 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5830 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 5831 | intel_crtc_vblank_on(pipe_config); |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5832 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5833 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5834 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5835 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5836 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5837 | |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5838 | /* |
| 5839 | * Must wait for vblank to avoid spurious PCH FIFO underruns. |
| 5840 | * And a second vblank wait is needed at least on ILK with |
| 5841 | * some interlaced HDMI modes. Let's do the double wait always |
| 5842 | * in case there are more corner cases we don't know about. |
| 5843 | */ |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5844 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5845 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5846 | intel_wait_for_vblank(dev_priv, pipe); |
| 5847 | } |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5848 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5849 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5852 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5853 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5854 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5855 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5856 | } |
| 5857 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5858 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5859 | enum pipe pipe, bool apply) |
| 5860 | { |
| 5861 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5862 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5863 | |
| 5864 | if (apply) |
| 5865 | val |= mask; |
| 5866 | else |
| 5867 | val &= ~mask; |
| 5868 | |
| 5869 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5870 | } |
| 5871 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5872 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5873 | { |
| 5874 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5875 | enum pipe pipe = crtc->pipe; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 5876 | u32 val; |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5877 | |
Rodrigo Vivi | 443d5e3 | 2018-10-04 08:18:14 -0700 | [diff] [blame] | 5878 | val = MBUS_DBOX_A_CREDIT(2); |
| 5879 | val |= MBUS_DBOX_BW_CREDIT(1); |
| 5880 | val |= MBUS_DBOX_B_CREDIT(8); |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5881 | |
| 5882 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5883 | } |
| 5884 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5885 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5886 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5887 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5888 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5889 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5890 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5891 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5892 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5893 | struct intel_atomic_state *old_intel_state = |
| 5894 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5895 | bool psl_clkgate_wa; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5896 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5897 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5898 | return; |
| 5899 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5900 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5901 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5902 | if (pipe_config->shared_dpll) |
| 5903 | intel_enable_shared_dpll(pipe_config); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5904 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame] | 5905 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5906 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5907 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5908 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5909 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5910 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5911 | intel_set_pipe_timings(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5912 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5913 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5914 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5915 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5916 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5917 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5918 | pipe_config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5919 | } |
| 5920 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5921 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5922 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5923 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5924 | } |
| 5925 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5926 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5927 | haswell_set_pipeconf(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5928 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5929 | haswell_set_pipemisc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5930 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5931 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5932 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5933 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5934 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5935 | pipe_config->pch_pfit.enabled; |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5936 | if (psl_clkgate_wa) |
| 5937 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5938 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5939 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5940 | skylake_pfit_enable(pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5941 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5942 | ironlake_pfit_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5943 | |
| 5944 | /* |
| 5945 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5946 | * clocks enabled |
| 5947 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5948 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 5949 | intel_color_commit(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5950 | |
Ville Syrjälä | d162211 | 2019-02-04 22:21:39 +0200 | [diff] [blame] | 5951 | if (INTEL_GEN(dev_priv) >= 11) |
| 5952 | icl_set_pipe_chicken(intel_crtc); |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5953 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5954 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5955 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5956 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5957 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5958 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5959 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5960 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5961 | if (INTEL_GEN(dev_priv) >= 11) |
| 5962 | icl_pipe_mbus_enable(intel_crtc); |
| 5963 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5964 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5965 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5966 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5967 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5968 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5969 | lpt_pch_enable(old_intel_state, pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5970 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5971 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5972 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5973 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5974 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 5975 | intel_crtc_vblank_on(pipe_config); |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5976 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5977 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5978 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5979 | if (psl_clkgate_wa) { |
| 5980 | intel_wait_for_vblank(dev_priv, pipe); |
| 5981 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5982 | } |
| 5983 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5984 | /* If we change the relative order between pipe/planes enabling, we need |
| 5985 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5986 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5987 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5988 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5989 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5990 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5991 | } |
| 5992 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5993 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5994 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5995 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5996 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5997 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5998 | |
| 5999 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 6000 | * it's in use. The hw state code will make sure we get this right. */ |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6001 | if (old_crtc_state->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 6002 | I915_WRITE(PF_CTL(pipe), 0); |
| 6003 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 6004 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 6005 | } |
| 6006 | } |
| 6007 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6008 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6009 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6010 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6011 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6012 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6013 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6014 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6015 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6016 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 6017 | /* |
| 6018 | * Sometimes spurious CPU pipe underruns happen when the |
| 6019 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 6020 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 6021 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 6022 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 6023 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 6024 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6025 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 6026 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6027 | drm_crtc_vblank_off(crtc); |
| 6028 | assert_vblank_disabled(crtc); |
| 6029 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6030 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6031 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6032 | ironlake_pfit_disable(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6033 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6034 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 6035 | ironlake_fdi_disable(crtc); |
| 6036 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6037 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6038 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6039 | if (old_crtc_state->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6040 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6041 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 6042 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 6043 | i915_reg_t reg; |
| 6044 | u32 temp; |
| 6045 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6046 | /* disable TRANS_DP_CTL */ |
| 6047 | reg = TRANS_DP_CTL(pipe); |
| 6048 | temp = I915_READ(reg); |
| 6049 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 6050 | TRANS_DP_PORT_SEL_MASK); |
| 6051 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 6052 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6053 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6054 | /* disable DPLL_SEL */ |
| 6055 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 6056 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6057 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6058 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6059 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6060 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6061 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 6062 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 6063 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 6064 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6065 | } |
| 6066 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6067 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6068 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6069 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6070 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6071 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6072 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 6073 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6074 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6075 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6076 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6077 | drm_crtc_vblank_off(crtc); |
| 6078 | assert_vblank_disabled(crtc); |
| 6079 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 6080 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 6081 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6082 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6083 | |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 6084 | if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) |
| 6085 | intel_ddi_set_vc_payload_alloc(old_crtc_state, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 6086 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 6087 | if (!transcoder_is_dsi(cpu_transcoder)) |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 6088 | intel_ddi_disable_transcoder_func(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6089 | |
Manasi Navare | a600622 | 2018-11-28 12:26:23 -0800 | [diff] [blame] | 6090 | intel_dsc_disable(old_crtc_state); |
| 6091 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6092 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 6093 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 6094 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6095 | ironlake_pfit_disable(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6096 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6097 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 6098 | |
Imre Deak | bdaa29b | 2018-11-01 16:04:24 +0200 | [diff] [blame] | 6099 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6100 | } |
| 6101 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6102 | static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6103 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6104 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6105 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6106 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6107 | if (!crtc_state->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6108 | return; |
| 6109 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 6110 | /* |
| 6111 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 6112 | * according to register description and PRM. |
| 6113 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6114 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 6115 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6116 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6117 | I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios); |
| 6118 | I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 6119 | |
| 6120 | /* Border color in case we don't scale up to the full screen. Black by |
| 6121 | * default, change to something else for debugging. */ |
| 6122 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6123 | } |
| 6124 | |
Mahesh Kumar | 176597a | 2018-10-04 14:20:43 +0530 | [diff] [blame] | 6125 | bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port) |
| 6126 | { |
| 6127 | if (port == PORT_NONE) |
| 6128 | return false; |
| 6129 | |
| 6130 | if (IS_ICELAKE(dev_priv)) |
| 6131 | return port <= PORT_B; |
| 6132 | |
| 6133 | return false; |
| 6134 | } |
| 6135 | |
Paulo Zanoni | ac213c1 | 2018-05-21 17:25:37 -0700 | [diff] [blame] | 6136 | bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port) |
| 6137 | { |
| 6138 | if (IS_ICELAKE(dev_priv)) |
| 6139 | return port >= PORT_C && port <= PORT_F; |
| 6140 | |
| 6141 | return false; |
| 6142 | } |
| 6143 | |
| 6144 | enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) |
| 6145 | { |
| 6146 | if (!intel_port_is_tc(dev_priv, port)) |
| 6147 | return PORT_TC_NONE; |
| 6148 | |
| 6149 | return port - PORT_C; |
| 6150 | } |
| 6151 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6152 | enum intel_display_power_domain intel_port_to_power_domain(enum port port) |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6153 | { |
| 6154 | switch (port) { |
| 6155 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6156 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6157 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6158 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6159 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6160 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6161 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6162 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 6163 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6164 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 6165 | case PORT_F: |
| 6166 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6167 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 6168 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6169 | return POWER_DOMAIN_PORT_OTHER; |
| 6170 | } |
| 6171 | } |
| 6172 | |
Imre Deak | 337837a | 2018-11-01 16:04:23 +0200 | [diff] [blame] | 6173 | enum intel_display_power_domain |
| 6174 | intel_aux_power_domain(struct intel_digital_port *dig_port) |
| 6175 | { |
| 6176 | switch (dig_port->aux_ch) { |
| 6177 | case AUX_CH_A: |
| 6178 | return POWER_DOMAIN_AUX_A; |
| 6179 | case AUX_CH_B: |
| 6180 | return POWER_DOMAIN_AUX_B; |
| 6181 | case AUX_CH_C: |
| 6182 | return POWER_DOMAIN_AUX_C; |
| 6183 | case AUX_CH_D: |
| 6184 | return POWER_DOMAIN_AUX_D; |
| 6185 | case AUX_CH_E: |
| 6186 | return POWER_DOMAIN_AUX_E; |
| 6187 | case AUX_CH_F: |
| 6188 | return POWER_DOMAIN_AUX_F; |
| 6189 | default: |
| 6190 | MISSING_CASE(dig_port->aux_ch); |
| 6191 | return POWER_DOMAIN_AUX_A; |
| 6192 | } |
| 6193 | } |
| 6194 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6195 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 6196 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6197 | { |
| 6198 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6199 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6200 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6201 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6202 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6203 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6204 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6205 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6206 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6207 | return 0; |
| 6208 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6209 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 6210 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6211 | if (crtc_state->pch_pfit.enabled || |
| 6212 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6213 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6214 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6215 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 6216 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 6217 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6218 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6219 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6220 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6221 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6222 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6223 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6224 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6225 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6226 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6227 | return mask; |
| 6228 | } |
| 6229 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6230 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6231 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 6232 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6233 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6234 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6235 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6236 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6237 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6238 | |
| 6239 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6240 | intel_crtc->enabled_power_domains = new_domains = |
| 6241 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6242 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6243 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6244 | |
| 6245 | for_each_power_domain(domain, domains) |
| 6246 | intel_display_power_get(dev_priv, domain); |
| 6247 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6248 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6252 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6253 | { |
| 6254 | enum intel_display_power_domain domain; |
| 6255 | |
| 6256 | for_each_power_domain(domain, domains) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 6257 | intel_display_power_put_unchecked(dev_priv, domain); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6258 | } |
| 6259 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6260 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6261 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6262 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6263 | struct intel_atomic_state *old_intel_state = |
| 6264 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6265 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6266 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6267 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6268 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6269 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6270 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6271 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6272 | return; |
| 6273 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6274 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6275 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6276 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6277 | intel_set_pipe_timings(pipe_config); |
| 6278 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6279 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6280 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6281 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6282 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6283 | } |
| 6284 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6285 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6286 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6287 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6288 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6289 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6290 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6291 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6292 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6293 | if (IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6294 | chv_prepare_pll(intel_crtc, pipe_config); |
| 6295 | chv_enable_pll(intel_crtc, pipe_config); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6296 | } else { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6297 | vlv_prepare_pll(intel_crtc, pipe_config); |
| 6298 | vlv_enable_pll(intel_crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6299 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6300 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6301 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6302 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6303 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6304 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6305 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 6306 | intel_color_commit(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6307 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6308 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6309 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6310 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6311 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6312 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 6313 | intel_crtc_vblank_on(pipe_config); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6314 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6315 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6316 | } |
| 6317 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6318 | static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6319 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6320 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6321 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6322 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6323 | I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0); |
| 6324 | I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6325 | } |
| 6326 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6327 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6328 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6329 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6330 | struct intel_atomic_state *old_intel_state = |
| 6331 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6332 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6333 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6334 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6335 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6336 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6337 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6338 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6339 | return; |
| 6340 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6341 | i9xx_set_pll_dividers(pipe_config); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6342 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6343 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6344 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6345 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6346 | intel_set_pipe_timings(pipe_config); |
| 6347 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6348 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6349 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6350 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6351 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6352 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6353 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6354 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6355 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6356 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6357 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 6358 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6359 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6360 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6361 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6362 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 6363 | intel_color_commit(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6364 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6365 | if (dev_priv->display.initial_watermarks != NULL) |
| 6366 | dev_priv->display.initial_watermarks(old_intel_state, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6367 | pipe_config); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6368 | else |
| 6369 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6370 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6371 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6372 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 6373 | intel_crtc_vblank_on(pipe_config); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6374 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6375 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6376 | } |
| 6377 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6378 | static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state) |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6379 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6380 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 6381 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6382 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6383 | if (!old_crtc_state->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6384 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6385 | |
| 6386 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6387 | |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 6388 | DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n", |
| 6389 | I915_READ(PFIT_CONTROL)); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6390 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6391 | } |
| 6392 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6393 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6394 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6395 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6396 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6397 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6398 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6399 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6400 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6401 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6402 | /* |
| 6403 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6404 | * wait for planes to fully turn off before disabling the pipe. |
| 6405 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6406 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6407 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6408 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6409 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6410 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6411 | drm_crtc_vblank_off(crtc); |
| 6412 | assert_vblank_disabled(crtc); |
| 6413 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6414 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6415 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6416 | i9xx_pfit_disable(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6417 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6418 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6419 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6420 | if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6421 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6422 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6423 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6424 | vlv_disable_pll(dev_priv, pipe); |
| 6425 | else |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6426 | i9xx_disable_pll(old_crtc_state); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6427 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6428 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6429 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6430 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6431 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6432 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6433 | |
| 6434 | if (!dev_priv->display.initial_watermarks) |
| 6435 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6436 | |
| 6437 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6438 | if (IS_I830(dev_priv)) |
| 6439 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6440 | } |
| 6441 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6442 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6443 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6444 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6445 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6446 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6447 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6448 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6449 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6450 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6451 | struct drm_atomic_state *state; |
| 6452 | struct intel_crtc_state *crtc_state; |
| 6453 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6454 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6455 | if (!intel_crtc->active) |
| 6456 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6457 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6458 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6459 | const struct intel_plane_state *plane_state = |
| 6460 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6461 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6462 | if (plane_state->base.visible) |
| 6463 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6464 | } |
| 6465 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6466 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6467 | if (!state) { |
| 6468 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6469 | crtc->base.id, crtc->name); |
| 6470 | return; |
| 6471 | } |
| 6472 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6473 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6474 | |
| 6475 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6476 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6477 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6478 | |
| 6479 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6480 | |
| 6481 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6482 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6483 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6484 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6485 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6486 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6487 | |
| 6488 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6489 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6490 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6491 | crtc->enabled = false; |
| 6492 | crtc->state->connector_mask = 0; |
| 6493 | crtc->state->encoder_mask = 0; |
| 6494 | |
| 6495 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6496 | encoder->base.crtc = NULL; |
| 6497 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6498 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6499 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 6500 | intel_disable_shared_dpll(to_intel_crtc_state(crtc->state)); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6501 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6502 | domains = intel_crtc->enabled_power_domains; |
| 6503 | for_each_power_domain(domain, domains) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 6504 | intel_display_power_put_unchecked(dev_priv, domain); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6505 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6506 | |
| 6507 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6508 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6509 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6510 | } |
| 6511 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6512 | /* |
| 6513 | * turn all crtc's off, but do not adjust state |
| 6514 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6515 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6516 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6517 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6518 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6519 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6520 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6521 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6522 | state = drm_atomic_helper_suspend(dev); |
| 6523 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6524 | if (ret) |
| 6525 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6526 | else |
| 6527 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6528 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6529 | } |
| 6530 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6531 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6532 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6533 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6534 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6535 | drm_encoder_cleanup(encoder); |
| 6536 | kfree(intel_encoder); |
| 6537 | } |
| 6538 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6539 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6540 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6541 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6542 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6543 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6544 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6545 | |
| 6546 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6547 | connector->base.base.id, |
| 6548 | connector->base.name); |
| 6549 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6550 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6551 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6552 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6553 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6554 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6555 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6556 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6557 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6558 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6559 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6560 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6561 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6562 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6563 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6564 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6565 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6566 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6567 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6568 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6569 | "attached encoder crtc differs from connector crtc\n"); |
| 6570 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6571 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6572 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6573 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6574 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6575 | } |
| 6576 | } |
| 6577 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6578 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6579 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6580 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6581 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6582 | |
| 6583 | return 0; |
| 6584 | } |
| 6585 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6586 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6587 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6588 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6589 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6590 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6591 | struct intel_crtc *other_crtc; |
| 6592 | struct intel_crtc_state *other_crtc_state; |
| 6593 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6594 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6595 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6596 | if (pipe_config->fdi_lanes > 4) { |
| 6597 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6598 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6599 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6600 | } |
| 6601 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6602 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6603 | if (pipe_config->fdi_lanes > 2) { |
| 6604 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6605 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6606 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6607 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6608 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6609 | } |
| 6610 | } |
| 6611 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6612 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6613 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6614 | |
| 6615 | /* Ivybridge 3 pipe is really complicated */ |
| 6616 | switch (pipe) { |
| 6617 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6618 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6619 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6620 | if (pipe_config->fdi_lanes <= 2) |
| 6621 | return 0; |
| 6622 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6623 | other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6624 | other_crtc_state = |
| 6625 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6626 | if (IS_ERR(other_crtc_state)) |
| 6627 | return PTR_ERR(other_crtc_state); |
| 6628 | |
| 6629 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6630 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6631 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6632 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6633 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6634 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6635 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6636 | if (pipe_config->fdi_lanes > 2) { |
| 6637 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6638 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6639 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6640 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6641 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6642 | other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6643 | other_crtc_state = |
| 6644 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6645 | if (IS_ERR(other_crtc_state)) |
| 6646 | return PTR_ERR(other_crtc_state); |
| 6647 | |
| 6648 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6649 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6650 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6651 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6652 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6653 | default: |
| 6654 | BUG(); |
| 6655 | } |
| 6656 | } |
| 6657 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6658 | #define RETRY 1 |
| 6659 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6660 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6661 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6662 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6663 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6664 | int lane, link_bw, fdi_dotclock, ret; |
| 6665 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6666 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6667 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6668 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6669 | * each output octet as 10 bits. The actual frequency |
| 6670 | * is stored as a divider into a 100MHz clock, and the |
| 6671 | * mode pixel clock is stored in units of 1KHz. |
| 6672 | * Hence the bw of each lane in terms of the mode signal |
| 6673 | * is: |
| 6674 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6675 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6676 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6677 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6678 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6679 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6680 | pipe_config->pipe_bpp); |
| 6681 | |
| 6682 | pipe_config->fdi_lanes = lane; |
| 6683 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6684 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6685 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6686 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6687 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 6688 | if (ret == -EDEADLK) |
| 6689 | return ret; |
| 6690 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6691 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6692 | pipe_config->pipe_bpp -= 2*3; |
| 6693 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6694 | pipe_config->pipe_bpp); |
| 6695 | needs_recompute = true; |
| 6696 | pipe_config->bw_constrained = true; |
| 6697 | |
| 6698 | goto retry; |
| 6699 | } |
| 6700 | |
| 6701 | if (needs_recompute) |
| 6702 | return RETRY; |
| 6703 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6704 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6705 | } |
| 6706 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6707 | bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6708 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6709 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6710 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6711 | |
| 6712 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6713 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6714 | return false; |
| 6715 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6716 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6717 | return false; |
| 6718 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6719 | if (crtc_state->pipe_bpp > 24) |
| 6720 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6721 | |
| 6722 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6723 | * We compare against max which means we must take |
| 6724 | * the increased cdclk requirement into account when |
| 6725 | * calculating the new cdclk. |
| 6726 | * |
| 6727 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6728 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6729 | if (IS_BROADWELL(dev_priv) && |
| 6730 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6731 | return false; |
| 6732 | |
| 6733 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6734 | } |
| 6735 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6736 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6737 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6738 | struct drm_i915_private *dev_priv = |
| 6739 | to_i915(crtc_state->base.crtc->dev); |
| 6740 | struct intel_atomic_state *intel_state = |
| 6741 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6742 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6743 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6744 | return false; |
| 6745 | |
| 6746 | if (crtc_state->ips_force_disable) |
| 6747 | return false; |
| 6748 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6749 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6750 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6751 | return false; |
| 6752 | |
| 6753 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6754 | if (IS_BROADWELL(dev_priv) && |
| 6755 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6756 | return false; |
| 6757 | |
| 6758 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6759 | } |
| 6760 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6761 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6762 | { |
| 6763 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6764 | |
| 6765 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6766 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6767 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6768 | } |
| 6769 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6770 | static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6771 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6772 | u32 pixel_rate; |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6773 | |
| 6774 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6775 | |
| 6776 | /* |
| 6777 | * We only use IF-ID interlacing. If we ever use |
| 6778 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6779 | */ |
| 6780 | |
| 6781 | if (pipe_config->pch_pfit.enabled) { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6782 | u64 pipe_w, pipe_h, pfit_w, pfit_h; |
| 6783 | u32 pfit_size = pipe_config->pch_pfit.size; |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6784 | |
| 6785 | pipe_w = pipe_config->pipe_src_w; |
| 6786 | pipe_h = pipe_config->pipe_src_h; |
| 6787 | |
| 6788 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6789 | pfit_h = pfit_size & 0xFFFF; |
| 6790 | if (pipe_w < pfit_w) |
| 6791 | pipe_w = pfit_w; |
| 6792 | if (pipe_h < pfit_h) |
| 6793 | pipe_h = pfit_h; |
| 6794 | |
| 6795 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6796 | return pixel_rate; |
| 6797 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6798 | pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h, |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6799 | pfit_w * pfit_h); |
| 6800 | } |
| 6801 | |
| 6802 | return pixel_rate; |
| 6803 | } |
| 6804 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6805 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6806 | { |
| 6807 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6808 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 6809 | if (HAS_GMCH(dev_priv)) |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6810 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6811 | crtc_state->pixel_rate = |
| 6812 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6813 | else |
| 6814 | crtc_state->pixel_rate = |
| 6815 | ilk_pipe_pixel_rate(crtc_state); |
| 6816 | } |
| 6817 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6818 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6819 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6820 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6821 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6822 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6823 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6824 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6825 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6826 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6827 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6828 | |
| 6829 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6830 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6831 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6832 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6833 | if (intel_crtc_supports_double_wide(crtc) && |
| 6834 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6835 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6836 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6837 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6838 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6839 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6840 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6841 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6842 | adjusted_mode->crtc_clock, clock_limit, |
| 6843 | yesno(pipe_config->double_wide)); |
| 6844 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6845 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6846 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 6847 | if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 6848 | pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) && |
| 6849 | pipe_config->base.ctm) { |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6850 | /* |
| 6851 | * There is only one pipe CSC unit per pipe, and we need that |
| 6852 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6853 | * applied we can't support YCBCR420 output. |
| 6854 | */ |
| 6855 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6856 | return -EINVAL; |
| 6857 | } |
| 6858 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6859 | /* |
| 6860 | * Pipe horizontal size must be even in: |
| 6861 | * - DVO ganged mode |
| 6862 | * - LVDS dual channel mode |
| 6863 | * - Double wide pipe |
| 6864 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6865 | if (pipe_config->pipe_src_w & 1) { |
| 6866 | if (pipe_config->double_wide) { |
| 6867 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6868 | return -EINVAL; |
| 6869 | } |
| 6870 | |
| 6871 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6872 | intel_is_dual_link_lvds(dev)) { |
| 6873 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6874 | return -EINVAL; |
| 6875 | } |
| 6876 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6877 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6878 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6879 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6880 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6881 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6882 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6883 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6884 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6885 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6886 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6887 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6888 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6889 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6890 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6891 | } |
| 6892 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6893 | static void |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6894 | intel_reduce_m_n_ratio(u32 *num, u32 *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6895 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6896 | while (*num > DATA_LINK_M_N_MASK || |
| 6897 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6898 | *num >>= 1; |
| 6899 | *den >>= 1; |
| 6900 | } |
| 6901 | } |
| 6902 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6903 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6904 | u32 *ret_m, u32 *ret_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6905 | bool constant_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6906 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6907 | /* |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6908 | * Several DP dongles in particular seem to be fussy about |
| 6909 | * too large link M/N values. Give N value as 0x8000 that |
| 6910 | * should be acceptable by specific devices. 0x8000 is the |
| 6911 | * specified fixed N value for asynchronous clock mode, |
| 6912 | * which the devices expect also in synchronous clock mode. |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6913 | */ |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6914 | if (constant_n) |
| 6915 | *ret_n = 0x8000; |
| 6916 | else |
| 6917 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6918 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6919 | *ret_m = div_u64((u64)m * *ret_n, n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6920 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6921 | } |
| 6922 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6923 | void |
Manasi Navare | a4a1577 | 2018-11-28 13:36:21 -0800 | [diff] [blame] | 6924 | intel_link_compute_m_n(u16 bits_per_pixel, int nlanes, |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6925 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6926 | struct intel_link_m_n *m_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6927 | bool constant_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6928 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6929 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6930 | |
| 6931 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6932 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6933 | &m_n->gmch_m, &m_n->gmch_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6934 | constant_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6935 | |
| 6936 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6937 | &m_n->link_m, &m_n->link_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6938 | constant_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6939 | } |
| 6940 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6941 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6942 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6943 | if (i915_modparams.panel_use_ssc >= 0) |
| 6944 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6945 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6946 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6947 | } |
| 6948 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6949 | static u32 pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6950 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6951 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6952 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6953 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6954 | static u32 i9xx_dpll_compute_fp(struct dpll *dpll) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6955 | { |
| 6956 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6957 | } |
| 6958 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6959 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6960 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6961 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6962 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6963 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6964 | u32 fp, fp2 = 0; |
| 6965 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6966 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6967 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6968 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6969 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6970 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6971 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6972 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6973 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6974 | } |
| 6975 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6976 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6977 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6978 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6979 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6980 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6981 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6982 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6983 | } |
| 6984 | } |
| 6985 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6986 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6987 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6988 | { |
| 6989 | u32 reg_val; |
| 6990 | |
| 6991 | /* |
| 6992 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6993 | * and set it to a reasonable value instead. |
| 6994 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6995 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6996 | reg_val &= 0xffffff00; |
| 6997 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6998 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6999 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7000 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 7001 | reg_val &= 0x00ffffff; |
| 7002 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7003 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7004 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7005 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7006 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7007 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7008 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7009 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7010 | reg_val &= 0x00ffffff; |
| 7011 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7012 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7013 | } |
| 7014 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7015 | static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 7016 | const struct intel_link_m_n *m_n) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7017 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7018 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7019 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7020 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7021 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7022 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7023 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7024 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7025 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7026 | } |
| 7027 | |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7028 | static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv, |
| 7029 | enum transcoder transcoder) |
| 7030 | { |
| 7031 | if (IS_HASWELL(dev_priv)) |
| 7032 | return transcoder == TRANSCODER_EDP; |
| 7033 | |
| 7034 | /* |
| 7035 | * Strictly speaking some registers are available before |
| 7036 | * gen7, but we only support DRRS on gen7+ |
| 7037 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7038 | return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7039 | } |
| 7040 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7041 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 7042 | const struct intel_link_m_n *m_n, |
| 7043 | const struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7044 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7045 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7046 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7047 | enum pipe pipe = crtc->pipe; |
| 7048 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7049 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7050 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7051 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7052 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7053 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7054 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7055 | /* |
| 7056 | * M2_N2 registers are set only if DRRS is supported |
| 7057 | * (to make sure the registers are not unnecessarily accessed). |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7058 | */ |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7059 | if (m2_n2 && crtc_state->has_drrs && |
| 7060 | transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7061 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7062 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7063 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7064 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7065 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7066 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7067 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7068 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7069 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7070 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7071 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7072 | } |
| 7073 | } |
| 7074 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7075 | void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7076 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7077 | const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7078 | |
| 7079 | if (m_n == M1_N1) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7080 | dp_m_n = &crtc_state->dp_m_n; |
| 7081 | dp_m2_n2 = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7082 | } else if (m_n == M2_N2) { |
| 7083 | |
| 7084 | /* |
| 7085 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7086 | * needs to be programmed into M1_N1. |
| 7087 | */ |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7088 | dp_m_n = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7089 | } else { |
| 7090 | DRM_ERROR("Unsupported divider value\n"); |
| 7091 | return; |
| 7092 | } |
| 7093 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7094 | if (crtc_state->has_pch_encoder) |
| 7095 | intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7096 | else |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7097 | intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7098 | } |
| 7099 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7100 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7101 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7102 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7103 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7104 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7105 | if (crtc->pipe != PIPE_A) |
| 7106 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7107 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7108 | /* DPLL not used with DSI, but still need the rest set up */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 7109 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7110 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 7111 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 7112 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7113 | pipe_config->dpll_hw_state.dpll_md = |
| 7114 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 7115 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7116 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7117 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7118 | struct intel_crtc_state *pipe_config) |
| 7119 | { |
| 7120 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7121 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7122 | if (crtc->pipe != PIPE_A) |
| 7123 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7124 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7125 | /* DPLL not used with DSI, but still need the rest set up */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 7126 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7127 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 7128 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7129 | pipe_config->dpll_hw_state.dpll_md = |
| 7130 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7131 | } |
| 7132 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7133 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7134 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7135 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7136 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7137 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7138 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7139 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7140 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7141 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7142 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7143 | /* Enable Refclk */ |
| 7144 | I915_WRITE(DPLL(pipe), |
| 7145 | pipe_config->dpll_hw_state.dpll & |
| 7146 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 7147 | |
| 7148 | /* No need to actually set up the DPLL with DSI */ |
| 7149 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7150 | return; |
| 7151 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7152 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7153 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7154 | bestn = pipe_config->dpll.n; |
| 7155 | bestm1 = pipe_config->dpll.m1; |
| 7156 | bestm2 = pipe_config->dpll.m2; |
| 7157 | bestp1 = pipe_config->dpll.p1; |
| 7158 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7159 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7160 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7161 | |
| 7162 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7163 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7164 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7165 | |
| 7166 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7167 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7168 | |
| 7169 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7170 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7171 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7172 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7173 | |
| 7174 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7175 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7176 | |
| 7177 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7178 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7179 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7180 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7181 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7182 | |
| 7183 | /* |
| 7184 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7185 | * but we don't support that). |
| 7186 | * Note: don't use the DAC post divider as it seems unstable. |
| 7187 | */ |
| 7188 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7189 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7190 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7191 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7192 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7193 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7194 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7195 | if (pipe_config->port_clock == 162000 || |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7196 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) || |
| 7197 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7198 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7199 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7200 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7201 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7202 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7203 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7204 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7205 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7206 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7207 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7208 | 0x0df40000); |
| 7209 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7210 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7211 | 0x0df70000); |
| 7212 | } else { /* HDMI or VGA */ |
| 7213 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7214 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7215 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7216 | 0x0df70000); |
| 7217 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7218 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7219 | 0x0df40000); |
| 7220 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7221 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7222 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7223 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7224 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7225 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7226 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7227 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7228 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7229 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7230 | } |
| 7231 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7232 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7233 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7234 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7235 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7236 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7237 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7238 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7239 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7240 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7241 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7242 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7243 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7244 | /* Enable Refclk and SSC */ |
| 7245 | I915_WRITE(DPLL(pipe), |
| 7246 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7247 | |
| 7248 | /* No need to actually set up the DPLL with DSI */ |
| 7249 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7250 | return; |
| 7251 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7252 | bestn = pipe_config->dpll.n; |
| 7253 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7254 | bestm1 = pipe_config->dpll.m1; |
| 7255 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7256 | bestp1 = pipe_config->dpll.p1; |
| 7257 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7258 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7259 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7260 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7261 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7262 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7263 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7264 | /* p1 and p2 divider */ |
| 7265 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7266 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7267 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7268 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7269 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7270 | |
| 7271 | /* Feedback post-divider - m2 */ |
| 7272 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7273 | |
| 7274 | /* Feedback refclk divider - n and m1 */ |
| 7275 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7276 | DPIO_CHV_M1_DIV_BY_2 | |
| 7277 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7278 | |
| 7279 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7280 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7281 | |
| 7282 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7283 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7284 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7285 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7286 | if (bestm2_frac) |
| 7287 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7288 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7289 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7290 | /* Program digital lock detect threshold */ |
| 7291 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7292 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7293 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7294 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7295 | if (!bestm2_frac) |
| 7296 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7297 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7298 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7299 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7300 | if (vco == 5400000) { |
| 7301 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7302 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7303 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7304 | tribuf_calcntr = 0x9; |
| 7305 | } else if (vco <= 6200000) { |
| 7306 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7307 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7308 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7309 | tribuf_calcntr = 0x9; |
| 7310 | } else if (vco <= 6480000) { |
| 7311 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7312 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7313 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7314 | tribuf_calcntr = 0x8; |
| 7315 | } else { |
| 7316 | /* Not supported. Apply the same limits as in the max case */ |
| 7317 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7318 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7319 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7320 | tribuf_calcntr = 0; |
| 7321 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7322 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7323 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7324 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7325 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7326 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7327 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7328 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7329 | /* AFC Recal */ |
| 7330 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7331 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7332 | DPIO_AFC_RECAL); |
| 7333 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7334 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7335 | } |
| 7336 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7337 | /** |
| 7338 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7339 | * @dev_priv: i915 private structure |
| 7340 | * @pipe: pipe PLL to enable |
| 7341 | * @dpll: PLL configuration |
| 7342 | * |
| 7343 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7344 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7345 | * be enabled. |
| 7346 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7347 | int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe, |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7348 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7349 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7350 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7351 | struct intel_crtc_state *pipe_config; |
| 7352 | |
| 7353 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7354 | if (!pipe_config) |
| 7355 | return -ENOMEM; |
| 7356 | |
| 7357 | pipe_config->base.crtc = &crtc->base; |
| 7358 | pipe_config->pixel_multiplier = 1; |
| 7359 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7360 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7361 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7362 | chv_compute_dpll(crtc, pipe_config); |
| 7363 | chv_prepare_pll(crtc, pipe_config); |
| 7364 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7365 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7366 | vlv_compute_dpll(crtc, pipe_config); |
| 7367 | vlv_prepare_pll(crtc, pipe_config); |
| 7368 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7369 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7370 | |
| 7371 | kfree(pipe_config); |
| 7372 | |
| 7373 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7374 | } |
| 7375 | |
| 7376 | /** |
| 7377 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7378 | * @dev_priv: i915 private structure |
| 7379 | * @pipe: pipe PLL to disable |
| 7380 | * |
| 7381 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7382 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7383 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7384 | void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7385 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7386 | if (IS_CHERRYVIEW(dev_priv)) |
| 7387 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7388 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7389 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7390 | } |
| 7391 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7392 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7393 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7394 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7395 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7396 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7397 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7398 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7399 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7400 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7401 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7402 | dpll = DPLL_VGA_MODE_DIS; |
| 7403 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7404 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7405 | dpll |= DPLLB_MODE_LVDS; |
| 7406 | else |
| 7407 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7408 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7409 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7410 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7411 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7412 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7413 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7414 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7415 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7416 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7417 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7418 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7419 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7420 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7421 | |
| 7422 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7423 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7424 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7425 | else { |
| 7426 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7427 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7428 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7429 | } |
| 7430 | switch (clock->p2) { |
| 7431 | case 5: |
| 7432 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7433 | break; |
| 7434 | case 7: |
| 7435 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7436 | break; |
| 7437 | case 10: |
| 7438 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7439 | break; |
| 7440 | case 14: |
| 7441 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7442 | break; |
| 7443 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7444 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7445 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7446 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7447 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7448 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7449 | else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7450 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7451 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7452 | else |
| 7453 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7454 | |
| 7455 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7456 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7457 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7458 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7459 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7460 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7461 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7462 | } |
| 7463 | } |
| 7464 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7465 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7466 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7467 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7468 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7469 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7470 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7471 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7472 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7473 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7474 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7475 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7476 | dpll = DPLL_VGA_MODE_DIS; |
| 7477 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7478 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7479 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7480 | } else { |
| 7481 | if (clock->p1 == 2) |
| 7482 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7483 | else |
| 7484 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7485 | if (clock->p2 == 4) |
| 7486 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7487 | } |
| 7488 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7489 | if (!IS_I830(dev_priv) && |
| 7490 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7491 | dpll |= DPLL_DVO_2X_MODE; |
| 7492 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7493 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7494 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7495 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7496 | else |
| 7497 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7498 | |
| 7499 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7500 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7501 | } |
| 7502 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7503 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7504 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7505 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7506 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7507 | enum pipe pipe = crtc->pipe; |
| 7508 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 7509 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7510 | u32 crtc_vtotal, crtc_vblank_end; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7511 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7512 | |
| 7513 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7514 | * the hw state checker will get angry at the mismatch. */ |
| 7515 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7516 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7517 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7518 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7519 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7520 | crtc_vtotal -= 1; |
| 7521 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7522 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7523 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7524 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7525 | else |
| 7526 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7527 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7528 | if (vsyncshift < 0) |
| 7529 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7530 | } |
| 7531 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7532 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7533 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7534 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7535 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7536 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7537 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7538 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7539 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7540 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7541 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7542 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7543 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7544 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7545 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7546 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7547 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7548 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7549 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7550 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7551 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7552 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7553 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7554 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7555 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7556 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7557 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7558 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7559 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7560 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7561 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7562 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7563 | } |
| 7564 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7565 | static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state) |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7566 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7567 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7568 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7569 | enum pipe pipe = crtc->pipe; |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7570 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7571 | /* pipesrc controls the size that is scaled from, which should |
| 7572 | * always be the user's requested size. |
| 7573 | */ |
| 7574 | I915_WRITE(PIPESRC(pipe), |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7575 | ((crtc_state->pipe_src_w - 1) << 16) | |
| 7576 | (crtc_state->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7577 | } |
| 7578 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7579 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7580 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7581 | { |
| 7582 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7583 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7584 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7585 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7586 | |
| 7587 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7588 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7589 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7590 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7591 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7592 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7593 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7594 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7595 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7596 | |
| 7597 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7598 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7599 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7600 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7601 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7602 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7603 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7604 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7605 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7606 | |
| 7607 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7608 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7609 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7610 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7611 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7612 | } |
| 7613 | |
| 7614 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7615 | struct intel_crtc_state *pipe_config) |
| 7616 | { |
| 7617 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7618 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7619 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7620 | |
| 7621 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7622 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7623 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7624 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7625 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7626 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7627 | } |
| 7628 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7629 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7630 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7631 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7632 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7633 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7634 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7635 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7636 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7637 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7638 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7639 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7640 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7641 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7642 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7643 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7644 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7645 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7646 | |
| 7647 | mode->hsync = drm_mode_hsync(mode); |
| 7648 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7649 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7650 | } |
| 7651 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7652 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7653 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7654 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7655 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7656 | u32 pipeconf; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7657 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7658 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7659 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7660 | /* we keep both pipes enabled on 830 */ |
| 7661 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7662 | pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7663 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7664 | if (crtc_state->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7665 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7666 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7667 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7668 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7669 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7670 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7671 | if (crtc_state->dither && crtc_state->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7672 | pipeconf |= PIPECONF_DITHER_EN | |
| 7673 | PIPECONF_DITHER_TYPE_SP; |
| 7674 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7675 | switch (crtc_state->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7676 | case 18: |
| 7677 | pipeconf |= PIPECONF_6BPC; |
| 7678 | break; |
| 7679 | case 24: |
| 7680 | pipeconf |= PIPECONF_8BPC; |
| 7681 | break; |
| 7682 | case 30: |
| 7683 | pipeconf |= PIPECONF_10BPC; |
| 7684 | break; |
| 7685 | default: |
| 7686 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7687 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7688 | } |
| 7689 | } |
| 7690 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7691 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7692 | if (INTEL_GEN(dev_priv) < 4 || |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7693 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7694 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7695 | else |
| 7696 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7697 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7698 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7699 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7700 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7701 | crtc_state->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7702 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7703 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7704 | I915_WRITE(PIPECONF(crtc->pipe), pipeconf); |
| 7705 | POSTING_READ(PIPECONF(crtc->pipe)); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7706 | } |
| 7707 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7708 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7709 | struct intel_crtc_state *crtc_state) |
| 7710 | { |
| 7711 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7712 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7713 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7714 | int refclk = 48000; |
| 7715 | |
| 7716 | memset(&crtc_state->dpll_hw_state, 0, |
| 7717 | sizeof(crtc_state->dpll_hw_state)); |
| 7718 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7719 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7720 | if (intel_panel_use_ssc(dev_priv)) { |
| 7721 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7722 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7723 | } |
| 7724 | |
| 7725 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7726 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7727 | limit = &intel_limits_i8xx_dvo; |
| 7728 | } else { |
| 7729 | limit = &intel_limits_i8xx_dac; |
| 7730 | } |
| 7731 | |
| 7732 | if (!crtc_state->clock_set && |
| 7733 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7734 | refclk, NULL, &crtc_state->dpll)) { |
| 7735 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7736 | return -EINVAL; |
| 7737 | } |
| 7738 | |
| 7739 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7740 | |
| 7741 | return 0; |
| 7742 | } |
| 7743 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7744 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7745 | struct intel_crtc_state *crtc_state) |
| 7746 | { |
| 7747 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7748 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7749 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7750 | int refclk = 96000; |
| 7751 | |
| 7752 | memset(&crtc_state->dpll_hw_state, 0, |
| 7753 | sizeof(crtc_state->dpll_hw_state)); |
| 7754 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7755 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7756 | if (intel_panel_use_ssc(dev_priv)) { |
| 7757 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7758 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7759 | } |
| 7760 | |
| 7761 | if (intel_is_dual_link_lvds(dev)) |
| 7762 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7763 | else |
| 7764 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7765 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7766 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7767 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7768 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7769 | limit = &intel_limits_g4x_sdvo; |
| 7770 | } else { |
| 7771 | /* The option is for other outputs */ |
| 7772 | limit = &intel_limits_i9xx_sdvo; |
| 7773 | } |
| 7774 | |
| 7775 | if (!crtc_state->clock_set && |
| 7776 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7777 | refclk, NULL, &crtc_state->dpll)) { |
| 7778 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7779 | return -EINVAL; |
| 7780 | } |
| 7781 | |
| 7782 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7783 | |
| 7784 | return 0; |
| 7785 | } |
| 7786 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7787 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7788 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7789 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7790 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7791 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7792 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7793 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7794 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7795 | memset(&crtc_state->dpll_hw_state, 0, |
| 7796 | sizeof(crtc_state->dpll_hw_state)); |
| 7797 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7798 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7799 | if (intel_panel_use_ssc(dev_priv)) { |
| 7800 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7801 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7802 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7803 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7804 | limit = &intel_limits_pineview_lvds; |
| 7805 | } else { |
| 7806 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7807 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7808 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7809 | if (!crtc_state->clock_set && |
| 7810 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7811 | refclk, NULL, &crtc_state->dpll)) { |
| 7812 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7813 | return -EINVAL; |
| 7814 | } |
| 7815 | |
| 7816 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7817 | |
| 7818 | return 0; |
| 7819 | } |
| 7820 | |
| 7821 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7822 | struct intel_crtc_state *crtc_state) |
| 7823 | { |
| 7824 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7825 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7826 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7827 | int refclk = 96000; |
| 7828 | |
| 7829 | memset(&crtc_state->dpll_hw_state, 0, |
| 7830 | sizeof(crtc_state->dpll_hw_state)); |
| 7831 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7832 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7833 | if (intel_panel_use_ssc(dev_priv)) { |
| 7834 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7835 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7836 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7837 | |
| 7838 | limit = &intel_limits_i9xx_lvds; |
| 7839 | } else { |
| 7840 | limit = &intel_limits_i9xx_sdvo; |
| 7841 | } |
| 7842 | |
| 7843 | if (!crtc_state->clock_set && |
| 7844 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7845 | refclk, NULL, &crtc_state->dpll)) { |
| 7846 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7847 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7848 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7849 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7850 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7851 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7852 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7853 | } |
| 7854 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7855 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7856 | struct intel_crtc_state *crtc_state) |
| 7857 | { |
| 7858 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7859 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7860 | |
| 7861 | memset(&crtc_state->dpll_hw_state, 0, |
| 7862 | sizeof(crtc_state->dpll_hw_state)); |
| 7863 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7864 | if (!crtc_state->clock_set && |
| 7865 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7866 | refclk, NULL, &crtc_state->dpll)) { |
| 7867 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7868 | return -EINVAL; |
| 7869 | } |
| 7870 | |
| 7871 | chv_compute_dpll(crtc, crtc_state); |
| 7872 | |
| 7873 | return 0; |
| 7874 | } |
| 7875 | |
| 7876 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7877 | struct intel_crtc_state *crtc_state) |
| 7878 | { |
| 7879 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7880 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7881 | |
| 7882 | memset(&crtc_state->dpll_hw_state, 0, |
| 7883 | sizeof(crtc_state->dpll_hw_state)); |
| 7884 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7885 | if (!crtc_state->clock_set && |
| 7886 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7887 | refclk, NULL, &crtc_state->dpll)) { |
| 7888 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7889 | return -EINVAL; |
| 7890 | } |
| 7891 | |
| 7892 | vlv_compute_dpll(crtc, crtc_state); |
| 7893 | |
| 7894 | return 0; |
| 7895 | } |
| 7896 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7897 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7898 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7899 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7900 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7901 | u32 tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7902 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7903 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7904 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7905 | return; |
| 7906 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7907 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7908 | if (!(tmp & PFIT_ENABLE)) |
| 7909 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7910 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7911 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7912 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7913 | if (crtc->pipe != PIPE_B) |
| 7914 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7915 | } else { |
| 7916 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7917 | return; |
| 7918 | } |
| 7919 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7920 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7921 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7922 | } |
| 7923 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7924 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7925 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7926 | { |
| 7927 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7928 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7929 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7930 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7931 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7932 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7933 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7934 | /* In case of DSI, DPLL will not be used */ |
| 7935 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7936 | return; |
| 7937 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7938 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7939 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7940 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7941 | |
| 7942 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7943 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7944 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7945 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7946 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7947 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7948 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7949 | } |
| 7950 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7951 | static void |
| 7952 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7953 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7954 | { |
| 7955 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7956 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7957 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7958 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7959 | enum pipe pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7960 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7961 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7962 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7963 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7964 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7965 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7966 | if (!plane->get_hw_state(plane, &pipe)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7967 | return; |
| 7968 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7969 | WARN_ON(pipe != crtc->pipe); |
| 7970 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7971 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7972 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7973 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7974 | return; |
| 7975 | } |
| 7976 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7977 | fb = &intel_fb->base; |
| 7978 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7979 | fb->dev = dev; |
| 7980 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7981 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7982 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7983 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7984 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7985 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7986 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7987 | } |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7988 | |
| 7989 | if (val & DISPPLANE_ROTATE_180) |
| 7990 | plane_config->rotation = DRM_MODE_ROTATE_180; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7991 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7992 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7993 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B && |
| 7994 | val & DISPPLANE_MIRROR) |
| 7995 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 7996 | |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7997 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7998 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 7999 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8000 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 8001 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 8002 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 8003 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 8004 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8005 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8006 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8007 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8008 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 8009 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8010 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8011 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8012 | } |
| 8013 | plane_config->base = base; |
| 8014 | |
| 8015 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8016 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8017 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8018 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8019 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8020 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8021 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8022 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8023 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8024 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8025 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8026 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8027 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 8028 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8029 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8030 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8031 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8032 | } |
| 8033 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8034 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8035 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8036 | { |
| 8037 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8038 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8039 | int pipe = pipe_config->cpu_transcoder; |
| 8040 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8041 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8042 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8043 | int refclk = 100000; |
| 8044 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 8045 | /* In case of DSI, DPLL will not be used */ |
| 8046 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 8047 | return; |
| 8048 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8049 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8050 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 8051 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 8052 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 8053 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8054 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8055 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8056 | |
| 8057 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8058 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 8059 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 8060 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8061 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 8062 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 8063 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 8064 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8065 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8066 | } |
| 8067 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8068 | static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc, |
| 8069 | struct intel_crtc_state *pipe_config) |
| 8070 | { |
| 8071 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8072 | enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB; |
| 8073 | |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 8074 | pipe_config->lspcon_downsampling = false; |
| 8075 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8076 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
| 8077 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 8078 | |
| 8079 | if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) { |
| 8080 | bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE; |
| 8081 | bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 8082 | |
| 8083 | if (ycbcr420_enabled) { |
| 8084 | /* We support 4:2:0 in full blend mode only */ |
| 8085 | if (!blend) |
| 8086 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 8087 | else if (!(IS_GEMINILAKE(dev_priv) || |
| 8088 | INTEL_GEN(dev_priv) >= 10)) |
| 8089 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 8090 | else |
| 8091 | output = INTEL_OUTPUT_FORMAT_YCBCR420; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8092 | } else { |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 8093 | /* |
| 8094 | * Currently there is no interface defined to |
| 8095 | * check user preference between RGB/YCBCR444 |
| 8096 | * or YCBCR420. So the only possible case for |
| 8097 | * YCBCR444 usage is driving YCBCR420 output |
| 8098 | * with LSPCON, when pipe is configured for |
| 8099 | * YCBCR444 output and LSPCON takes care of |
| 8100 | * downsampling it. |
| 8101 | */ |
| 8102 | pipe_config->lspcon_downsampling = true; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8103 | output = INTEL_OUTPUT_FORMAT_YCBCR444; |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8104 | } |
| 8105 | } |
| 8106 | } |
| 8107 | |
| 8108 | pipe_config->output_format = output; |
| 8109 | } |
| 8110 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8111 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8112 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8113 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8114 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8115 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8116 | intel_wakeref_t wakeref; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8117 | u32 tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8118 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8119 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8120 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8121 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 8122 | if (!wakeref) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8123 | return false; |
| 8124 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 8125 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8126 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8127 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8128 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8129 | ret = false; |
| 8130 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8131 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8132 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8133 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8134 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 8135 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 8136 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8137 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8138 | case PIPECONF_6BPC: |
| 8139 | pipe_config->pipe_bpp = 18; |
| 8140 | break; |
| 8141 | case PIPECONF_8BPC: |
| 8142 | pipe_config->pipe_bpp = 24; |
| 8143 | break; |
| 8144 | case PIPECONF_10BPC: |
| 8145 | pipe_config->pipe_bpp = 30; |
| 8146 | break; |
| 8147 | default: |
| 8148 | break; |
| 8149 | } |
| 8150 | } |
| 8151 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8152 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8153 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8154 | pipe_config->limited_color_range = true; |
| 8155 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8156 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8157 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8158 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8159 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8160 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8161 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8162 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8163 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8164 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8165 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8166 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8167 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8168 | else |
| 8169 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8170 | pipe_config->pixel_multiplier = |
| 8171 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8172 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8173 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8174 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 8175 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8176 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8177 | pipe_config->pixel_multiplier = |
| 8178 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8179 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8180 | } else { |
| 8181 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8182 | * port and will be fixed up in the encoder->get_config |
| 8183 | * function. */ |
| 8184 | pipe_config->pixel_multiplier = 1; |
| 8185 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8186 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8187 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8188 | /* |
| 8189 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8190 | * on 830. Filter it out here so that we don't |
| 8191 | * report errors due to that. |
| 8192 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8193 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8194 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8195 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8196 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8197 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8198 | } else { |
| 8199 | /* Mask out read-only status bits. */ |
| 8200 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8201 | DPLL_PORTC_READY_MASK | |
| 8202 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8203 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8204 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8205 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8206 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 8207 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8208 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8209 | else |
| 8210 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8211 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8212 | /* |
| 8213 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8214 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8215 | * default. |
| 8216 | */ |
| 8217 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8218 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8219 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8220 | ret = true; |
| 8221 | |
| 8222 | out: |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8223 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8224 | |
| 8225 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8226 | } |
| 8227 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8228 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8229 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8230 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8231 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8232 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8233 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8234 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8235 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8236 | bool has_ck505 = false; |
| 8237 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8238 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8239 | |
| 8240 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8241 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8242 | switch (encoder->type) { |
| 8243 | case INTEL_OUTPUT_LVDS: |
| 8244 | has_panel = true; |
| 8245 | has_lvds = true; |
| 8246 | break; |
| 8247 | case INTEL_OUTPUT_EDP: |
| 8248 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 8249 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8250 | has_cpu_edp = true; |
| 8251 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8252 | default: |
| 8253 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8254 | } |
| 8255 | } |
| 8256 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8257 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8258 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8259 | can_ssc = has_ck505; |
| 8260 | } else { |
| 8261 | has_ck505 = false; |
| 8262 | can_ssc = true; |
| 8263 | } |
| 8264 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8265 | /* Check if any DPLLs are using the SSC source */ |
| 8266 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8267 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8268 | |
| 8269 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8270 | continue; |
| 8271 | |
| 8272 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8273 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8274 | using_ssc_source = true; |
| 8275 | break; |
| 8276 | } |
| 8277 | } |
| 8278 | |
| 8279 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8280 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8281 | |
| 8282 | /* Ironlake: try to setup display ref clock before DPLL |
| 8283 | * enabling. This is only under driver's control after |
| 8284 | * PCH B stepping, previous chipset stepping should be |
| 8285 | * ignoring this setting. |
| 8286 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8287 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8288 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8289 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8290 | * compute the final state we want first and check if we need to |
| 8291 | * make any changes at all. |
| 8292 | */ |
| 8293 | final = val; |
| 8294 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8295 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8296 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8297 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8298 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8299 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8300 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8301 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8302 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8303 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8304 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8305 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8306 | |
| 8307 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8308 | final |= DREF_SSC1_ENABLE; |
| 8309 | |
| 8310 | if (has_cpu_edp) { |
| 8311 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8312 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8313 | else |
| 8314 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8315 | } else |
| 8316 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8317 | } else if (using_ssc_source) { |
| 8318 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8319 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | if (final == val) |
| 8323 | return; |
| 8324 | |
| 8325 | /* Always enable nonspread source */ |
| 8326 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8327 | |
| 8328 | if (has_ck505) |
| 8329 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8330 | else |
| 8331 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8332 | |
| 8333 | if (has_panel) { |
| 8334 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8335 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8336 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8337 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8338 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8339 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8340 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8341 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8342 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8343 | |
| 8344 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8345 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8346 | POSTING_READ(PCH_DREF_CONTROL); |
| 8347 | udelay(200); |
| 8348 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8349 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8350 | |
| 8351 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8352 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8353 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8354 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8355 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8356 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8357 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8358 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8359 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8360 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8361 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8362 | POSTING_READ(PCH_DREF_CONTROL); |
| 8363 | udelay(200); |
| 8364 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8365 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8366 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8367 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8368 | |
| 8369 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8370 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8371 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8372 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8373 | POSTING_READ(PCH_DREF_CONTROL); |
| 8374 | udelay(200); |
| 8375 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8376 | if (!using_ssc_source) { |
| 8377 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8378 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8379 | /* Turn off the SSC source */ |
| 8380 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8381 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8382 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8383 | /* Turn off SSC1 */ |
| 8384 | val &= ~DREF_SSC1_ENABLE; |
| 8385 | |
| 8386 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8387 | POSTING_READ(PCH_DREF_CONTROL); |
| 8388 | udelay(200); |
| 8389 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8390 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8391 | |
| 8392 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8393 | } |
| 8394 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8395 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8396 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8397 | u32 tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8398 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8399 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8400 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8401 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8402 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8403 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8404 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8405 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8406 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8407 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8408 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8409 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8410 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8411 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8412 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8413 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | /* WaMPhyProgramming:hsw */ |
| 8417 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8418 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8419 | u32 tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8420 | |
| 8421 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8422 | tmp &= ~(0xFF << 24); |
| 8423 | tmp |= (0x12 << 24); |
| 8424 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8425 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8426 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8427 | tmp |= (1 << 11); |
| 8428 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8429 | |
| 8430 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8431 | tmp |= (1 << 11); |
| 8432 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8433 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8434 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8435 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8436 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8437 | |
| 8438 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8439 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8440 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8441 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8442 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8443 | tmp &= ~(7 << 13); |
| 8444 | tmp |= (5 << 13); |
| 8445 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8446 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8447 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8448 | tmp &= ~(7 << 13); |
| 8449 | tmp |= (5 << 13); |
| 8450 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8451 | |
| 8452 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8453 | tmp &= ~0xFF; |
| 8454 | tmp |= 0x1C; |
| 8455 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8456 | |
| 8457 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8458 | tmp &= ~0xFF; |
| 8459 | tmp |= 0x1C; |
| 8460 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8461 | |
| 8462 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8463 | tmp &= ~(0xFF << 16); |
| 8464 | tmp |= (0x1C << 16); |
| 8465 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8466 | |
| 8467 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8468 | tmp &= ~(0xFF << 16); |
| 8469 | tmp |= (0x1C << 16); |
| 8470 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8471 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8472 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8473 | tmp |= (1 << 27); |
| 8474 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8475 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8476 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8477 | tmp |= (1 << 27); |
| 8478 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8479 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8480 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8481 | tmp &= ~(0xF << 28); |
| 8482 | tmp |= (4 << 28); |
| 8483 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8484 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8485 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8486 | tmp &= ~(0xF << 28); |
| 8487 | tmp |= (4 << 28); |
| 8488 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8489 | } |
| 8490 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8491 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8492 | * Programming" based on the parameters passed: |
| 8493 | * - Sequence to enable CLKOUT_DP |
| 8494 | * - Sequence to enable CLKOUT_DP without spread |
| 8495 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8496 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8497 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8498 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8499 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8500 | u32 reg, tmp; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8501 | |
| 8502 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8503 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8504 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8505 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8506 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8507 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8508 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8509 | |
| 8510 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8511 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8512 | tmp |= SBI_SSCCTL_PATHALT; |
| 8513 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8514 | |
| 8515 | udelay(24); |
| 8516 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8517 | if (with_spread) { |
| 8518 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8519 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8520 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8521 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8522 | if (with_fdi) { |
| 8523 | lpt_reset_fdi_mphy(dev_priv); |
| 8524 | lpt_program_fdi_mphy(dev_priv); |
| 8525 | } |
| 8526 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8527 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8528 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8529 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8530 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8531 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8532 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8533 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8534 | } |
| 8535 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8536 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8537 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8538 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8539 | u32 reg, tmp; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8540 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8541 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8542 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8543 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8544 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8545 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8546 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8547 | |
| 8548 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8549 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8550 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8551 | tmp |= SBI_SSCCTL_PATHALT; |
| 8552 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8553 | udelay(32); |
| 8554 | } |
| 8555 | tmp |= SBI_SSCCTL_DISABLE; |
| 8556 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8557 | } |
| 8558 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8559 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8560 | } |
| 8561 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8562 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8563 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8564 | static const u16 sscdivintphase[] = { |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8565 | [BEND_IDX( 50)] = 0x3B23, |
| 8566 | [BEND_IDX( 45)] = 0x3B23, |
| 8567 | [BEND_IDX( 40)] = 0x3C23, |
| 8568 | [BEND_IDX( 35)] = 0x3C23, |
| 8569 | [BEND_IDX( 30)] = 0x3D23, |
| 8570 | [BEND_IDX( 25)] = 0x3D23, |
| 8571 | [BEND_IDX( 20)] = 0x3E23, |
| 8572 | [BEND_IDX( 15)] = 0x3E23, |
| 8573 | [BEND_IDX( 10)] = 0x3F23, |
| 8574 | [BEND_IDX( 5)] = 0x3F23, |
| 8575 | [BEND_IDX( 0)] = 0x0025, |
| 8576 | [BEND_IDX( -5)] = 0x0025, |
| 8577 | [BEND_IDX(-10)] = 0x0125, |
| 8578 | [BEND_IDX(-15)] = 0x0125, |
| 8579 | [BEND_IDX(-20)] = 0x0225, |
| 8580 | [BEND_IDX(-25)] = 0x0225, |
| 8581 | [BEND_IDX(-30)] = 0x0325, |
| 8582 | [BEND_IDX(-35)] = 0x0325, |
| 8583 | [BEND_IDX(-40)] = 0x0425, |
| 8584 | [BEND_IDX(-45)] = 0x0425, |
| 8585 | [BEND_IDX(-50)] = 0x0525, |
| 8586 | }; |
| 8587 | |
| 8588 | /* |
| 8589 | * Bend CLKOUT_DP |
| 8590 | * steps -50 to 50 inclusive, in steps of 5 |
| 8591 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8592 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8593 | */ |
| 8594 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8595 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8596 | u32 tmp; |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8597 | int idx = BEND_IDX(steps); |
| 8598 | |
| 8599 | if (WARN_ON(steps % 5 != 0)) |
| 8600 | return; |
| 8601 | |
| 8602 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8603 | return; |
| 8604 | |
| 8605 | mutex_lock(&dev_priv->sb_lock); |
| 8606 | |
| 8607 | if (steps % 10 != 0) |
| 8608 | tmp = 0xAAAAAAAB; |
| 8609 | else |
| 8610 | tmp = 0x00000000; |
| 8611 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8612 | |
| 8613 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8614 | tmp &= 0xffff0000; |
| 8615 | tmp |= sscdivintphase[idx]; |
| 8616 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8617 | |
| 8618 | mutex_unlock(&dev_priv->sb_lock); |
| 8619 | } |
| 8620 | |
| 8621 | #undef BEND_IDX |
| 8622 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8623 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8624 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8625 | struct intel_encoder *encoder; |
| 8626 | bool has_vga = false; |
| 8627 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8628 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8629 | switch (encoder->type) { |
| 8630 | case INTEL_OUTPUT_ANALOG: |
| 8631 | has_vga = true; |
| 8632 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8633 | default: |
| 8634 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8635 | } |
| 8636 | } |
| 8637 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8638 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8639 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8640 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8641 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8642 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8643 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8644 | } |
| 8645 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8646 | /* |
| 8647 | * Initialize reference clocks when the driver loads |
| 8648 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8649 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8650 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8651 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8652 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8653 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8654 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8655 | } |
| 8656 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8657 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8658 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8659 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8660 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8661 | enum pipe pipe = crtc->pipe; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8662 | u32 val; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8663 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8664 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8665 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8666 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8667 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8668 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8669 | break; |
| 8670 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8671 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8672 | break; |
| 8673 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8674 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8675 | break; |
| 8676 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8677 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8678 | break; |
| 8679 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8680 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8681 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8682 | } |
| 8683 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8684 | if (crtc_state->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8685 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8686 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8687 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8688 | val |= PIPECONF_INTERLACED_ILK; |
| 8689 | else |
| 8690 | val |= PIPECONF_PROGRESSIVE; |
| 8691 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8692 | if (crtc_state->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8693 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8694 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8695 | I915_WRITE(PIPECONF(pipe), val); |
| 8696 | POSTING_READ(PIPECONF(pipe)); |
| 8697 | } |
| 8698 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8699 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8700 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8701 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8702 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8703 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8704 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8705 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8706 | if (IS_HASWELL(dev_priv) && crtc_state->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8707 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8708 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8709 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8710 | val |= PIPECONF_INTERLACED_ILK; |
| 8711 | else |
| 8712 | val |= PIPECONF_PROGRESSIVE; |
| 8713 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8714 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8715 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8716 | } |
| 8717 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8718 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state) |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8719 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8720 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8721 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8722 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8723 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8724 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8725 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8726 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8727 | case 18: |
| 8728 | val |= PIPEMISC_DITHER_6_BPC; |
| 8729 | break; |
| 8730 | case 24: |
| 8731 | val |= PIPEMISC_DITHER_8_BPC; |
| 8732 | break; |
| 8733 | case 30: |
| 8734 | val |= PIPEMISC_DITHER_10_BPC; |
| 8735 | break; |
| 8736 | case 36: |
| 8737 | val |= PIPEMISC_DITHER_12_BPC; |
| 8738 | break; |
| 8739 | default: |
| 8740 | /* Case prevented by pipe_config_set_bpp. */ |
| 8741 | BUG(); |
| 8742 | } |
| 8743 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8744 | if (crtc_state->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8745 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8746 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8747 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 8748 | crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8749 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8750 | |
| 8751 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8752 | val |= PIPEMISC_YUV420_ENABLE | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8753 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8754 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8755 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8756 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8757 | } |
| 8758 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8759 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8760 | { |
| 8761 | /* |
| 8762 | * Account for spread spectrum to avoid |
| 8763 | * oversubscribing the link. Max center spread |
| 8764 | * is 2.5%; use 5% for safety's sake. |
| 8765 | */ |
| 8766 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8767 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8768 | } |
| 8769 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8770 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8771 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8772 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8773 | } |
| 8774 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8775 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8776 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8777 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8778 | { |
| 8779 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8780 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8781 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8782 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8783 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8784 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8785 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8786 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8787 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8788 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8789 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8790 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8791 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8792 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8793 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8794 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8795 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8796 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8797 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8798 | fp |= FP_CB_TUNE; |
| 8799 | |
| 8800 | if (reduced_clock) { |
| 8801 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8802 | |
| 8803 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8804 | fp2 |= FP_CB_TUNE; |
| 8805 | } else { |
| 8806 | fp2 = fp; |
| 8807 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8808 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8809 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8810 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8811 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8812 | dpll |= DPLLB_MODE_LVDS; |
| 8813 | else |
| 8814 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8815 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8816 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8817 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8818 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8819 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8820 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8821 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8822 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8823 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8824 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8825 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8826 | /* |
| 8827 | * The high speed IO clock is only really required for |
| 8828 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8829 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8830 | * the clock needlessly does no real harm, except use up a |
| 8831 | * bit of power potentially. |
| 8832 | * |
| 8833 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8834 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8835 | * driving PCH ports at the same time. On SNB we could do this, |
| 8836 | * and potentially avoid enabling the second DPLL, but it's not |
| 8837 | * clear if it''s a win or loss power wise. No point in doing |
| 8838 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8839 | */ |
| 8840 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8841 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8842 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8843 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8844 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8845 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8846 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8847 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8848 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8849 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8850 | case 5: |
| 8851 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8852 | break; |
| 8853 | case 7: |
| 8854 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8855 | break; |
| 8856 | case 10: |
| 8857 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8858 | break; |
| 8859 | case 14: |
| 8860 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8861 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8862 | } |
| 8863 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8864 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8865 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8866 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8867 | else |
| 8868 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8869 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8870 | dpll |= DPLL_VCO_ENABLE; |
| 8871 | |
| 8872 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8873 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8874 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8875 | } |
| 8876 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8877 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8878 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8879 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8880 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8881 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8882 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8883 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8884 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8885 | memset(&crtc_state->dpll_hw_state, 0, |
| 8886 | sizeof(crtc_state->dpll_hw_state)); |
| 8887 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8888 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8889 | if (!crtc_state->has_pch_encoder) |
| 8890 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8891 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8892 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8893 | if (intel_panel_use_ssc(dev_priv)) { |
| 8894 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8895 | dev_priv->vbt.lvds_ssc_freq); |
| 8896 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8897 | } |
| 8898 | |
| 8899 | if (intel_is_dual_link_lvds(dev)) { |
| 8900 | if (refclk == 100000) |
| 8901 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8902 | else |
| 8903 | limit = &intel_limits_ironlake_dual_lvds; |
| 8904 | } else { |
| 8905 | if (refclk == 100000) |
| 8906 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8907 | else |
| 8908 | limit = &intel_limits_ironlake_single_lvds; |
| 8909 | } |
| 8910 | } else { |
| 8911 | limit = &intel_limits_ironlake_dac; |
| 8912 | } |
| 8913 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8914 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8915 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8916 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8917 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8918 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8919 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8920 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8921 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8922 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8923 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 8924 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 8925 | pipe_name(crtc->pipe)); |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8926 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8927 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8928 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8929 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8930 | } |
| 8931 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8932 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8933 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8934 | { |
| 8935 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8936 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8937 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8938 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8939 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8940 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8941 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8942 | & ~TU_SIZE_MASK; |
| 8943 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8944 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8945 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8946 | } |
| 8947 | |
| 8948 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8949 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8950 | struct intel_link_m_n *m_n, |
| 8951 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8952 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8953 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8954 | enum pipe pipe = crtc->pipe; |
| 8955 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8956 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8957 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8958 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8959 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8960 | & ~TU_SIZE_MASK; |
| 8961 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8962 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8963 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 8964 | |
| 8965 | if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8966 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8967 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8968 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8969 | & ~TU_SIZE_MASK; |
| 8970 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8971 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8972 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8973 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8974 | } else { |
| 8975 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8976 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8977 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8978 | & ~TU_SIZE_MASK; |
| 8979 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8980 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8981 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8982 | } |
| 8983 | } |
| 8984 | |
| 8985 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8986 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8987 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8988 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8989 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8990 | else |
| 8991 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8992 | &pipe_config->dp_m_n, |
| 8993 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8994 | } |
| 8995 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8996 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8997 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8998 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8999 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9000 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9001 | } |
| 9002 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9003 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9004 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9005 | { |
| 9006 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9007 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9008 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9009 | u32 ps_ctrl = 0; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9010 | int id = -1; |
| 9011 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9012 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9013 | /* find scaler attached to this pipe */ |
| 9014 | for (i = 0; i < crtc->num_scalers; i++) { |
| 9015 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 9016 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 9017 | id = i; |
| 9018 | pipe_config->pch_pfit.enabled = true; |
| 9019 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 9020 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
Maarten Lankhorst | 0cdc1d0 | 2019-01-08 17:08:41 +0100 | [diff] [blame] | 9021 | scaler_state->scalers[i].in_use = true; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9022 | break; |
| 9023 | } |
| 9024 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9025 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9026 | scaler_state->scaler_id = id; |
| 9027 | if (id >= 0) { |
| 9028 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 9029 | } else { |
| 9030 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9031 | } |
| 9032 | } |
| 9033 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9034 | static void |
| 9035 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9036 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9037 | { |
| 9038 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9039 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9040 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 9041 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9042 | enum pipe pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9043 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9044 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9045 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9046 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9047 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9048 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9049 | if (!plane->get_hw_state(plane, &pipe)) |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 9050 | return; |
| 9051 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9052 | WARN_ON(pipe != crtc->pipe); |
| 9053 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9054 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9055 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9056 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9057 | return; |
| 9058 | } |
| 9059 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9060 | fb = &intel_fb->base; |
| 9061 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 9062 | fb->dev = dev; |
| 9063 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9064 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9065 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 9066 | if (INTEL_GEN(dev_priv) >= 11) |
| 9067 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 9068 | else |
| 9069 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9070 | |
| 9071 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9072 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9073 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 9074 | } else { |
| 9075 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 9076 | } |
| 9077 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9078 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9079 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 9080 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9081 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9082 | tiling = val & PLANE_CTL_TILED_MASK; |
| 9083 | switch (tiling) { |
| 9084 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 9085 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9086 | break; |
| 9087 | case PLANE_CTL_TILED_X: |
| 9088 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9089 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9090 | break; |
| 9091 | case PLANE_CTL_TILED_Y: |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 9092 | plane_config->tiling = I915_TILING_Y; |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 9093 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 9094 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 9095 | else |
| 9096 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9097 | break; |
| 9098 | case PLANE_CTL_TILED_YF: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 9099 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 9100 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 9101 | else |
| 9102 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9103 | break; |
| 9104 | default: |
| 9105 | MISSING_CASE(tiling); |
| 9106 | goto error; |
| 9107 | } |
| 9108 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 9109 | /* |
| 9110 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 9111 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 9112 | */ |
| 9113 | switch (val & PLANE_CTL_ROTATE_MASK) { |
| 9114 | case PLANE_CTL_ROTATE_0: |
| 9115 | plane_config->rotation = DRM_MODE_ROTATE_0; |
| 9116 | break; |
| 9117 | case PLANE_CTL_ROTATE_90: |
| 9118 | plane_config->rotation = DRM_MODE_ROTATE_270; |
| 9119 | break; |
| 9120 | case PLANE_CTL_ROTATE_180: |
| 9121 | plane_config->rotation = DRM_MODE_ROTATE_180; |
| 9122 | break; |
| 9123 | case PLANE_CTL_ROTATE_270: |
| 9124 | plane_config->rotation = DRM_MODE_ROTATE_90; |
| 9125 | break; |
| 9126 | } |
| 9127 | |
| 9128 | if (INTEL_GEN(dev_priv) >= 10 && |
| 9129 | val & PLANE_CTL_FLIP_HORIZONTAL) |
| 9130 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 9131 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9132 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9133 | plane_config->base = base; |
| 9134 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9135 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9136 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9137 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9138 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 9139 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 9140 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9141 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 9142 | stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9143 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9144 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 9145 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9146 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9147 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9148 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9149 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9150 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 9151 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9152 | plane_config->size); |
| 9153 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9154 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9155 | return; |
| 9156 | |
| 9157 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 9158 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9159 | } |
| 9160 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9161 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9162 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9163 | { |
| 9164 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9165 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9166 | u32 tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9167 | |
| 9168 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9169 | |
| 9170 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9171 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9172 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9173 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9174 | |
| 9175 | /* We currently do not free assignements of panel fitters on |
| 9176 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9177 | * differentiates them) so just WARN about this case for now. */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9178 | if (IS_GEN(dev_priv, 7)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9179 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9180 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9181 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9182 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9183 | } |
| 9184 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9185 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9186 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9187 | { |
| 9188 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9189 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9190 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9191 | intel_wakeref_t wakeref; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9192 | u32 tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9193 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9194 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9195 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9196 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 9197 | if (!wakeref) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9198 | return false; |
| 9199 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 9200 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9201 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9202 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9203 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9204 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9205 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9206 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9207 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9208 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9209 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9210 | case PIPECONF_6BPC: |
| 9211 | pipe_config->pipe_bpp = 18; |
| 9212 | break; |
| 9213 | case PIPECONF_8BPC: |
| 9214 | pipe_config->pipe_bpp = 24; |
| 9215 | break; |
| 9216 | case PIPECONF_10BPC: |
| 9217 | pipe_config->pipe_bpp = 30; |
| 9218 | break; |
| 9219 | case PIPECONF_12BPC: |
| 9220 | pipe_config->pipe_bpp = 36; |
| 9221 | break; |
| 9222 | default: |
| 9223 | break; |
| 9224 | } |
| 9225 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9226 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9227 | pipe_config->limited_color_range = true; |
| 9228 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9229 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9230 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9231 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9232 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9233 | pipe_config->has_pch_encoder = true; |
| 9234 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9235 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9236 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9237 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9238 | |
| 9239 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9240 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9241 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9242 | /* |
| 9243 | * The pipe->pch transcoder and pch transcoder->pll |
| 9244 | * mapping is fixed. |
| 9245 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9246 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9247 | } else { |
| 9248 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9249 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9250 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9251 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9252 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9253 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9254 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9255 | pipe_config->shared_dpll = |
| 9256 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9257 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9258 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9259 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9260 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9261 | |
| 9262 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9263 | pipe_config->pixel_multiplier = |
| 9264 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9265 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9266 | |
| 9267 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9268 | } else { |
| 9269 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9270 | } |
| 9271 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9272 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9273 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9274 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9275 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9276 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9277 | ret = true; |
| 9278 | |
| 9279 | out: |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9280 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9281 | |
| 9282 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9283 | } |
| 9284 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9285 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9286 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 9287 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9288 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9289 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9290 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9291 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9292 | pipe_name(crtc->pipe)); |
| 9293 | |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 9294 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2), |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 9295 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9296 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
Ville Syrjälä | 01403de | 2015-09-18 20:03:33 +0300 | [diff] [blame] | 9297 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9298 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 9299 | I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9300 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9301 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9302 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9303 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9304 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9305 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9306 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9307 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9308 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9309 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9310 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9311 | /* |
| 9312 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9313 | * interrupts remain enabled. We used to check for that, but since it's |
| 9314 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9315 | * the interrupts, the check below should be enough. |
| 9316 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9317 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9318 | } |
| 9319 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9320 | static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9321 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9322 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9323 | return I915_READ(D_COMP_HSW); |
| 9324 | else |
| 9325 | return I915_READ(D_COMP_BDW); |
| 9326 | } |
| 9327 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9328 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val) |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9329 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9330 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9331 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9332 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9333 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 9334 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9335 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9336 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9337 | I915_WRITE(D_COMP_BDW, val); |
| 9338 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9339 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9340 | } |
| 9341 | |
| 9342 | /* |
| 9343 | * This function implements pieces of two sequences from BSpec: |
| 9344 | * - Sequence for display software to disable LCPLL |
| 9345 | * - Sequence for display software to allow package C8+ |
| 9346 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9347 | * register. Callers should take care of disabling all the display engine |
| 9348 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9349 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9350 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9351 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9352 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9353 | u32 val; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9354 | |
| 9355 | assert_can_disable_lcpll(dev_priv); |
| 9356 | |
| 9357 | val = I915_READ(LCPLL_CTL); |
| 9358 | |
| 9359 | if (switch_to_fclk) { |
| 9360 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9361 | I915_WRITE(LCPLL_CTL, val); |
| 9362 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9363 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9364 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9365 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9366 | |
| 9367 | val = I915_READ(LCPLL_CTL); |
| 9368 | } |
| 9369 | |
| 9370 | val |= LCPLL_PLL_DISABLE; |
| 9371 | I915_WRITE(LCPLL_CTL, val); |
| 9372 | POSTING_READ(LCPLL_CTL); |
| 9373 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 9374 | if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9375 | DRM_ERROR("LCPLL still locked\n"); |
| 9376 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9377 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9378 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9379 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9380 | ndelay(100); |
| 9381 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9382 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9383 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9384 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9385 | |
| 9386 | if (allow_power_down) { |
| 9387 | val = I915_READ(LCPLL_CTL); |
| 9388 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9389 | I915_WRITE(LCPLL_CTL, val); |
| 9390 | POSTING_READ(LCPLL_CTL); |
| 9391 | } |
| 9392 | } |
| 9393 | |
| 9394 | /* |
| 9395 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9396 | * source. |
| 9397 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9398 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9399 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9400 | u32 val; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9401 | |
| 9402 | val = I915_READ(LCPLL_CTL); |
| 9403 | |
| 9404 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9405 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9406 | return; |
| 9407 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9408 | /* |
| 9409 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9410 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9411 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9412 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9413 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9414 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9415 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9416 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9417 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9418 | } |
| 9419 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9420 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9421 | val |= D_COMP_COMP_FORCE; |
| 9422 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9423 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9424 | |
| 9425 | val = I915_READ(LCPLL_CTL); |
| 9426 | val &= ~LCPLL_PLL_DISABLE; |
| 9427 | I915_WRITE(LCPLL_CTL, val); |
| 9428 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9429 | if (intel_wait_for_register(dev_priv, |
| 9430 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9431 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9432 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9433 | |
| 9434 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9435 | val = I915_READ(LCPLL_CTL); |
| 9436 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9437 | I915_WRITE(LCPLL_CTL, val); |
| 9438 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9439 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9440 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9441 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9442 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9443 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9444 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9445 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9446 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9447 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9448 | } |
| 9449 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9450 | /* |
| 9451 | * Package states C8 and deeper are really deep PC states that can only be |
| 9452 | * reached when all the devices on the system allow it, so even if the graphics |
| 9453 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9454 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9455 | * |
| 9456 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9457 | * well is disabled and most interrupts are disabled, and these are also |
| 9458 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9459 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9460 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9461 | * hang the machine. |
| 9462 | * |
| 9463 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9464 | * the state of some registers, so when we come back from PC8+ we need to |
| 9465 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9466 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9467 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9468 | * because of the runtime PM support). |
| 9469 | * |
| 9470 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9471 | * documentation. |
| 9472 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9473 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9474 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9475 | u32 val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9476 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9477 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9478 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9479 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9480 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9481 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9482 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9483 | } |
| 9484 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9485 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9486 | hsw_disable_lcpll(dev_priv, true, true); |
| 9487 | } |
| 9488 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9489 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9490 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9491 | u32 val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9492 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9493 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9494 | |
| 9495 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9496 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9497 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9498 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9499 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9500 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9501 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9502 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9503 | } |
| 9504 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9505 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9506 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9507 | { |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9508 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9509 | struct intel_atomic_state *state = |
| 9510 | to_intel_atomic_state(crtc_state->base.state); |
| 9511 | |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9512 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) || |
| 9513 | IS_ICELAKE(dev_priv)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9514 | struct intel_encoder *encoder = |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9515 | intel_get_crtc_new_encoder(state, crtc_state); |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9516 | |
| 9517 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 9518 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 9519 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9520 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9521 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9522 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9523 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9524 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9525 | } |
| 9526 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9527 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9528 | enum port port, |
| 9529 | struct intel_crtc_state *pipe_config) |
| 9530 | { |
| 9531 | enum intel_dpll_id id; |
| 9532 | u32 temp; |
| 9533 | |
| 9534 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9535 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9536 | |
| 9537 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9538 | return; |
| 9539 | |
| 9540 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9541 | } |
| 9542 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9543 | static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9544 | enum port port, |
| 9545 | struct intel_crtc_state *pipe_config) |
| 9546 | { |
| 9547 | enum intel_dpll_id id; |
| 9548 | u32 temp; |
| 9549 | |
| 9550 | /* TODO: TBT pll not implemented. */ |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9551 | if (intel_port_is_combophy(dev_priv, port)) { |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9552 | temp = I915_READ(DPCLKA_CFGCR0_ICL) & |
| 9553 | DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
| 9554 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
| 9555 | |
Vandita Kulkarni | a54270d | 2018-10-03 12:52:00 +0530 | [diff] [blame] | 9556 | if (WARN_ON(!intel_dpll_is_combophy(id))) |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9557 | return; |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9558 | } else if (intel_port_is_tc(dev_priv, port)) { |
Lucas De Marchi | 584fca1 | 2019-01-25 14:24:41 -0800 | [diff] [blame] | 9559 | id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv, port)); |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9560 | } else { |
| 9561 | WARN(1, "Invalid port %x\n", port); |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9562 | return; |
| 9563 | } |
| 9564 | |
| 9565 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9566 | } |
| 9567 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9568 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9569 | enum port port, |
| 9570 | struct intel_crtc_state *pipe_config) |
| 9571 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9572 | enum intel_dpll_id id; |
| 9573 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9574 | switch (port) { |
| 9575 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9576 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9577 | break; |
| 9578 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9579 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9580 | break; |
| 9581 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9582 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9583 | break; |
| 9584 | default: |
| 9585 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9586 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9587 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9588 | |
| 9589 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9590 | } |
| 9591 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9592 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9593 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9594 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9595 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9596 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9597 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9598 | |
| 9599 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9600 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9601 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9602 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9603 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9604 | |
| 9605 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9606 | } |
| 9607 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9608 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9609 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9610 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9611 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9612 | enum intel_dpll_id id; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9613 | u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9614 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9615 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9616 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9617 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9618 | break; |
| 9619 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9620 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9621 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9622 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9623 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9624 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9625 | case PORT_CLK_SEL_LCPLL_810: |
| 9626 | id = DPLL_ID_LCPLL_810; |
| 9627 | break; |
| 9628 | case PORT_CLK_SEL_LCPLL_1350: |
| 9629 | id = DPLL_ID_LCPLL_1350; |
| 9630 | break; |
| 9631 | case PORT_CLK_SEL_LCPLL_2700: |
| 9632 | id = DPLL_ID_LCPLL_2700; |
| 9633 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9634 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9635 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9636 | /* fall through */ |
| 9637 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9638 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9639 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9640 | |
| 9641 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9642 | } |
| 9643 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9644 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9645 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9646 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9647 | { |
| 9648 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9649 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9650 | enum intel_display_power_domain power_domain; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9651 | unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP); |
| 9652 | unsigned long enabled_panel_transcoders = 0; |
| 9653 | enum transcoder panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9654 | u32 tmp; |
| 9655 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9656 | if (IS_ICELAKE(dev_priv)) |
| 9657 | panel_transcoder_mask |= |
| 9658 | BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9659 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9660 | /* |
| 9661 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9662 | * and DSI transcoders handled below. |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9663 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9664 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9665 | |
| 9666 | /* |
| 9667 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9668 | * consistency and less surprising code; it's in always on power). |
| 9669 | */ |
Chris Wilson | 1b4bd5c | 2019-01-16 15:54:21 +0000 | [diff] [blame] | 9670 | for_each_set_bit(panel_transcoder, |
| 9671 | &panel_transcoder_mask, |
| 9672 | ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) { |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9673 | enum pipe trans_pipe; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9674 | |
| 9675 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder)); |
| 9676 | if (!(tmp & TRANS_DDI_FUNC_ENABLE)) |
| 9677 | continue; |
| 9678 | |
| 9679 | /* |
| 9680 | * Log all enabled ones, only use the first one. |
| 9681 | * |
| 9682 | * FIXME: This won't work for two separate DSI displays. |
| 9683 | */ |
| 9684 | enabled_panel_transcoders |= BIT(panel_transcoder); |
| 9685 | if (enabled_panel_transcoders != BIT(panel_transcoder)) |
| 9686 | continue; |
| 9687 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9688 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9689 | default: |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9690 | WARN(1, "unknown pipe linked to transcoder %s\n", |
| 9691 | transcoder_name(panel_transcoder)); |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 9692 | /* fall through */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9693 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9694 | case TRANS_DDI_EDP_INPUT_A_ON: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9695 | trans_pipe = PIPE_A; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9696 | break; |
| 9697 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9698 | trans_pipe = PIPE_B; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9699 | break; |
| 9700 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9701 | trans_pipe = PIPE_C; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9702 | break; |
| 9703 | } |
| 9704 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9705 | if (trans_pipe == crtc->pipe) |
| 9706 | pipe_config->cpu_transcoder = panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9707 | } |
| 9708 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9709 | /* |
| 9710 | * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1 |
| 9711 | */ |
| 9712 | WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) && |
| 9713 | enabled_panel_transcoders != BIT(TRANSCODER_EDP)); |
| 9714 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9715 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9716 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9717 | return false; |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9718 | |
| 9719 | WARN_ON(*power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9720 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9721 | |
| 9722 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9723 | |
| 9724 | return tmp & PIPECONF_ENABLE; |
| 9725 | } |
| 9726 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9727 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9728 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9729 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9730 | { |
| 9731 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9732 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9733 | enum intel_display_power_domain power_domain; |
| 9734 | enum port port; |
| 9735 | enum transcoder cpu_transcoder; |
| 9736 | u32 tmp; |
| 9737 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9738 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9739 | if (port == PORT_A) |
| 9740 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9741 | else |
| 9742 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9743 | |
| 9744 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9745 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9746 | continue; |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9747 | |
| 9748 | WARN_ON(*power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9749 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9750 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9751 | /* |
| 9752 | * The PLL needs to be enabled with a valid divider |
| 9753 | * configuration, otherwise accessing DSI registers will hang |
| 9754 | * the machine. See BSpec North Display Engine |
| 9755 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9756 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9757 | */ |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 9758 | if (!bxt_dsi_pll_is_enabled(dev_priv)) |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9759 | break; |
| 9760 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9761 | /* XXX: this works for video mode only */ |
| 9762 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9763 | if (!(tmp & DPI_ENABLE)) |
| 9764 | continue; |
| 9765 | |
| 9766 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9767 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9768 | continue; |
| 9769 | |
| 9770 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9771 | break; |
| 9772 | } |
| 9773 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9774 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9775 | } |
| 9776 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9777 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9778 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9779 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9780 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9781 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9782 | enum port port; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9783 | u32 tmp; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9784 | |
| 9785 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9786 | |
| 9787 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9788 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9789 | if (IS_ICELAKE(dev_priv)) |
| 9790 | icelake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9791 | else if (IS_CANNONLAKE(dev_priv)) |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9792 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9793 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9794 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9795 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9796 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9797 | else |
| 9798 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9799 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9800 | pll = pipe_config->shared_dpll; |
| 9801 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9802 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9803 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9804 | } |
| 9805 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9806 | /* |
| 9807 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9808 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9809 | * the PCH transcoder is on. |
| 9810 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9811 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9812 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9813 | pipe_config->has_pch_encoder = true; |
| 9814 | |
| 9815 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9816 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9817 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9818 | |
| 9819 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9820 | } |
| 9821 | } |
| 9822 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9823 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9824 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9825 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9826 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9827 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9828 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9829 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9830 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9831 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9832 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9833 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9834 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9835 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9836 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9837 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9838 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9839 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9840 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9841 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9842 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9843 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9844 | WARN_ON(active); |
| 9845 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9846 | } |
| 9847 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9848 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9849 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9850 | |
Madhav Chauhan | 2eae5d6 | 2018-11-29 16:12:28 +0200 | [diff] [blame] | 9851 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || |
| 9852 | IS_ICELAKE(dev_priv)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9853 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9854 | intel_get_pipe_timings(crtc, pipe_config); |
| 9855 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9856 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9857 | intel_get_pipe_src_size(crtc, pipe_config); |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 9858 | intel_get_crtc_ycbcr_config(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9859 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9860 | pipe_config->gamma_mode = |
| 9861 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9862 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9863 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9864 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9865 | WARN_ON(power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9866 | power_domain_mask |= BIT_ULL(power_domain); |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9867 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9868 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9869 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9870 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9871 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9872 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9873 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9874 | if (hsw_crtc_supports_ips(crtc)) { |
| 9875 | if (IS_HASWELL(dev_priv)) |
| 9876 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9877 | else { |
| 9878 | /* |
| 9879 | * We cannot readout IPS state on broadwell, set to |
| 9880 | * true so we can set it to a defined state on first |
| 9881 | * commit. |
| 9882 | */ |
| 9883 | pipe_config->ips_enabled = true; |
| 9884 | } |
| 9885 | } |
| 9886 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9887 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9888 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9889 | pipe_config->pixel_multiplier = |
| 9890 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9891 | } else { |
| 9892 | pipe_config->pixel_multiplier = 1; |
| 9893 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9894 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9895 | out: |
| 9896 | for_each_power_domain(power_domain, power_domain_mask) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9897 | intel_display_power_put_unchecked(dev_priv, power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9898 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9899 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9900 | } |
| 9901 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9902 | static u32 intel_cursor_base(const struct intel_plane_state *plane_state) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9903 | { |
| 9904 | struct drm_i915_private *dev_priv = |
| 9905 | to_i915(plane_state->base.plane->dev); |
| 9906 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9907 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9908 | u32 base; |
| 9909 | |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 9910 | if (INTEL_INFO(dev_priv)->display.cursor_needs_physical) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9911 | base = obj->phys_handle->busaddr; |
| 9912 | else |
| 9913 | base = intel_plane_ggtt_offset(plane_state); |
| 9914 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 9915 | base += plane_state->color_plane[0].offset; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9916 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9917 | /* ILK+ do this automagically */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 9918 | if (HAS_GMCH(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9919 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9920 | base += (plane_state->base.crtc_h * |
| 9921 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9922 | |
| 9923 | return base; |
| 9924 | } |
| 9925 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9926 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9927 | { |
| 9928 | int x = plane_state->base.crtc_x; |
| 9929 | int y = plane_state->base.crtc_y; |
| 9930 | u32 pos = 0; |
| 9931 | |
| 9932 | if (x < 0) { |
| 9933 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9934 | x = -x; |
| 9935 | } |
| 9936 | pos |= x << CURSOR_X_SHIFT; |
| 9937 | |
| 9938 | if (y < 0) { |
| 9939 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9940 | y = -y; |
| 9941 | } |
| 9942 | pos |= y << CURSOR_Y_SHIFT; |
| 9943 | |
| 9944 | return pos; |
| 9945 | } |
| 9946 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9947 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9948 | { |
| 9949 | const struct drm_mode_config *config = |
| 9950 | &plane_state->base.plane->dev->mode_config; |
| 9951 | int width = plane_state->base.crtc_w; |
| 9952 | int height = plane_state->base.crtc_h; |
| 9953 | |
| 9954 | return width > 0 && width <= config->cursor_width && |
| 9955 | height > 0 && height <= config->cursor_height; |
| 9956 | } |
| 9957 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9958 | static int intel_cursor_check_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9959 | { |
| 9960 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9961 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9962 | int src_x, src_y; |
| 9963 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9964 | int ret; |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9965 | |
| 9966 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
| 9967 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 9968 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9969 | ret = intel_plane_check_stride(plane_state); |
| 9970 | if (ret) |
| 9971 | return ret; |
| 9972 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9973 | src_x = plane_state->base.src_x >> 16; |
| 9974 | src_y = plane_state->base.src_y >> 16; |
| 9975 | |
| 9976 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 9977 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 9978 | plane_state, 0); |
| 9979 | |
| 9980 | if (src_x != 0 || src_y != 0) { |
| 9981 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 9982 | return -EINVAL; |
| 9983 | } |
| 9984 | |
| 9985 | plane_state->color_plane[0].offset = offset; |
| 9986 | |
| 9987 | return 0; |
| 9988 | } |
| 9989 | |
| 9990 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 9991 | struct intel_plane_state *plane_state) |
| 9992 | { |
| 9993 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9994 | int ret; |
| 9995 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9996 | if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 9997 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 9998 | return -EINVAL; |
| 9999 | } |
| 10000 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 10001 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 10002 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 10003 | DRM_PLANE_HELPER_NO_SCALING, |
| 10004 | DRM_PLANE_HELPER_NO_SCALING, |
| 10005 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10006 | if (ret) |
| 10007 | return ret; |
| 10008 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 10009 | if (!plane_state->base.visible) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10010 | return 0; |
| 10011 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 10012 | ret = intel_plane_check_src_coordinates(plane_state); |
| 10013 | if (ret) |
| 10014 | return ret; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10015 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 10016 | ret = intel_cursor_check_surface(plane_state); |
| 10017 | if (ret) |
| 10018 | return ret; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 10019 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10020 | return 0; |
| 10021 | } |
| 10022 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 10023 | static unsigned int |
| 10024 | i845_cursor_max_stride(struct intel_plane *plane, |
| 10025 | u32 pixel_format, u64 modifier, |
| 10026 | unsigned int rotation) |
| 10027 | { |
| 10028 | return 2048; |
| 10029 | } |
| 10030 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10031 | static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 10032 | { |
| 10033 | return CURSOR_GAMMA_ENABLE; |
| 10034 | } |
| 10035 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10036 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 10037 | const struct intel_plane_state *plane_state) |
| 10038 | { |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10039 | return CURSOR_ENABLE | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10040 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10041 | CURSOR_STRIDE(plane_state->color_plane[0].stride); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10042 | } |
| 10043 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10044 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 10045 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10046 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10047 | |
| 10048 | /* |
| 10049 | * 845g/865g are only limited by the width of their cursors, |
| 10050 | * the height is arbitrary up to the precision of the register. |
| 10051 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 10052 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10053 | } |
| 10054 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10055 | static int i845_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10056 | struct intel_plane_state *plane_state) |
| 10057 | { |
| 10058 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10059 | int ret; |
| 10060 | |
| 10061 | ret = intel_check_cursor(crtc_state, plane_state); |
| 10062 | if (ret) |
| 10063 | return ret; |
| 10064 | |
| 10065 | /* if we want to turn off the cursor ignore width and height */ |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10066 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10067 | return 0; |
| 10068 | |
| 10069 | /* Check for which cursor types we support */ |
| 10070 | if (!i845_cursor_size_ok(plane_state)) { |
| 10071 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 10072 | plane_state->base.crtc_w, |
| 10073 | plane_state->base.crtc_h); |
| 10074 | return -EINVAL; |
| 10075 | } |
| 10076 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10077 | WARN_ON(plane_state->base.visible && |
| 10078 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 10079 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10080 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10081 | case 256: |
| 10082 | case 512: |
| 10083 | case 1024: |
| 10084 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10085 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10086 | default: |
| 10087 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 10088 | fb->pitches[0]); |
| 10089 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10090 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10091 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10092 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 10093 | |
| 10094 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10095 | } |
| 10096 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10097 | static void i845_update_cursor(struct intel_plane *plane, |
| 10098 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10099 | const struct intel_plane_state *plane_state) |
| 10100 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10101 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10102 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 10103 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10104 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10105 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10106 | unsigned int width = plane_state->base.crtc_w; |
| 10107 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10108 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10109 | cntl = plane_state->ctl | |
| 10110 | i845_cursor_ctl_crtc(crtc_state); |
| 10111 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10112 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10113 | |
| 10114 | base = intel_cursor_base(plane_state); |
| 10115 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10116 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10117 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10118 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10119 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10120 | /* On these chipsets we can only modify the base/size/stride |
| 10121 | * whilst the cursor is disabled. |
| 10122 | */ |
| 10123 | if (plane->cursor.base != base || |
| 10124 | plane->cursor.size != size || |
| 10125 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10126 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10127 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10128 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10129 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10130 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10131 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10132 | plane->cursor.base = base; |
| 10133 | plane->cursor.size = size; |
| 10134 | plane->cursor.cntl = cntl; |
| 10135 | } else { |
| 10136 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10137 | } |
| 10138 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10139 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 10140 | } |
| 10141 | |
| 10142 | static void i845_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10143 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10144 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10145 | i845_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10146 | } |
| 10147 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10148 | static bool i845_cursor_get_hw_state(struct intel_plane *plane, |
| 10149 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10150 | { |
| 10151 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10152 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10153 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10154 | bool ret; |
| 10155 | |
| 10156 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10157 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 10158 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10159 | return false; |
| 10160 | |
| 10161 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 10162 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10163 | *pipe = PIPE_A; |
| 10164 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10165 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10166 | |
| 10167 | return ret; |
| 10168 | } |
| 10169 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 10170 | static unsigned int |
| 10171 | i9xx_cursor_max_stride(struct intel_plane *plane, |
| 10172 | u32 pixel_format, u64 modifier, |
| 10173 | unsigned int rotation) |
| 10174 | { |
| 10175 | return plane->base.dev->mode_config.cursor_width * 4; |
| 10176 | } |
| 10177 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10178 | static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 10179 | { |
| 10180 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 10181 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 10182 | u32 cntl = 0; |
| 10183 | |
| 10184 | if (INTEL_GEN(dev_priv) >= 11) |
| 10185 | return cntl; |
| 10186 | |
| 10187 | cntl |= MCURSOR_GAMMA_ENABLE; |
| 10188 | |
| 10189 | if (HAS_DDI(dev_priv)) |
| 10190 | cntl |= MCURSOR_PIPE_CSC_ENABLE; |
| 10191 | |
| 10192 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 10193 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
| 10194 | |
| 10195 | return cntl; |
| 10196 | } |
| 10197 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10198 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 10199 | const struct intel_plane_state *plane_state) |
| 10200 | { |
| 10201 | struct drm_i915_private *dev_priv = |
| 10202 | to_i915(plane_state->base.plane->dev); |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10203 | u32 cntl = 0; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10204 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10205 | if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | e876b78 | 2018-01-30 22:38:05 +0200 | [diff] [blame] | 10206 | cntl |= MCURSOR_TRICKLE_FEED_DISABLE; |
| 10207 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10208 | switch (plane_state->base.crtc_w) { |
| 10209 | case 64: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10210 | cntl |= MCURSOR_MODE_64_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10211 | break; |
| 10212 | case 128: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10213 | cntl |= MCURSOR_MODE_128_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10214 | break; |
| 10215 | case 256: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10216 | cntl |= MCURSOR_MODE_256_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10217 | break; |
| 10218 | default: |
| 10219 | MISSING_CASE(plane_state->base.crtc_w); |
| 10220 | return 0; |
| 10221 | } |
| 10222 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 10223 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10224 | cntl |= MCURSOR_ROTATE_180; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10225 | |
| 10226 | return cntl; |
| 10227 | } |
| 10228 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10229 | static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10230 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10231 | struct drm_i915_private *dev_priv = |
| 10232 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10233 | int width = plane_state->base.crtc_w; |
| 10234 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10235 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 10236 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10237 | return false; |
| 10238 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10239 | /* Cursor width is limited to a few power-of-two sizes */ |
| 10240 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10241 | case 256: |
| 10242 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10243 | case 64: |
| 10244 | break; |
| 10245 | default: |
| 10246 | return false; |
| 10247 | } |
| 10248 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10249 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10250 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 10251 | * height from 8 lines up to the cursor width, when the |
| 10252 | * cursor is not rotated. Everything else requires square |
| 10253 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10254 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10255 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 10256 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10257 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10258 | return false; |
| 10259 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10260 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10261 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10262 | } |
| 10263 | |
| 10264 | return true; |
| 10265 | } |
| 10266 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10267 | static int i9xx_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10268 | struct intel_plane_state *plane_state) |
| 10269 | { |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10270 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10271 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10272 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10273 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10274 | int ret; |
| 10275 | |
| 10276 | ret = intel_check_cursor(crtc_state, plane_state); |
| 10277 | if (ret) |
| 10278 | return ret; |
| 10279 | |
| 10280 | /* if we want to turn off the cursor ignore width and height */ |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10281 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10282 | return 0; |
| 10283 | |
| 10284 | /* Check for which cursor types we support */ |
| 10285 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 10286 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 10287 | plane_state->base.crtc_w, |
| 10288 | plane_state->base.crtc_h); |
| 10289 | return -EINVAL; |
| 10290 | } |
| 10291 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10292 | WARN_ON(plane_state->base.visible && |
| 10293 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 10294 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10295 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 10296 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 10297 | fb->pitches[0], plane_state->base.crtc_w); |
| 10298 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10299 | } |
| 10300 | |
| 10301 | /* |
| 10302 | * There's something wrong with the cursor on CHV pipe C. |
| 10303 | * If it straddles the left edge of the screen then |
| 10304 | * moving it away from the edge or disabling it often |
| 10305 | * results in a pipe underrun, and often that can lead to |
| 10306 | * dead pipe (constant underrun reported, and it scans |
| 10307 | * out just a solid color). To recover from that, the |
| 10308 | * display power well must be turned off and on again. |
| 10309 | * Refuse the put the cursor into that compromised position. |
| 10310 | */ |
| 10311 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 10312 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 10313 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 10314 | return -EINVAL; |
| 10315 | } |
| 10316 | |
| 10317 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 10318 | |
| 10319 | return 0; |
| 10320 | } |
| 10321 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10322 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 10323 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10324 | const struct intel_plane_state *plane_state) |
| 10325 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10326 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10327 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10328 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10329 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10330 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10331 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10332 | cntl = plane_state->ctl | |
| 10333 | i9xx_cursor_ctl_crtc(crtc_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10334 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10335 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 10336 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 10337 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10338 | base = intel_cursor_base(plane_state); |
| 10339 | pos = intel_cursor_position(plane_state); |
| 10340 | } |
| 10341 | |
| 10342 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10343 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10344 | /* |
| 10345 | * On some platforms writing CURCNTR first will also |
| 10346 | * cause CURPOS to be armed by the CURBASE write. |
| 10347 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10348 | * arm itself. Thus we always update CURCNTR before |
| 10349 | * CURPOS. |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10350 | * |
| 10351 | * On other platforms CURPOS always requires the |
| 10352 | * CURBASE write to arm the update. Additonally |
| 10353 | * a write to any of the cursor register will cancel |
| 10354 | * an already armed cursor update. Thus leaving out |
| 10355 | * the CURBASE write after CURPOS could lead to a |
| 10356 | * cursor that doesn't appear to move, or even change |
| 10357 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10358 | * |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10359 | * The other registers are armed by by the CURBASE write |
| 10360 | * except when the plane is getting enabled at which time |
| 10361 | * the CURCNTR write arms the update. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10362 | */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 10363 | |
| 10364 | if (INTEL_GEN(dev_priv) >= 9) |
| 10365 | skl_write_cursor_wm(plane, crtc_state); |
| 10366 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10367 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10368 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10369 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10370 | if (HAS_CUR_FBC(dev_priv)) |
| 10371 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10372 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10373 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10374 | I915_WRITE_FW(CURBASE(pipe), base); |
| 10375 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10376 | plane->cursor.base = base; |
| 10377 | plane->cursor.size = fbc_ctl; |
| 10378 | plane->cursor.cntl = cntl; |
| 10379 | } else { |
| 10380 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10381 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10382 | } |
| 10383 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10384 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10385 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10386 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10387 | static void i9xx_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10388 | const struct intel_crtc_state *crtc_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10389 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10390 | i9xx_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10391 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 10392 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10393 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane, |
| 10394 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10395 | { |
| 10396 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10397 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10398 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10399 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10400 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10401 | |
| 10402 | /* |
| 10403 | * Not 100% correct for planes that can move between pipes, |
| 10404 | * but that's only the case for gen2-3 which don't have any |
| 10405 | * display power wells. |
| 10406 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10407 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10408 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 10409 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10410 | return false; |
| 10411 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10412 | val = I915_READ(CURCNTR(plane->pipe)); |
| 10413 | |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10414 | ret = val & MCURSOR_MODE; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10415 | |
| 10416 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 10417 | *pipe = plane->pipe; |
| 10418 | else |
| 10419 | *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >> |
| 10420 | MCURSOR_PIPE_SELECT_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10421 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10422 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10423 | |
| 10424 | return ret; |
| 10425 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10426 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10427 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10428 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10429 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10430 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10431 | }; |
| 10432 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10433 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10434 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 10435 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10436 | { |
| 10437 | struct intel_framebuffer *intel_fb; |
| 10438 | int ret; |
| 10439 | |
| 10440 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10441 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10442 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10443 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10444 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10445 | if (ret) |
| 10446 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10447 | |
| 10448 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10449 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10450 | err: |
| 10451 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10452 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10453 | } |
| 10454 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10455 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 10456 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10457 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10458 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10459 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10460 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10461 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10462 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10463 | if (ret) |
| 10464 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10465 | |
| 10466 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 10467 | if (plane_state->crtc != crtc) |
| 10468 | continue; |
| 10469 | |
| 10470 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 10471 | if (ret) |
| 10472 | return ret; |
| 10473 | |
| 10474 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 10475 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10476 | |
| 10477 | return 0; |
| 10478 | } |
| 10479 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10480 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10481 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10482 | struct intel_load_detect_pipe *old, |
| 10483 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10484 | { |
| 10485 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10486 | struct intel_encoder *intel_encoder = |
| 10487 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10488 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10489 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10490 | struct drm_crtc *crtc = NULL; |
| 10491 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10492 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10493 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10494 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10495 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10496 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10497 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10498 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10499 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10500 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10501 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10502 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10503 | old->restore_state = NULL; |
| 10504 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10505 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10506 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10507 | /* |
| 10508 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10509 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10510 | * - if the connector already has an assigned crtc, use it (but make |
| 10511 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10512 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10513 | * - try to find the first unused crtc that can drive this connector, |
| 10514 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10515 | */ |
| 10516 | |
| 10517 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10518 | if (connector->state->crtc) { |
| 10519 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10520 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10521 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10522 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10523 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10524 | |
| 10525 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10526 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10527 | } |
| 10528 | |
| 10529 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10530 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10531 | i++; |
| 10532 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10533 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10534 | |
| 10535 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10536 | if (ret) |
| 10537 | goto fail; |
| 10538 | |
| 10539 | if (possible_crtc->state->enable) { |
| 10540 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10541 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10542 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10543 | |
| 10544 | crtc = possible_crtc; |
| 10545 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10546 | } |
| 10547 | |
| 10548 | /* |
| 10549 | * If we didn't find an unused CRTC, don't use any. |
| 10550 | */ |
| 10551 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10552 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10553 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10554 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10555 | } |
| 10556 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10557 | found: |
| 10558 | intel_crtc = to_intel_crtc(crtc); |
| 10559 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10560 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10561 | restore_state = drm_atomic_state_alloc(dev); |
| 10562 | if (!state || !restore_state) { |
| 10563 | ret = -ENOMEM; |
| 10564 | goto fail; |
| 10565 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10566 | |
| 10567 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10568 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10569 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10570 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10571 | if (IS_ERR(connector_state)) { |
| 10572 | ret = PTR_ERR(connector_state); |
| 10573 | goto fail; |
| 10574 | } |
| 10575 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10576 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10577 | if (ret) |
| 10578 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10579 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10580 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10581 | if (IS_ERR(crtc_state)) { |
| 10582 | ret = PTR_ERR(crtc_state); |
| 10583 | goto fail; |
| 10584 | } |
| 10585 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10586 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10587 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10588 | if (!mode) |
| 10589 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10590 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10591 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10592 | if (ret) |
| 10593 | goto fail; |
| 10594 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10595 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10596 | if (ret) |
| 10597 | goto fail; |
| 10598 | |
| 10599 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10600 | if (!ret) |
| 10601 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); |
Ville Syrjälä | be90cc3 | 2018-03-22 17:23:12 +0200 | [diff] [blame] | 10602 | if (!ret) |
| 10603 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10604 | if (ret) { |
| 10605 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10606 | goto fail; |
| 10607 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10608 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10609 | ret = drm_atomic_commit(state); |
| 10610 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10611 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10612 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10613 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10614 | |
| 10615 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10616 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10617 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10618 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10619 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10620 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10621 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10622 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10623 | if (state) { |
| 10624 | drm_atomic_state_put(state); |
| 10625 | state = NULL; |
| 10626 | } |
| 10627 | if (restore_state) { |
| 10628 | drm_atomic_state_put(restore_state); |
| 10629 | restore_state = NULL; |
| 10630 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10631 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10632 | if (ret == -EDEADLK) |
| 10633 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10634 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10635 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10636 | } |
| 10637 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10638 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10639 | struct intel_load_detect_pipe *old, |
| 10640 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10641 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10642 | struct intel_encoder *intel_encoder = |
| 10643 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10644 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10645 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10646 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10647 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10648 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10649 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10650 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10651 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10652 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10653 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10654 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10655 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10656 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10657 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10658 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10659 | } |
| 10660 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10661 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10662 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10663 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10664 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10665 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10666 | |
| 10667 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10668 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10669 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10670 | return 120000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10671 | else if (!IS_GEN(dev_priv, 2)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10672 | return 96000; |
| 10673 | else |
| 10674 | return 48000; |
| 10675 | } |
| 10676 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10677 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10678 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10679 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10680 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10681 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10682 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10683 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10684 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10685 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10686 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10687 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10688 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10689 | |
| 10690 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10691 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10692 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10693 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10694 | |
| 10695 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10696 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10697 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10698 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10699 | } else { |
| 10700 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10701 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10702 | } |
| 10703 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10704 | if (!IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10705 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10706 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10707 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10708 | else |
| 10709 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10710 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10711 | |
| 10712 | switch (dpll & DPLL_MODE_MASK) { |
| 10713 | case DPLLB_MODE_DAC_SERIAL: |
| 10714 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10715 | 5 : 10; |
| 10716 | break; |
| 10717 | case DPLLB_MODE_LVDS: |
| 10718 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10719 | 7 : 14; |
| 10720 | break; |
| 10721 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10722 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10723 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10724 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10725 | } |
| 10726 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10727 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10728 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10729 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10730 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10731 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10732 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10733 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10734 | |
| 10735 | if (is_lvds) { |
| 10736 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10737 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10738 | |
| 10739 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10740 | clock.p2 = 7; |
| 10741 | else |
| 10742 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10743 | } else { |
| 10744 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10745 | clock.p1 = 2; |
| 10746 | else { |
| 10747 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10748 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10749 | } |
| 10750 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10751 | clock.p2 = 4; |
| 10752 | else |
| 10753 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10754 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10755 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10756 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10757 | } |
| 10758 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10759 | /* |
| 10760 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10761 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10762 | * encoder's get_config() function. |
| 10763 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10764 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10765 | } |
| 10766 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10767 | int intel_dotclock_calculate(int link_freq, |
| 10768 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10769 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10770 | /* |
| 10771 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10772 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10773 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10774 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10775 | * |
| 10776 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10777 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10778 | */ |
| 10779 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10780 | if (!m_n->link_n) |
| 10781 | return 0; |
| 10782 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10783 | return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10784 | } |
| 10785 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10786 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10787 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10788 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10789 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10790 | |
| 10791 | /* read out port_clock from the DPLL */ |
| 10792 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10793 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10794 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10795 | * In case there is an active pipe without active ports, |
| 10796 | * we may need some idea for the dotclock anyway. |
| 10797 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10798 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10799 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10800 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10801 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10802 | } |
| 10803 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10804 | /* Returns the currently programmed mode of the given encoder. */ |
| 10805 | struct drm_display_mode * |
| 10806 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10807 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10808 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10809 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10810 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10811 | struct intel_crtc *crtc; |
| 10812 | enum pipe pipe; |
| 10813 | |
| 10814 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10815 | return NULL; |
| 10816 | |
| 10817 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10818 | |
| 10819 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10820 | if (!mode) |
| 10821 | return NULL; |
| 10822 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10823 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10824 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10825 | kfree(mode); |
| 10826 | return NULL; |
| 10827 | } |
| 10828 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10829 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10830 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10831 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10832 | kfree(crtc_state); |
| 10833 | kfree(mode); |
| 10834 | return NULL; |
| 10835 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10836 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10837 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10838 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10839 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10840 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10841 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10842 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10843 | return mode; |
| 10844 | } |
| 10845 | |
| 10846 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10847 | { |
| 10848 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10849 | |
| 10850 | drm_crtc_cleanup(crtc); |
| 10851 | kfree(intel_crtc); |
| 10852 | } |
| 10853 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10854 | /** |
| 10855 | * intel_wm_need_update - Check whether watermarks need updating |
Chris Wilson | 6bf1981 | 2018-12-31 14:35:05 +0000 | [diff] [blame] | 10856 | * @cur: current plane state |
| 10857 | * @new: new plane state |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10858 | * |
| 10859 | * Check current plane state versus the new one to determine whether |
| 10860 | * watermarks need to be recalculated. |
| 10861 | * |
| 10862 | * Returns true or false. |
| 10863 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10864 | static bool intel_wm_need_update(struct intel_plane_state *cur, |
| 10865 | struct intel_plane_state *new) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10866 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10867 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10868 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10869 | return true; |
| 10870 | |
| 10871 | if (!cur->base.fb || !new->base.fb) |
| 10872 | return false; |
| 10873 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10874 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10875 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10876 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10877 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10878 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10879 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10880 | return true; |
| 10881 | |
| 10882 | return false; |
| 10883 | } |
| 10884 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10885 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10886 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10887 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10888 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10889 | int dst_w = drm_rect_width(&state->base.dst); |
| 10890 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10891 | |
| 10892 | return (src_w != dst_w || src_h != dst_h); |
| 10893 | } |
| 10894 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10895 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10896 | struct drm_crtc_state *crtc_state, |
| 10897 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10898 | struct drm_plane_state *plane_state) |
| 10899 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10900 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10901 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10902 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10903 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10904 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10905 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10906 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10907 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10908 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10909 | bool turn_off, turn_on, visible, was_visible; |
| 10910 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10911 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10912 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10913 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10914 | ret = skl_update_scaler_plane( |
| 10915 | to_intel_crtc_state(crtc_state), |
| 10916 | to_intel_plane_state(plane_state)); |
| 10917 | if (ret) |
| 10918 | return ret; |
| 10919 | } |
| 10920 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10921 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10922 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10923 | |
| 10924 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10925 | was_visible = false; |
| 10926 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10927 | /* |
| 10928 | * Visibility is calculated as if the crtc was on, but |
| 10929 | * after scaler setup everything depends on it being off |
| 10930 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10931 | * |
| 10932 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10933 | * be computed as if the pipe would be active. Perhaps move |
| 10934 | * per-plane wm computation to the .check_plane() hook, and |
| 10935 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10936 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10937 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10938 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10939 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10940 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10941 | |
| 10942 | if (!was_visible && !visible) |
| 10943 | return 0; |
| 10944 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10945 | if (fb != old_plane_state->base.fb) |
| 10946 | pipe_config->fb_changed = true; |
| 10947 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10948 | turn_off = was_visible && (!visible || mode_changed); |
| 10949 | turn_on = visible && (!was_visible || mode_changed); |
| 10950 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10951 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n", |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10952 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 10953 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10954 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10955 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10956 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n", |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10957 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10958 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10959 | turn_off, turn_on, mode_changed); |
| 10960 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10961 | if (turn_on) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10962 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10963 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10964 | |
| 10965 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10966 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10967 | pipe_config->disable_cxsr = true; |
| 10968 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10969 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10970 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10971 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10972 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10973 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10974 | pipe_config->disable_cxsr = true; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10975 | } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state), |
| 10976 | to_intel_plane_state(plane_state))) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10977 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10978 | /* FIXME bollocks */ |
| 10979 | pipe_config->update_wm_pre = true; |
| 10980 | pipe_config->update_wm_post = true; |
| 10981 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10982 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10983 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 10984 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10985 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10986 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10987 | /* |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10988 | * ILK/SNB DVSACNTR/Sprite Enable |
| 10989 | * IVB SPR_CTL/Sprite Enable |
| 10990 | * "When in Self Refresh Big FIFO mode, a write to enable the |
| 10991 | * plane will be internally buffered and delayed while Big FIFO |
| 10992 | * mode is exiting." |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10993 | * |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10994 | * Which means that enabling the sprite can take an extra frame |
| 10995 | * when we start in big FIFO mode (LP1+). Thus we need to drop |
| 10996 | * down to LP0 and wait for vblank in order to make sure the |
| 10997 | * sprite gets enabled on the next vblank after the register write. |
| 10998 | * Doing otherwise would risk enabling the sprite one frame after |
| 10999 | * we've already signalled flip completion. We can resume LP1+ |
| 11000 | * once the sprite has been enabled. |
| 11001 | * |
| 11002 | * |
| 11003 | * WaCxSRDisabledForSpriteScaling:ivb |
| 11004 | * IVB SPR_SCALE/Scaling Enable |
| 11005 | * "Low Power watermarks must be disabled for at least one |
| 11006 | * frame before enabling sprite scaling, and kept disabled |
| 11007 | * until sprite scaling is disabled." |
| 11008 | * |
| 11009 | * ILK/SNB DVSASCALE/Scaling Enable |
| 11010 | * "When in Self Refresh Big FIFO mode, scaling enable will be |
| 11011 | * masked off while Big FIFO mode is exiting." |
| 11012 | * |
| 11013 | * Despite the w/a only being listed for IVB we assume that |
| 11014 | * the ILK/SNB note has similar ramifications, hence we apply |
| 11015 | * the w/a on all three platforms. |
Juha-Pekka Heikkila | d8af327 | 2018-12-20 13:26:08 +0200 | [diff] [blame] | 11016 | * |
| 11017 | * With experimental results seems this is needed also for primary |
| 11018 | * plane, not only sprite plane. |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11019 | */ |
Juha-Pekka Heikkila | d8af327 | 2018-12-20 13:26:08 +0200 | [diff] [blame] | 11020 | if (plane->id != PLANE_CURSOR && |
Lucas De Marchi | f3ce44a | 2018-12-12 10:10:44 -0800 | [diff] [blame] | 11021 | (IS_GEN_RANGE(dev_priv, 5, 6) || |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 11022 | IS_IVYBRIDGE(dev_priv)) && |
| 11023 | (turn_on || (!needs_scaling(old_plane_state) && |
| 11024 | needs_scaling(to_intel_plane_state(plane_state))))) |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11025 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11026 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11027 | return 0; |
| 11028 | } |
| 11029 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11030 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 11031 | const struct intel_encoder *b) |
| 11032 | { |
| 11033 | /* masks could be asymmetric, so check both ways */ |
| 11034 | return a == b || (a->cloneable & (1 << b->type) && |
| 11035 | b->cloneable & (1 << a->type)); |
| 11036 | } |
| 11037 | |
| 11038 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 11039 | struct intel_crtc *crtc, |
| 11040 | struct intel_encoder *encoder) |
| 11041 | { |
| 11042 | struct intel_encoder *source_encoder; |
| 11043 | struct drm_connector *connector; |
| 11044 | struct drm_connector_state *connector_state; |
| 11045 | int i; |
| 11046 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11047 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11048 | if (connector_state->crtc != &crtc->base) |
| 11049 | continue; |
| 11050 | |
| 11051 | source_encoder = |
| 11052 | to_intel_encoder(connector_state->best_encoder); |
| 11053 | if (!encoders_cloneable(encoder, source_encoder)) |
| 11054 | return false; |
| 11055 | } |
| 11056 | |
| 11057 | return true; |
| 11058 | } |
| 11059 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11060 | static int icl_add_linked_planes(struct intel_atomic_state *state) |
| 11061 | { |
| 11062 | struct intel_plane *plane, *linked; |
| 11063 | struct intel_plane_state *plane_state, *linked_plane_state; |
| 11064 | int i; |
| 11065 | |
| 11066 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 11067 | linked = plane_state->linked_plane; |
| 11068 | |
| 11069 | if (!linked) |
| 11070 | continue; |
| 11071 | |
| 11072 | linked_plane_state = intel_atomic_get_plane_state(state, linked); |
| 11073 | if (IS_ERR(linked_plane_state)) |
| 11074 | return PTR_ERR(linked_plane_state); |
| 11075 | |
| 11076 | WARN_ON(linked_plane_state->linked_plane != plane); |
| 11077 | WARN_ON(linked_plane_state->slave == plane_state->slave); |
| 11078 | } |
| 11079 | |
| 11080 | return 0; |
| 11081 | } |
| 11082 | |
| 11083 | static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state) |
| 11084 | { |
| 11085 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 11086 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 11087 | struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state); |
| 11088 | struct intel_plane *plane, *linked; |
| 11089 | struct intel_plane_state *plane_state; |
| 11090 | int i; |
| 11091 | |
| 11092 | if (INTEL_GEN(dev_priv) < 11) |
| 11093 | return 0; |
| 11094 | |
| 11095 | /* |
| 11096 | * Destroy all old plane links and make the slave plane invisible |
| 11097 | * in the crtc_state->active_planes mask. |
| 11098 | */ |
| 11099 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 11100 | if (plane->pipe != crtc->pipe || !plane_state->linked_plane) |
| 11101 | continue; |
| 11102 | |
| 11103 | plane_state->linked_plane = NULL; |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 11104 | if (plane_state->slave && !plane_state->base.visible) { |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11105 | crtc_state->active_planes &= ~BIT(plane->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 11106 | crtc_state->update_planes |= BIT(plane->id); |
| 11107 | } |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11108 | |
| 11109 | plane_state->slave = false; |
| 11110 | } |
| 11111 | |
| 11112 | if (!crtc_state->nv12_planes) |
| 11113 | return 0; |
| 11114 | |
| 11115 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 11116 | struct intel_plane_state *linked_state = NULL; |
| 11117 | |
| 11118 | if (plane->pipe != crtc->pipe || |
| 11119 | !(crtc_state->nv12_planes & BIT(plane->id))) |
| 11120 | continue; |
| 11121 | |
| 11122 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) { |
| 11123 | if (!icl_is_nv12_y_plane(linked->id)) |
| 11124 | continue; |
| 11125 | |
| 11126 | if (crtc_state->active_planes & BIT(linked->id)) |
| 11127 | continue; |
| 11128 | |
| 11129 | linked_state = intel_atomic_get_plane_state(state, linked); |
| 11130 | if (IS_ERR(linked_state)) |
| 11131 | return PTR_ERR(linked_state); |
| 11132 | |
| 11133 | break; |
| 11134 | } |
| 11135 | |
| 11136 | if (!linked_state) { |
| 11137 | DRM_DEBUG_KMS("Need %d free Y planes for NV12\n", |
| 11138 | hweight8(crtc_state->nv12_planes)); |
| 11139 | |
| 11140 | return -EINVAL; |
| 11141 | } |
| 11142 | |
| 11143 | plane_state->linked_plane = linked; |
| 11144 | |
| 11145 | linked_state->slave = true; |
| 11146 | linked_state->linked_plane = plane; |
| 11147 | crtc_state->active_planes |= BIT(linked->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 11148 | crtc_state->update_planes |= BIT(linked->id); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11149 | DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name); |
| 11150 | } |
| 11151 | |
| 11152 | return 0; |
| 11153 | } |
| 11154 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11155 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 11156 | struct drm_crtc_state *crtc_state) |
| 11157 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11158 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11159 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11160 | struct intel_crtc_state *pipe_config = |
| 11161 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11162 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11163 | bool mode_changed = needs_modeset(crtc_state); |
| 11164 | |
Ville Syrjälä | 440e84a | 2019-02-06 20:54:33 +0200 | [diff] [blame] | 11165 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) && |
| 11166 | mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11167 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 11168 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11169 | if (mode_changed && crtc_state->enable && |
| 11170 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11171 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11172 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11173 | pipe_config); |
| 11174 | if (ret) |
| 11175 | return ret; |
| 11176 | } |
| 11177 | |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 11178 | if (mode_changed || crtc_state->color_mgmt_changed) { |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 11179 | ret = intel_color_check(pipe_config); |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11180 | if (ret) |
| 11181 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 11182 | |
| 11183 | /* |
| 11184 | * Changing color management on Intel hardware is |
| 11185 | * handled as part of planes update. |
| 11186 | */ |
| 11187 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11188 | } |
| 11189 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11190 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11191 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 11192 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11193 | if (ret) { |
| 11194 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11195 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11196 | } |
| 11197 | } |
| 11198 | |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 11199 | if (dev_priv->display.compute_intermediate_wm) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11200 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 11201 | return 0; |
| 11202 | |
| 11203 | /* |
| 11204 | * Calculate 'intermediate' watermarks that satisfy both the |
| 11205 | * old state and the new state. We can program these |
| 11206 | * immediately. |
| 11207 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11208 | ret = dev_priv->display.compute_intermediate_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11209 | if (ret) { |
| 11210 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 11211 | return ret; |
| 11212 | } |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11213 | } |
| 11214 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11215 | if (INTEL_GEN(dev_priv) >= 9) { |
Hans de Goede | 2c5c415 | 2018-12-17 15:19:03 +0100 | [diff] [blame] | 11216 | if (mode_changed || pipe_config->update_pipe) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11217 | ret = skl_update_scaler_crtc(pipe_config); |
| 11218 | |
| 11219 | if (!ret) |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11220 | ret = icl_check_nv12_planes(pipe_config); |
| 11221 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 11222 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 11223 | pipe_config); |
| 11224 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 11225 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11226 | pipe_config); |
| 11227 | } |
| 11228 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 11229 | if (HAS_IPS(dev_priv)) |
| 11230 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 11231 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11232 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11233 | } |
| 11234 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11235 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11236 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11237 | }; |
| 11238 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11239 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11240 | { |
| 11241 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11242 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11243 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11244 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11245 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11246 | if (connector->base.state->crtc) |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11247 | drm_connector_put(&connector->base); |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11248 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11249 | if (connector->base.encoder) { |
| 11250 | connector->base.state->best_encoder = |
| 11251 | connector->base.encoder; |
| 11252 | connector->base.state->crtc = |
| 11253 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11254 | |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11255 | drm_connector_get(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11256 | } else { |
| 11257 | connector->base.state->best_encoder = NULL; |
| 11258 | connector->base.state->crtc = NULL; |
| 11259 | } |
| 11260 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11261 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11262 | } |
| 11263 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11264 | static int |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11265 | compute_sink_pipe_bpp(const struct drm_connector_state *conn_state, |
| 11266 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11267 | { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11268 | struct drm_connector *connector = conn_state->connector; |
| 11269 | const struct drm_display_info *info = &connector->display_info; |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11270 | int bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11271 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11272 | switch (conn_state->max_bpc) { |
| 11273 | case 6 ... 7: |
| 11274 | bpp = 6 * 3; |
| 11275 | break; |
| 11276 | case 8 ... 9: |
| 11277 | bpp = 8 * 3; |
| 11278 | break; |
| 11279 | case 10 ... 11: |
| 11280 | bpp = 10 * 3; |
| 11281 | break; |
| 11282 | case 12: |
| 11283 | bpp = 12 * 3; |
| 11284 | break; |
| 11285 | default: |
| 11286 | return -EINVAL; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11287 | } |
| 11288 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11289 | if (bpp < pipe_config->pipe_bpp) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11290 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of " |
| 11291 | "EDID bpp %d, requested bpp %d, max platform bpp %d\n", |
| 11292 | connector->base.id, connector->name, |
| 11293 | bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc, |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11294 | pipe_config->pipe_bpp); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11295 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11296 | pipe_config->pipe_bpp = bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11297 | } |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11298 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11299 | return 0; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11300 | } |
| 11301 | |
| 11302 | static int |
| 11303 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11304 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11305 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11306 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11307 | struct drm_atomic_state *state = pipe_config->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11308 | struct drm_connector *connector; |
| 11309 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11310 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11311 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11312 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 11313 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11314 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11315 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11316 | bpp = 12*3; |
| 11317 | else |
| 11318 | bpp = 8*3; |
| 11319 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11320 | pipe_config->pipe_bpp = bpp; |
| 11321 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11322 | /* Clamp display bpp to connector max bpp */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11323 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11324 | int ret; |
| 11325 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11326 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11327 | continue; |
| 11328 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11329 | ret = compute_sink_pipe_bpp(connector_state, pipe_config); |
| 11330 | if (ret) |
| 11331 | return ret; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11332 | } |
| 11333 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11334 | return 0; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11335 | } |
| 11336 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11337 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11338 | { |
| 11339 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11340 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11341 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11342 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11343 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11344 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11345 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11346 | } |
| 11347 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11348 | static inline void |
| 11349 | intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id, |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11350 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11351 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11352 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11353 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11354 | m_n->gmch_m, m_n->gmch_n, |
| 11355 | m_n->link_m, m_n->link_n, m_n->tu); |
| 11356 | } |
| 11357 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11358 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 11359 | |
| 11360 | static const char * const output_type_str[] = { |
| 11361 | OUTPUT_TYPE(UNUSED), |
| 11362 | OUTPUT_TYPE(ANALOG), |
| 11363 | OUTPUT_TYPE(DVO), |
| 11364 | OUTPUT_TYPE(SDVO), |
| 11365 | OUTPUT_TYPE(LVDS), |
| 11366 | OUTPUT_TYPE(TVOUT), |
| 11367 | OUTPUT_TYPE(HDMI), |
| 11368 | OUTPUT_TYPE(DP), |
| 11369 | OUTPUT_TYPE(EDP), |
| 11370 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11371 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11372 | OUTPUT_TYPE(DP_MST), |
| 11373 | }; |
| 11374 | |
| 11375 | #undef OUTPUT_TYPE |
| 11376 | |
| 11377 | static void snprintf_output_types(char *buf, size_t len, |
| 11378 | unsigned int output_types) |
| 11379 | { |
| 11380 | char *str = buf; |
| 11381 | int i; |
| 11382 | |
| 11383 | str[0] = '\0'; |
| 11384 | |
| 11385 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 11386 | int r; |
| 11387 | |
| 11388 | if ((output_types & BIT(i)) == 0) |
| 11389 | continue; |
| 11390 | |
| 11391 | r = snprintf(str, len, "%s%s", |
| 11392 | str != buf ? "," : "", output_type_str[i]); |
| 11393 | if (r >= len) |
| 11394 | break; |
| 11395 | str += r; |
| 11396 | len -= r; |
| 11397 | |
| 11398 | output_types &= ~BIT(i); |
| 11399 | } |
| 11400 | |
| 11401 | WARN_ON_ONCE(output_types != 0); |
| 11402 | } |
| 11403 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11404 | static const char * const output_format_str[] = { |
| 11405 | [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid", |
| 11406 | [INTEL_OUTPUT_FORMAT_RGB] = "RGB", |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11407 | [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0", |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 11408 | [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4", |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11409 | }; |
| 11410 | |
| 11411 | static const char *output_formats(enum intel_output_format format) |
| 11412 | { |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11413 | if (format >= ARRAY_SIZE(output_format_str)) |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11414 | format = INTEL_OUTPUT_FORMAT_INVALID; |
| 11415 | return output_format_str[format]; |
| 11416 | } |
| 11417 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11418 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11419 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11420 | const char *context) |
| 11421 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11422 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11423 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11424 | struct drm_plane *plane; |
| 11425 | struct intel_plane *intel_plane; |
| 11426 | struct intel_plane_state *state; |
| 11427 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11428 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11429 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 11430 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 11431 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11432 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11433 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 11434 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 11435 | buf, pipe_config->output_types); |
| 11436 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11437 | DRM_DEBUG_KMS("output format: %s\n", |
| 11438 | output_formats(pipe_config->output_format)); |
| 11439 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11440 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 11441 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11442 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11443 | |
| 11444 | if (pipe_config->has_pch_encoder) |
| 11445 | intel_dump_m_n_config(pipe_config, "fdi", |
| 11446 | pipe_config->fdi_lanes, |
| 11447 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11448 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11449 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11450 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 11451 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 11452 | if (pipe_config->has_drrs) |
| 11453 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 11454 | pipe_config->lane_count, |
| 11455 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11456 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11457 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11458 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11459 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11460 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11461 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11462 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11463 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11464 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11465 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11466 | DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11467 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11468 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 11469 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11470 | |
| 11471 | if (INTEL_GEN(dev_priv) >= 9) |
| 11472 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11473 | crtc->num_scalers, |
| 11474 | pipe_config->scaler_state.scaler_users, |
| 11475 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11476 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 11477 | if (HAS_GMCH(dev_priv)) |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11478 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11479 | pipe_config->gmch_pfit.control, |
| 11480 | pipe_config->gmch_pfit.pgm_ratios, |
| 11481 | pipe_config->gmch_pfit.lvds_border_bits); |
| 11482 | else |
| 11483 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 11484 | pipe_config->pch_pfit.pos, |
| 11485 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 11486 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11487 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11488 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 11489 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11490 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 11491 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11492 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11493 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11494 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11495 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11496 | intel_plane = to_intel_plane(plane); |
| 11497 | if (intel_plane->pipe != crtc->pipe) |
| 11498 | continue; |
| 11499 | |
| 11500 | state = to_intel_plane_state(plane->state); |
| 11501 | fb = state->base.fb; |
| 11502 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 11503 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 11504 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11505 | continue; |
| 11506 | } |
| 11507 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11508 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 11509 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11510 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 11511 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11512 | if (INTEL_GEN(dev_priv) >= 9) |
| 11513 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 11514 | state->scaler_id, |
| 11515 | state->base.src.x1 >> 16, |
| 11516 | state->base.src.y1 >> 16, |
| 11517 | drm_rect_width(&state->base.src) >> 16, |
| 11518 | drm_rect_height(&state->base.src) >> 16, |
| 11519 | state->base.dst.x1, state->base.dst.y1, |
| 11520 | drm_rect_width(&state->base.dst), |
| 11521 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11522 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11523 | } |
| 11524 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11525 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11526 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11527 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11528 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11529 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11530 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11531 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11532 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11533 | |
| 11534 | /* |
| 11535 | * Walk the connector list instead of the encoder |
| 11536 | * list to detect the problem on ddi platforms |
| 11537 | * where there's just one encoder per digital port. |
| 11538 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11539 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11540 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11541 | struct drm_connector_state *connector_state; |
| 11542 | struct intel_encoder *encoder; |
| 11543 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 11544 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11545 | if (!connector_state) |
| 11546 | connector_state = connector->state; |
| 11547 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11548 | if (!connector_state->best_encoder) |
| 11549 | continue; |
| 11550 | |
| 11551 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11552 | |
| 11553 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11554 | |
| 11555 | switch (encoder->type) { |
| 11556 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11557 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11558 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11559 | break; |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 11560 | /* else: fall through */ |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 11561 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11562 | case INTEL_OUTPUT_HDMI: |
| 11563 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11564 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11565 | |
| 11566 | /* the same port mustn't appear more than once */ |
| 11567 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11568 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11569 | |
| 11570 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11571 | break; |
| 11572 | case INTEL_OUTPUT_DP_MST: |
| 11573 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11574 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11575 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11576 | default: |
| 11577 | break; |
| 11578 | } |
| 11579 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11580 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11581 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11582 | /* can't mix MST and SST/HDMI on the same port */ |
| 11583 | if (used_ports & used_mst_ports) |
| 11584 | return false; |
| 11585 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11586 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11587 | } |
| 11588 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11589 | static int |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11590 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11591 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11592 | struct drm_i915_private *dev_priv = |
| 11593 | to_i915(crtc_state->base.crtc->dev); |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11594 | struct intel_crtc_state *saved_state; |
| 11595 | |
| 11596 | saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL); |
| 11597 | if (!saved_state) |
| 11598 | return -ENOMEM; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11599 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 11600 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 11601 | * kzalloc'd. Code that depends on any field being zero should be |
| 11602 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 11603 | * only fields that are know to not cause problems are preserved. */ |
| 11604 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11605 | saved_state->scaler_state = crtc_state->scaler_state; |
| 11606 | saved_state->shared_dpll = crtc_state->shared_dpll; |
| 11607 | saved_state->dpll_hw_state = crtc_state->dpll_hw_state; |
| 11608 | saved_state->pch_pfit.force_thru = crtc_state->pch_pfit.force_thru; |
| 11609 | saved_state->ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11610 | if (IS_G4X(dev_priv) || |
| 11611 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11612 | saved_state->wm = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11613 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11614 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 11615 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11616 | memcpy(&crtc_state->base + 1, &saved_state->base + 1, |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11617 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11618 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11619 | kfree(saved_state); |
| 11620 | return 0; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11621 | } |
| 11622 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11623 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11624 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11625 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11626 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11627 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11628 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11629 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11630 | struct drm_connector_state *connector_state; |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11631 | int base_bpp, ret; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11632 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11633 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11634 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11635 | ret = clear_intel_crtc_state(pipe_config); |
| 11636 | if (ret) |
| 11637 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11638 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11639 | pipe_config->cpu_transcoder = |
| 11640 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11641 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11642 | /* |
| 11643 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11644 | * positive or negative polarity is requested, treat this as meaning |
| 11645 | * negative polarity. |
| 11646 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11647 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11648 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11649 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11650 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11651 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11652 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11653 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11654 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11655 | ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11656 | pipe_config); |
| 11657 | if (ret) |
| 11658 | return ret; |
| 11659 | |
| 11660 | base_bpp = pipe_config->pipe_bpp; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11661 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11662 | /* |
| 11663 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11664 | * increase the actual pipe size due to the frame doubling and |
| 11665 | * insertion of additional space for blanks between the frame. This |
| 11666 | * is stored in the crtc timings. We use the requested mode to do this |
| 11667 | * computation to clearly distinguish it from the adjusted mode, which |
| 11668 | * can be changed by the connectors in the below retry loop. |
| 11669 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 11670 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11671 | &pipe_config->pipe_src_w, |
| 11672 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11673 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11674 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11675 | if (connector_state->crtc != crtc) |
| 11676 | continue; |
| 11677 | |
| 11678 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11679 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11680 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11681 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11682 | return -EINVAL; |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11683 | } |
| 11684 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11685 | /* |
| 11686 | * Determine output_types before calling the .compute_config() |
| 11687 | * hooks so that the hooks can use this information safely. |
| 11688 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11689 | if (encoder->compute_output_type) |
| 11690 | pipe_config->output_types |= |
| 11691 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11692 | connector_state)); |
| 11693 | else |
| 11694 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11695 | } |
| 11696 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11697 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11698 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11699 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11700 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11701 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11702 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11703 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11704 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11705 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11706 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11707 | * adjust it according to limitations or connector properties, and also |
| 11708 | * a chance to reject the mode entirely. |
| 11709 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11710 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11711 | if (connector_state->crtc != crtc) |
| 11712 | continue; |
| 11713 | |
| 11714 | encoder = to_intel_encoder(connector_state->best_encoder); |
Lyude Paul | 9655055 | 2019-01-15 15:08:00 -0500 | [diff] [blame] | 11715 | ret = encoder->compute_config(encoder, pipe_config, |
| 11716 | connector_state); |
| 11717 | if (ret < 0) { |
| 11718 | if (ret != -EDEADLK) |
| 11719 | DRM_DEBUG_KMS("Encoder config failure: %d\n", |
| 11720 | ret); |
| 11721 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11722 | } |
| 11723 | } |
| 11724 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11725 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11726 | * done afterwards in case the encoder adjusts the mode. */ |
| 11727 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11728 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11729 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11730 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11731 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 11732 | if (ret == -EDEADLK) |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11733 | return ret; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11734 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11735 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11736 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11737 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11738 | |
| 11739 | if (ret == RETRY) { |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11740 | if (WARN(!retry, "loop in pipe configuration computation\n")) |
| 11741 | return -EINVAL; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11742 | |
| 11743 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11744 | retry = false; |
| 11745 | goto encoder_retry; |
| 11746 | } |
| 11747 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11748 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11749 | * only enable it on 6bpc panels and when its not a compliance |
| 11750 | * test requesting 6bpc video pattern. |
| 11751 | */ |
| 11752 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11753 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11754 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11755 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11756 | |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11757 | return 0; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11758 | } |
| 11759 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11760 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11761 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11762 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11763 | |
| 11764 | if (clock1 == clock2) |
| 11765 | return true; |
| 11766 | |
| 11767 | if (!clock1 || !clock2) |
| 11768 | return false; |
| 11769 | |
| 11770 | diff = abs(clock1 - clock2); |
| 11771 | |
| 11772 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11773 | return true; |
| 11774 | |
| 11775 | return false; |
| 11776 | } |
| 11777 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11778 | static bool |
| 11779 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11780 | unsigned int m2, unsigned int n2, |
| 11781 | bool exact) |
| 11782 | { |
| 11783 | if (m == m2 && n == n2) |
| 11784 | return true; |
| 11785 | |
| 11786 | if (exact || !m || !n || !m2 || !n2) |
| 11787 | return false; |
| 11788 | |
| 11789 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11790 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11791 | if (n > n2) { |
| 11792 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11793 | m2 <<= 1; |
| 11794 | n2 <<= 1; |
| 11795 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11796 | } else if (n < n2) { |
| 11797 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11798 | m <<= 1; |
| 11799 | n <<= 1; |
| 11800 | } |
| 11801 | } |
| 11802 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11803 | if (n != n2) |
| 11804 | return false; |
| 11805 | |
| 11806 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11807 | } |
| 11808 | |
| 11809 | static bool |
| 11810 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11811 | struct intel_link_m_n *m2_n2, |
| 11812 | bool adjust) |
| 11813 | { |
| 11814 | if (m_n->tu == m2_n2->tu && |
| 11815 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11816 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11817 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11818 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11819 | if (adjust) |
| 11820 | *m2_n2 = *m_n; |
| 11821 | |
| 11822 | return true; |
| 11823 | } |
| 11824 | |
| 11825 | return false; |
| 11826 | } |
| 11827 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11828 | static void __printf(3, 4) |
| 11829 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11830 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11831 | struct va_format vaf; |
| 11832 | va_list args; |
| 11833 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11834 | va_start(args, format); |
| 11835 | vaf.fmt = format; |
| 11836 | vaf.va = &args; |
| 11837 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11838 | if (adjust) |
| 11839 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11840 | else |
| 11841 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11842 | |
| 11843 | va_end(args); |
| 11844 | } |
| 11845 | |
Hans de Goede | 3d6535c | 2019-01-24 14:01:14 +0100 | [diff] [blame] | 11846 | static bool fastboot_enabled(struct drm_i915_private *dev_priv) |
| 11847 | { |
| 11848 | if (i915_modparams.fastboot != -1) |
| 11849 | return i915_modparams.fastboot; |
| 11850 | |
| 11851 | /* Enable fastboot by default on Skylake and newer */ |
Hans de Goede | 7360c9f | 2019-01-29 15:22:37 +0100 | [diff] [blame] | 11852 | if (INTEL_GEN(dev_priv) >= 9) |
| 11853 | return true; |
| 11854 | |
| 11855 | /* Enable fastboot by default on VLV and CHV */ |
| 11856 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 11857 | return true; |
| 11858 | |
| 11859 | /* Disabled by default on all others */ |
| 11860 | return false; |
Hans de Goede | 3d6535c | 2019-01-24 14:01:14 +0100 | [diff] [blame] | 11861 | } |
| 11862 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11863 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11864 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11865 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11866 | struct intel_crtc_state *pipe_config, |
| 11867 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11868 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11869 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11870 | bool fixup_inherited = adjust && |
| 11871 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11872 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11873 | |
Hans de Goede | 3d6535c | 2019-01-24 14:01:14 +0100 | [diff] [blame] | 11874 | if (fixup_inherited && !fastboot_enabled(dev_priv)) { |
Maarten Lankhorst | d19f958 | 2019-01-08 17:08:40 +0100 | [diff] [blame] | 11875 | DRM_DEBUG_KMS("initial modeset and fastboot not set\n"); |
| 11876 | ret = false; |
| 11877 | } |
| 11878 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11879 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11880 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11881 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11882 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11883 | current_config->name, \ |
| 11884 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11885 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11886 | } \ |
| 11887 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11888 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11889 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11890 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11891 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11892 | "(expected %i, found %i)\n", \ |
| 11893 | current_config->name, \ |
| 11894 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11895 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11896 | } \ |
| 11897 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11898 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11899 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11900 | if (current_config->name != pipe_config->name) { \ |
| 11901 | pipe_config_err(adjust, __stringify(name), \ |
| 11902 | "(expected %s, found %s)\n", \ |
| 11903 | yesno(current_config->name), \ |
| 11904 | yesno(pipe_config->name)); \ |
| 11905 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11906 | } \ |
| 11907 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11908 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11909 | /* |
| 11910 | * Checks state where we only read out the enabling, but not the entire |
| 11911 | * state itself (like full infoframes or ELD for audio). These states |
| 11912 | * require a full modeset on bootup to fix up. |
| 11913 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11914 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11915 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11916 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11917 | } else { \ |
| 11918 | pipe_config_err(adjust, __stringify(name), \ |
| 11919 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11920 | yesno(current_config->name), \ |
| 11921 | yesno(pipe_config->name)); \ |
| 11922 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11923 | } \ |
| 11924 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11925 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11926 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11927 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11928 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11929 | "(expected %p, found %p)\n", \ |
| 11930 | current_config->name, \ |
| 11931 | pipe_config->name); \ |
| 11932 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11933 | } \ |
| 11934 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11935 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11936 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11937 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11938 | &pipe_config->name,\ |
| 11939 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11940 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11941 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11942 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11943 | current_config->name.tu, \ |
| 11944 | current_config->name.gmch_m, \ |
| 11945 | current_config->name.gmch_n, \ |
| 11946 | current_config->name.link_m, \ |
| 11947 | current_config->name.link_n, \ |
| 11948 | pipe_config->name.tu, \ |
| 11949 | pipe_config->name.gmch_m, \ |
| 11950 | pipe_config->name.gmch_n, \ |
| 11951 | pipe_config->name.link_m, \ |
| 11952 | pipe_config->name.link_n); \ |
| 11953 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11954 | } \ |
| 11955 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11956 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 11957 | /* This is required for BDW+ where there is only one set of registers for |
| 11958 | * switching between high and low RR. |
| 11959 | * This macro can be used whenever a comparison has to be made between one |
| 11960 | * hw state and multiple sw state variables. |
| 11961 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11962 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11963 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11964 | &pipe_config->name, adjust) && \ |
| 11965 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 11966 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11967 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11968 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11969 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 11970 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11971 | current_config->name.tu, \ |
| 11972 | current_config->name.gmch_m, \ |
| 11973 | current_config->name.gmch_n, \ |
| 11974 | current_config->name.link_m, \ |
| 11975 | current_config->name.link_n, \ |
| 11976 | current_config->alt_name.tu, \ |
| 11977 | current_config->alt_name.gmch_m, \ |
| 11978 | current_config->alt_name.gmch_n, \ |
| 11979 | current_config->alt_name.link_m, \ |
| 11980 | current_config->alt_name.link_n, \ |
| 11981 | pipe_config->name.tu, \ |
| 11982 | pipe_config->name.gmch_m, \ |
| 11983 | pipe_config->name.gmch_n, \ |
| 11984 | pipe_config->name.link_m, \ |
| 11985 | pipe_config->name.link_n); \ |
| 11986 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11987 | } \ |
| 11988 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11989 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11990 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11991 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11992 | pipe_config_err(adjust, __stringify(name), \ |
| 11993 | "(%x) (expected %i, found %i)\n", \ |
| 11994 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11995 | current_config->name & (mask), \ |
| 11996 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11997 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11998 | } \ |
| 11999 | } while (0) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12000 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12001 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12002 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 12003 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12004 | "(expected %i, found %i)\n", \ |
| 12005 | current_config->name, \ |
| 12006 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12007 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12008 | } \ |
| 12009 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12010 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12011 | #define PIPE_CONF_QUIRK(quirk) \ |
| 12012 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 12013 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 12014 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 12015 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12016 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12017 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12018 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12019 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12020 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 12021 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12022 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12023 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12024 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12025 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12026 | if (current_config->has_drrs) |
| 12027 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 12028 | } else |
| 12029 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12030 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 12031 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 12032 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12033 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 12034 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 12035 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 12036 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 12037 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 12038 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12039 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12040 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 12041 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 12042 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 12043 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 12044 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 12045 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12046 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 12047 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 12048 | PIPE_CONF_CHECK_I(output_format); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12049 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 12050 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 12051 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12052 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 12053 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12054 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 12055 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 12056 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12057 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 12058 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 12059 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12060 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12061 | DRM_MODE_FLAG_INTERLACE); |
| 12062 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12063 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12064 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12065 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12066 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12067 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12068 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12069 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12070 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12071 | DRM_MODE_FLAG_NVSYNC); |
| 12072 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12073 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12074 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 12075 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12076 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 12077 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12078 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 12079 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12080 | if (!adjust) { |
| 12081 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 12082 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 12083 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12084 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12085 | if (current_config->pch_pfit.enabled) { |
| 12086 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 12087 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 12088 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12089 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12090 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12091 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12092 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 12093 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12094 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 12095 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12096 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12097 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 12098 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12099 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 12100 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 12101 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12102 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 12103 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 12104 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 12105 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 12106 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 12107 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 12108 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 12109 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 12110 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 12111 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 12112 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 12113 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 12114 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 12115 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 12116 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 12117 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 12118 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 12119 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 12120 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 12121 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 12122 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 12123 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 12124 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 12125 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 12126 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 12127 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12128 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 12129 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 12130 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 12131 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 12132 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 12133 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 12134 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12135 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 12136 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12137 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12138 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 12139 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12140 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12141 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12142 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 12143 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12144 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12145 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12146 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12147 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 12148 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12149 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12150 | } |
| 12151 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12152 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 12153 | const struct intel_crtc_state *pipe_config) |
| 12154 | { |
| 12155 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 12156 | int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12157 | &pipe_config->fdi_m_n); |
| 12158 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 12159 | |
| 12160 | /* |
| 12161 | * FDI already provided one idea for the dotclock. |
| 12162 | * Yell if the encoder disagrees. |
| 12163 | */ |
| 12164 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 12165 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 12166 | fdi_dotclock, dotclock); |
| 12167 | } |
| 12168 | } |
| 12169 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12170 | static void verify_wm_state(struct drm_crtc *crtc, |
| 12171 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12172 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12173 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12174 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12175 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 12176 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 12177 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12178 | struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES]; |
| 12179 | struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12181 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12182 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12183 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12184 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12185 | return; |
| 12186 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12187 | skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 12188 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12189 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12190 | skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv); |
| 12191 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12192 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12193 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12194 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 12195 | if (INTEL_GEN(dev_priv) >= 11) |
| 12196 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 12197 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 12198 | sw_ddb->enabled_slices, |
| 12199 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12200 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 12201 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12202 | hw_plane_wm = &hw_wm.planes[plane]; |
| 12203 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12204 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12205 | /* Watermarks */ |
| 12206 | for (level = 0; level <= max_level; level++) { |
| 12207 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12208 | &sw_plane_wm->wm[level])) |
| 12209 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12210 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12211 | DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12212 | pipe_name(pipe), plane + 1, level, |
| 12213 | sw_plane_wm->wm[level].plane_en, |
| 12214 | sw_plane_wm->wm[level].plane_res_b, |
| 12215 | sw_plane_wm->wm[level].plane_res_l, |
| 12216 | hw_plane_wm->wm[level].plane_en, |
| 12217 | hw_plane_wm->wm[level].plane_res_b, |
| 12218 | hw_plane_wm->wm[level].plane_res_l); |
| 12219 | } |
| 12220 | |
| 12221 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12222 | &sw_plane_wm->trans_wm)) { |
| 12223 | DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12224 | pipe_name(pipe), plane + 1, |
| 12225 | sw_plane_wm->trans_wm.plane_en, |
| 12226 | sw_plane_wm->trans_wm.plane_res_b, |
| 12227 | sw_plane_wm->trans_wm.plane_res_l, |
| 12228 | hw_plane_wm->trans_wm.plane_en, |
| 12229 | hw_plane_wm->trans_wm.plane_res_b, |
| 12230 | hw_plane_wm->trans_wm.plane_res_l); |
| 12231 | } |
| 12232 | |
| 12233 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12234 | hw_ddb_entry = &hw_ddb_y[plane]; |
| 12235 | sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane]; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12236 | |
| 12237 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12238 | DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n", |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12239 | pipe_name(pipe), plane + 1, |
| 12240 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12241 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 12242 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12243 | } |
| 12244 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12245 | /* |
| 12246 | * cursor |
| 12247 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 12248 | * allocation. In that case since the ddb allocation will be updated |
| 12249 | * once the plane becomes visible, we can skip this check |
| 12250 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 12251 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12252 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 12253 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12254 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12255 | /* Watermarks */ |
| 12256 | for (level = 0; level <= max_level; level++) { |
| 12257 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12258 | &sw_plane_wm->wm[level])) |
| 12259 | continue; |
| 12260 | |
| 12261 | DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12262 | pipe_name(pipe), level, |
| 12263 | sw_plane_wm->wm[level].plane_en, |
| 12264 | sw_plane_wm->wm[level].plane_res_b, |
| 12265 | sw_plane_wm->wm[level].plane_res_l, |
| 12266 | hw_plane_wm->wm[level].plane_en, |
| 12267 | hw_plane_wm->wm[level].plane_res_b, |
| 12268 | hw_plane_wm->wm[level].plane_res_l); |
| 12269 | } |
| 12270 | |
| 12271 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12272 | &sw_plane_wm->trans_wm)) { |
| 12273 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12274 | pipe_name(pipe), |
| 12275 | sw_plane_wm->trans_wm.plane_en, |
| 12276 | sw_plane_wm->trans_wm.plane_res_b, |
| 12277 | sw_plane_wm->trans_wm.plane_res_l, |
| 12278 | hw_plane_wm->trans_wm.plane_en, |
| 12279 | hw_plane_wm->trans_wm.plane_res_b, |
| 12280 | hw_plane_wm->trans_wm.plane_res_l); |
| 12281 | } |
| 12282 | |
| 12283 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12284 | hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR]; |
| 12285 | sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR]; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12286 | |
| 12287 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12288 | DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n", |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12289 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12290 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12291 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12292 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12293 | } |
| 12294 | } |
| 12295 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12296 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12297 | verify_connector_state(struct drm_device *dev, |
| 12298 | struct drm_atomic_state *state, |
| 12299 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12300 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12301 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12302 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12303 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12304 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12305 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12306 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12307 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12308 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12309 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12310 | continue; |
| 12311 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12312 | if (crtc) |
| 12313 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 12314 | |
| 12315 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12316 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12317 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12318 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12319 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12320 | } |
| 12321 | |
| 12322 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12323 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12324 | { |
| 12325 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12326 | struct drm_connector *connector; |
| 12327 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 12328 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12329 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12330 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12331 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12332 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12333 | |
| 12334 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12335 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12336 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12337 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12338 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 12339 | new_conn_state, i) { |
| 12340 | if (old_conn_state->best_encoder == &encoder->base) |
| 12341 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12342 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12343 | if (new_conn_state->best_encoder != &encoder->base) |
| 12344 | continue; |
| 12345 | found = enabled = true; |
| 12346 | |
| 12347 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12348 | encoder->base.crtc, |
| 12349 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12350 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12351 | |
| 12352 | if (!found) |
| 12353 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12354 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12355 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12356 | "encoder's enabled state mismatch " |
| 12357 | "(expected %i, found %i)\n", |
| 12358 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12359 | |
| 12360 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12361 | bool active; |
| 12362 | |
| 12363 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12364 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12365 | "encoder detached but still enabled on pipe %c.\n", |
| 12366 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12367 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12368 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12369 | } |
| 12370 | |
| 12371 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12372 | verify_crtc_state(struct drm_crtc *crtc, |
| 12373 | struct drm_crtc_state *old_crtc_state, |
| 12374 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12375 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12376 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12377 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12378 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12379 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12380 | struct intel_crtc_state *pipe_config, *sw_config; |
| 12381 | struct drm_atomic_state *old_state; |
| 12382 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12383 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12384 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 12385 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12386 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12387 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12388 | pipe_config->base.crtc = crtc; |
| 12389 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12390 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12391 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12392 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12393 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12394 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 12395 | /* we keep both pipes enabled on 830 */ |
| 12396 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12397 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12398 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12399 | I915_STATE_WARN(new_crtc_state->active != active, |
| 12400 | "crtc active state doesn't match with hw state " |
| 12401 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12402 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12403 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 12404 | "transitional active state does not match atomic hw state " |
| 12405 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12406 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12407 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12408 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12409 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12410 | active = encoder->get_hw_state(encoder, &pipe); |
| 12411 | I915_STATE_WARN(active != new_crtc_state->active, |
| 12412 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12413 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12414 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12415 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12416 | "Encoder connected to wrong pipe %c\n", |
| 12417 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12418 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 12419 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12420 | encoder->get_config(encoder, pipe_config); |
| 12421 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12422 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12423 | intel_crtc_compute_pixel_rate(pipe_config); |
| 12424 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12425 | if (!new_crtc_state->active) |
| 12426 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12427 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12428 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12429 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12430 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12431 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12432 | pipe_config, false)) { |
| 12433 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 12434 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 12435 | "[hw state]"); |
| 12436 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 12437 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12438 | } |
| 12439 | } |
| 12440 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12441 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12442 | intel_verify_planes(struct intel_atomic_state *state) |
| 12443 | { |
| 12444 | struct intel_plane *plane; |
| 12445 | const struct intel_plane_state *plane_state; |
| 12446 | int i; |
| 12447 | |
| 12448 | for_each_new_intel_plane_in_state(state, plane, |
| 12449 | plane_state, i) |
| 12450 | assert_plane(plane, plane_state->base.visible); |
| 12451 | } |
| 12452 | |
| 12453 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12454 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 12455 | struct intel_shared_dpll *pll, |
| 12456 | struct drm_crtc *crtc, |
| 12457 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12458 | { |
| 12459 | struct intel_dpll_hw_state dpll_hw_state; |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12460 | unsigned int crtc_mask; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12461 | bool active; |
| 12462 | |
| 12463 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12464 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 12465 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12466 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 12467 | active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12468 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 12469 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12470 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12471 | "pll in active use but not on in sw tracking\n"); |
| 12472 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12473 | "pll is on but not used by any active crtc\n"); |
| 12474 | I915_STATE_WARN(pll->on != active, |
| 12475 | "pll on state mismatch (expected %i, found %i)\n", |
| 12476 | pll->on, active); |
| 12477 | } |
| 12478 | |
| 12479 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12480 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12481 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12482 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12483 | |
| 12484 | return; |
| 12485 | } |
| 12486 | |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12487 | crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12488 | |
| 12489 | if (new_state->active) |
| 12490 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 12491 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 12492 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12493 | else |
| 12494 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12495 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 12496 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12497 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12498 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12499 | "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12500 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12501 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12502 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12503 | &dpll_hw_state, |
| 12504 | sizeof(dpll_hw_state)), |
| 12505 | "pll hw state mismatch\n"); |
| 12506 | } |
| 12507 | |
| 12508 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12509 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 12510 | struct drm_crtc_state *old_crtc_state, |
| 12511 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12512 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12513 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12514 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 12515 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 12516 | |
| 12517 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12518 | verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12519 | |
| 12520 | if (old_state->shared_dpll && |
| 12521 | old_state->shared_dpll != new_state->shared_dpll) { |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12522 | unsigned int crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12523 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 12524 | |
| 12525 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12526 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 12527 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12528 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12529 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 12530 | pipe_name(drm_crtc_index(crtc))); |
| 12531 | } |
| 12532 | } |
| 12533 | |
| 12534 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12535 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12536 | struct drm_atomic_state *state, |
| 12537 | struct drm_crtc_state *old_state, |
| 12538 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12539 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12540 | if (!needs_modeset(new_state) && |
| 12541 | !to_intel_crtc_state(new_state)->update_pipe) |
| 12542 | return; |
| 12543 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12544 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12545 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12546 | verify_crtc_state(crtc, old_state, new_state); |
| 12547 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12548 | } |
| 12549 | |
| 12550 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12551 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12552 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12553 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12554 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12555 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12556 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12557 | verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12558 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12559 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12560 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12561 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 12562 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12563 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12564 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12565 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12566 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12567 | } |
| 12568 | |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12569 | static void update_scanline_offset(const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12570 | { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12571 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12572 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12573 | |
| 12574 | /* |
| 12575 | * The scanline counter increments at the leading edge of hsync. |
| 12576 | * |
| 12577 | * On most platforms it starts counting from vtotal-1 on the |
| 12578 | * first active line. That means the scanline counter value is |
| 12579 | * always one less than what we would expect. Ie. just after |
| 12580 | * start of vblank, which also occurs at start of hsync (on the |
| 12581 | * last active line), the scanline counter will read vblank_start-1. |
| 12582 | * |
| 12583 | * On gen2 the scanline counter starts counting from 1 instead |
| 12584 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12585 | * to keep the value positive), instead of adding one. |
| 12586 | * |
| 12587 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12588 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12589 | * there's an extra 1 line difference. So we need to add two instead of |
| 12590 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 12591 | * |
| 12592 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 12593 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 12594 | * that means we can't tell whether we're in vblank or not while |
| 12595 | * we're on that particular line. We must still set scanline_offset |
| 12596 | * to 1 so that the vblank timestamps come out correct when we query |
| 12597 | * the scanline counter from within the vblank interrupt handler. |
| 12598 | * However if queried just before the start of vblank we'll get an |
| 12599 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12600 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 12601 | if (IS_GEN(dev_priv, 2)) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12602 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12603 | int vtotal; |
| 12604 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12605 | vtotal = adjusted_mode->crtc_vtotal; |
| 12606 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12607 | vtotal /= 2; |
| 12608 | |
| 12609 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12610 | } else if (HAS_DDI(dev_priv) && |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12611 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12612 | crtc->scanline_offset = 2; |
| 12613 | } else |
| 12614 | crtc->scanline_offset = 1; |
| 12615 | } |
| 12616 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12617 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12618 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12619 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12620 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12621 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12622 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12623 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12624 | |
| 12625 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12626 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12627 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12628 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12629 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12630 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12631 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12632 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12633 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12634 | continue; |
| 12635 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12636 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12637 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12638 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12639 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12640 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 12641 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12642 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12643 | } |
| 12644 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12645 | /* |
| 12646 | * This implements the workaround described in the "notes" section of the mode |
| 12647 | * set sequence documentation. When going from no pipes or single pipe to |
| 12648 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12649 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12650 | */ |
| 12651 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12652 | { |
| 12653 | struct drm_crtc_state *crtc_state; |
| 12654 | struct intel_crtc *intel_crtc; |
| 12655 | struct drm_crtc *crtc; |
| 12656 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12657 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12658 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12659 | int i; |
| 12660 | |
| 12661 | /* look at all crtc's that are going to be enabled in during modeset */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12662 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12663 | intel_crtc = to_intel_crtc(crtc); |
| 12664 | |
| 12665 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12666 | continue; |
| 12667 | |
| 12668 | if (first_crtc_state) { |
| 12669 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12670 | break; |
| 12671 | } else { |
| 12672 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12673 | first_pipe = intel_crtc->pipe; |
| 12674 | } |
| 12675 | } |
| 12676 | |
| 12677 | /* No workaround needed? */ |
| 12678 | if (!first_crtc_state) |
| 12679 | return 0; |
| 12680 | |
| 12681 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12682 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12683 | struct intel_crtc_state *pipe_config; |
| 12684 | |
| 12685 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12686 | if (IS_ERR(pipe_config)) |
| 12687 | return PTR_ERR(pipe_config); |
| 12688 | |
| 12689 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12690 | |
| 12691 | if (!pipe_config->base.active || |
| 12692 | needs_modeset(&pipe_config->base)) |
| 12693 | continue; |
| 12694 | |
| 12695 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12696 | if (enabled_pipe != INVALID_PIPE) |
| 12697 | return 0; |
| 12698 | |
| 12699 | enabled_pipe = intel_crtc->pipe; |
| 12700 | } |
| 12701 | |
| 12702 | if (enabled_pipe != INVALID_PIPE) |
| 12703 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12704 | else if (other_crtc_state) |
| 12705 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12706 | |
| 12707 | return 0; |
| 12708 | } |
| 12709 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12710 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12711 | { |
| 12712 | struct drm_crtc *crtc; |
| 12713 | |
| 12714 | /* Add all pipes to the state */ |
| 12715 | for_each_crtc(state->dev, crtc) { |
| 12716 | struct drm_crtc_state *crtc_state; |
| 12717 | |
| 12718 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12719 | if (IS_ERR(crtc_state)) |
| 12720 | return PTR_ERR(crtc_state); |
| 12721 | } |
| 12722 | |
| 12723 | return 0; |
| 12724 | } |
| 12725 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12726 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12727 | { |
| 12728 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12729 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12730 | /* |
| 12731 | * Add all pipes to the state, and force |
| 12732 | * a modeset on all the active ones. |
| 12733 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12734 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12735 | struct drm_crtc_state *crtc_state; |
| 12736 | int ret; |
| 12737 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12738 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12739 | if (IS_ERR(crtc_state)) |
| 12740 | return PTR_ERR(crtc_state); |
| 12741 | |
| 12742 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12743 | continue; |
| 12744 | |
| 12745 | crtc_state->mode_changed = true; |
| 12746 | |
| 12747 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12748 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12749 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12750 | |
| 12751 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12752 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12753 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12754 | } |
| 12755 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12756 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12757 | } |
| 12758 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12759 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12760 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12761 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12762 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12763 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12764 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12765 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12766 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12767 | if (!check_digital_port_conflicts(state)) { |
| 12768 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12769 | return -EINVAL; |
| 12770 | } |
| 12771 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12772 | intel_state->modeset = true; |
| 12773 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12774 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12775 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12776 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12777 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12778 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12779 | intel_state->active_crtcs |= 1 << i; |
| 12780 | else |
| 12781 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12782 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12783 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12784 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12785 | } |
| 12786 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12787 | /* |
| 12788 | * See if the config requires any additional preparation, e.g. |
| 12789 | * to adjust global state with pipes off. We need to do this |
| 12790 | * here so we can get the modeset_pipe updated config for the new |
| 12791 | * mode set on this crtc. For other crtcs we need to use the |
| 12792 | * adjusted_mode bits in the crtc directly. |
| 12793 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12794 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12795 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12796 | if (ret < 0) |
| 12797 | return ret; |
| 12798 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12799 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12800 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12801 | * holding all the crtc locks, even if we don't end up |
| 12802 | * touching the hardware |
| 12803 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12804 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12805 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12806 | ret = intel_lock_all_pipes(state); |
| 12807 | if (ret < 0) |
| 12808 | return ret; |
| 12809 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12810 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12811 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12812 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12813 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12814 | ret = intel_modeset_all_pipes(state); |
| 12815 | if (ret < 0) |
| 12816 | return ret; |
| 12817 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12818 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12819 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12820 | intel_state->cdclk.logical.cdclk, |
| 12821 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12822 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12823 | intel_state->cdclk.logical.voltage_level, |
| 12824 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12825 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12826 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12827 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12828 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12829 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12830 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12831 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12832 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12833 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12834 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12835 | } |
| 12836 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12837 | /* |
| 12838 | * Handle calculation of various watermark data at the end of the atomic check |
| 12839 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12840 | * handlers to ensure that all derived state has been updated. |
| 12841 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12842 | static int calc_watermark_data(struct intel_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12843 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12844 | struct drm_device *dev = state->base.dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12845 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12846 | |
| 12847 | /* Is there platform-specific watermark information to calculate? */ |
| 12848 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12849 | return dev_priv->display.compute_global_watermarks(state); |
| 12850 | |
| 12851 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12852 | } |
| 12853 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12854 | /** |
| 12855 | * intel_atomic_check - validate state object |
| 12856 | * @dev: drm device |
| 12857 | * @state: state to validate |
| 12858 | */ |
| 12859 | static int intel_atomic_check(struct drm_device *dev, |
| 12860 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12861 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12862 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12863 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12864 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12865 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12866 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12867 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12868 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12869 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12870 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12871 | crtc_state, i) { |
| 12872 | if (crtc_state->mode.private_flags != |
| 12873 | old_crtc_state->mode.private_flags) |
| 12874 | crtc_state->mode_changed = true; |
| 12875 | } |
| 12876 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12877 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12878 | if (ret) |
| 12879 | return ret; |
| 12880 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12881 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12882 | struct intel_crtc_state *pipe_config = |
| 12883 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12884 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12885 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12886 | continue; |
| 12887 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12888 | if (!crtc_state->enable) { |
| 12889 | any_ms = true; |
| 12890 | continue; |
| 12891 | } |
| 12892 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12893 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 12894 | if (ret == -EDEADLK) |
| 12895 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12896 | if (ret) { |
| 12897 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12898 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12899 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12900 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12901 | |
Maarten Lankhorst | d19f958 | 2019-01-08 17:08:40 +0100 | [diff] [blame] | 12902 | if (intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12903 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12904 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12905 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12906 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12907 | } |
| 12908 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12909 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12910 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12911 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12912 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12913 | needs_modeset(crtc_state) ? |
| 12914 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12915 | } |
| 12916 | |
Lyude Paul | eceae14 | 2019-01-10 19:53:41 -0500 | [diff] [blame] | 12917 | ret = drm_dp_mst_atomic_check(state); |
| 12918 | if (ret) |
| 12919 | return ret; |
| 12920 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12921 | if (any_ms) { |
| 12922 | ret = intel_modeset_checks(state); |
| 12923 | |
| 12924 | if (ret) |
| 12925 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12926 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12927 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12928 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12929 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 12930 | ret = icl_add_linked_planes(intel_state); |
| 12931 | if (ret) |
| 12932 | return ret; |
| 12933 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12934 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12935 | if (ret) |
| 12936 | return ret; |
| 12937 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12938 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12939 | return calc_watermark_data(intel_state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12940 | } |
| 12941 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12942 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12943 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12944 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12945 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12946 | } |
| 12947 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12948 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12949 | { |
| 12950 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 12951 | struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)]; |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12952 | |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 12953 | if (!vblank->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 12954 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12955 | |
| 12956 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 12957 | } |
| 12958 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12959 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 12960 | struct drm_atomic_state *state, |
| 12961 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12962 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12963 | { |
| 12964 | struct drm_device *dev = crtc->dev; |
| 12965 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 12966 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12967 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 12968 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12969 | struct intel_plane_state *new_plane_state = |
| 12970 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 12971 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12972 | |
| 12973 | if (modeset) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12974 | update_scanline_offset(pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12975 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12976 | |
| 12977 | /* vblanks work again, re-enable pipe CRC. */ |
| 12978 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12979 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12980 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12981 | pipe_config); |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 12982 | |
| 12983 | if (pipe_config->update_pipe) |
| 12984 | intel_encoders_update_pipe(crtc, pipe_config, state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12985 | } |
| 12986 | |
Maarten Lankhorst | 50c42fc | 2018-12-20 16:17:19 +0100 | [diff] [blame] | 12987 | if (pipe_config->update_pipe && !pipe_config->enable_fbc) |
| 12988 | intel_fbc_disable(intel_crtc); |
| 12989 | else if (new_plane_state) |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12990 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12991 | |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12992 | intel_begin_crtc_commit(crtc, old_crtc_state); |
| 12993 | |
Ville Syrjälä | 5f2e511 | 2018-11-14 23:07:27 +0200 | [diff] [blame] | 12994 | if (INTEL_GEN(dev_priv) >= 9) |
| 12995 | skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
| 12996 | else |
| 12997 | i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12998 | |
| 12999 | intel_finish_crtc_commit(crtc, old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13000 | } |
| 13001 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13002 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13003 | { |
| 13004 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13005 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13006 | int i; |
| 13007 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13008 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 13009 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13010 | continue; |
| 13011 | |
| 13012 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13013 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13014 | } |
| 13015 | } |
| 13016 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13017 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13018 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 13019 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13020 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13021 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13022 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13023 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13024 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13025 | unsigned int updated = 0; |
| 13026 | bool progress; |
| 13027 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13028 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 13029 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 13030 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13031 | struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13032 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13033 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13034 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13035 | if (new_crtc_state->active) |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13036 | entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13037 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 13038 | /* If 2nd DBuf slice required, enable it here */ |
| 13039 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 13040 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 13041 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13042 | /* |
| 13043 | * Whenever the number of active pipes changes, we need to make sure we |
| 13044 | * update the pipes in the right order so that their ddb allocations |
| 13045 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 13046 | * cause pipe underruns and other bad stuff. |
| 13047 | */ |
| 13048 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13049 | progress = false; |
| 13050 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13051 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13052 | bool vbl_wait = false; |
| 13053 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13054 | |
| 13055 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 13056 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13057 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13058 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13059 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13060 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13061 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13062 | if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb, |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 13063 | entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13064 | INTEL_INFO(dev_priv)->num_pipes, i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13065 | continue; |
| 13066 | |
| 13067 | updated |= cmask; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13068 | entries[i] = cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13069 | |
| 13070 | /* |
| 13071 | * If this is an already active pipe, it's DDB changed, |
| 13072 | * and this isn't the last pipe that needs updating |
| 13073 | * then we need to wait for a vblank to pass for the |
| 13074 | * new ddb allocation to take effect. |
| 13075 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13076 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 13077 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13078 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13079 | intel_state->wm_results.dirty_pipes != updated) |
| 13080 | vbl_wait = true; |
| 13081 | |
| 13082 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13083 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13084 | |
| 13085 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 13086 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13087 | |
| 13088 | progress = true; |
| 13089 | } |
| 13090 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 13091 | |
| 13092 | /* If 2nd DBuf slice is no more required disable it */ |
| 13093 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 13094 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13095 | } |
| 13096 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 13097 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 13098 | { |
| 13099 | struct intel_atomic_state *state, *next; |
| 13100 | struct llist_node *freed; |
| 13101 | |
| 13102 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 13103 | llist_for_each_entry_safe(state, next, freed, freed) |
| 13104 | drm_atomic_state_put(&state->base); |
| 13105 | } |
| 13106 | |
| 13107 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 13108 | { |
| 13109 | struct drm_i915_private *dev_priv = |
| 13110 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 13111 | |
| 13112 | intel_atomic_helper_free_state(dev_priv); |
| 13113 | } |
| 13114 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 13115 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 13116 | { |
| 13117 | struct wait_queue_entry wait_fence, wait_reset; |
| 13118 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 13119 | |
| 13120 | init_wait_entry(&wait_fence, 0); |
| 13121 | init_wait_entry(&wait_reset, 0); |
| 13122 | for (;;) { |
| 13123 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 13124 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 13125 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 13126 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 13127 | |
| 13128 | |
| 13129 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 13130 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 13131 | break; |
| 13132 | |
| 13133 | schedule(); |
| 13134 | } |
| 13135 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 13136 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 13137 | } |
| 13138 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 13139 | static void intel_atomic_cleanup_work(struct work_struct *work) |
| 13140 | { |
| 13141 | struct drm_atomic_state *state = |
| 13142 | container_of(work, struct drm_atomic_state, commit_work); |
| 13143 | struct drm_i915_private *i915 = to_i915(state->dev); |
| 13144 | |
| 13145 | drm_atomic_helper_cleanup_planes(&i915->drm, state); |
| 13146 | drm_atomic_helper_commit_cleanup_done(state); |
| 13147 | drm_atomic_state_put(state); |
| 13148 | |
| 13149 | intel_atomic_helper_free_state(i915); |
| 13150 | } |
| 13151 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13152 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13153 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13154 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13155 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13156 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13157 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13158 | struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13159 | struct drm_crtc *crtc; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13160 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 13161 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13162 | intel_wakeref_t wakeref = 0; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 13163 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13164 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 13165 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13166 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 13167 | drm_atomic_helper_wait_for_dependencies(state); |
| 13168 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13169 | if (intel_state->modeset) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13170 | wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13171 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13172 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13173 | old_intel_crtc_state = to_intel_crtc_state(old_crtc_state); |
| 13174 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 13175 | intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13176 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13177 | if (needs_modeset(new_crtc_state) || |
| 13178 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13179 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13180 | put_domains[intel_crtc->pipe] = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13181 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13182 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13183 | } |
| 13184 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13185 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13186 | continue; |
| 13187 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13188 | intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13189 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13190 | if (old_crtc_state->active) { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 13191 | intel_crtc_disable_planes(intel_state, intel_crtc); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 13192 | |
| 13193 | /* |
| 13194 | * We need to disable pipe CRC before disabling the pipe, |
| 13195 | * or we race against vblank off. |
| 13196 | */ |
| 13197 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 13198 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13199 | dev_priv->display.crtc_disable(old_intel_crtc_state, state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13200 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 13201 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 13202 | intel_disable_shared_dpll(old_intel_crtc_state); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 13203 | |
| 13204 | /* |
| 13205 | * Underruns don't always raise |
| 13206 | * interrupts, so check manually. |
| 13207 | */ |
| 13208 | intel_check_cpu_fifo_underruns(dev_priv); |
| 13209 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13210 | |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 13211 | /* FIXME unify this for all platforms */ |
| 13212 | if (!new_crtc_state->active && |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 13213 | !HAS_GMCH(dev_priv) && |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 13214 | dev_priv->display.initial_watermarks) |
| 13215 | dev_priv->display.initial_watermarks(intel_state, |
| 13216 | new_intel_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13217 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13218 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13219 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 13220 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 13221 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 13222 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13223 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13224 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13225 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13226 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 13227 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 13228 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13229 | /* |
| 13230 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 13231 | * have more then one pipe enabled |
| 13232 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13233 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13234 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13235 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13236 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13237 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13238 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13239 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13240 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 13241 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13242 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13243 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13244 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13245 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13246 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13247 | spin_unlock_irq(&dev->event_lock); |
| 13248 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13249 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13250 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13251 | } |
| 13252 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13253 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13254 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13255 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13256 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 13257 | * already, but still need the state for the delayed optimization. To |
| 13258 | * fix this: |
| 13259 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 13260 | * - schedule that vblank worker _before_ calling hw_done |
| 13261 | * - at the start of commit_tail, cancel it _synchrously |
| 13262 | * - switch over to the vblank wait helper in the core after that since |
| 13263 | * we don't need out special handling any more. |
| 13264 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13265 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13266 | |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 13267 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 13268 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 13269 | |
| 13270 | if (new_crtc_state->active && |
| 13271 | !needs_modeset(new_crtc_state) && |
| 13272 | (new_intel_crtc_state->base.color_mgmt_changed || |
| 13273 | new_intel_crtc_state->update_pipe)) |
| 13274 | intel_color_load_luts(new_intel_crtc_state); |
| 13275 | } |
| 13276 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13277 | /* |
| 13278 | * Now that the vblank has passed, we can go ahead and program the |
| 13279 | * optimal watermarks on platforms that need two-step watermark |
| 13280 | * programming. |
| 13281 | * |
| 13282 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13283 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13284 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13285 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13286 | |
| 13287 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13288 | dev_priv->display.optimize_watermarks(intel_state, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13289 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13290 | } |
| 13291 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13292 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13293 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13294 | |
| 13295 | if (put_domains[i]) |
| 13296 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13297 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13298 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13299 | } |
| 13300 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 13301 | if (intel_state->modeset) |
| 13302 | intel_verify_planes(intel_state); |
| 13303 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13304 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13305 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13306 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13307 | drm_atomic_helper_commit_hw_done(state); |
| 13308 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13309 | if (intel_state->modeset) { |
| 13310 | /* As one of the primary mmio accessors, KMS has a high |
| 13311 | * likelihood of triggering bugs in unclaimed access. After we |
| 13312 | * finish modesetting, see if an error has been flagged, and if |
| 13313 | * so enable debugging for the next modeset - and hope we catch |
| 13314 | * the culprit. |
| 13315 | */ |
| 13316 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13317 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13318 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13319 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 13320 | /* |
| 13321 | * Defer the cleanup of the old state to a separate worker to not |
| 13322 | * impede the current task (userspace for blocking modesets) that |
| 13323 | * are executed inline. For out-of-line asynchronous modesets/flips, |
| 13324 | * deferring to a new worker seems overkill, but we would place a |
| 13325 | * schedule point (cond_resched()) here anyway to keep latencies |
| 13326 | * down. |
| 13327 | */ |
| 13328 | INIT_WORK(&state->commit_work, intel_atomic_cleanup_work); |
Chris Wilson | 41db645 | 2018-07-12 12:57:29 +0100 | [diff] [blame] | 13329 | queue_work(system_highpri_wq, &state->commit_work); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13330 | } |
| 13331 | |
| 13332 | static void intel_atomic_commit_work(struct work_struct *work) |
| 13333 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13334 | struct drm_atomic_state *state = |
| 13335 | container_of(work, struct drm_atomic_state, commit_work); |
| 13336 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13337 | intel_atomic_commit_tail(state); |
| 13338 | } |
| 13339 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13340 | static int __i915_sw_fence_call |
| 13341 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 13342 | enum i915_sw_fence_notify notify) |
| 13343 | { |
| 13344 | struct intel_atomic_state *state = |
| 13345 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 13346 | |
| 13347 | switch (notify) { |
| 13348 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13349 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13350 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13351 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 13352 | { |
| 13353 | struct intel_atomic_helper *helper = |
| 13354 | &to_i915(state->base.dev)->atomic_helper; |
| 13355 | |
| 13356 | if (llist_add(&state->freed, &helper->free_list)) |
| 13357 | schedule_work(&helper->free_work); |
| 13358 | break; |
| 13359 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13360 | } |
| 13361 | |
| 13362 | return NOTIFY_DONE; |
| 13363 | } |
| 13364 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13365 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 13366 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13367 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13368 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13369 | int i; |
| 13370 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13371 | for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 13372 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13373 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 13374 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13375 | } |
| 13376 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13377 | /** |
| 13378 | * intel_atomic_commit - commit validated state object |
| 13379 | * @dev: DRM device |
| 13380 | * @state: the top-level driver state object |
| 13381 | * @nonblock: nonblocking commit |
| 13382 | * |
| 13383 | * This function commits a top-level state object that has been validated |
| 13384 | * with drm_atomic_helper_check(). |
| 13385 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13386 | * RETURNS |
| 13387 | * Zero for success or -errno. |
| 13388 | */ |
| 13389 | static int intel_atomic_commit(struct drm_device *dev, |
| 13390 | struct drm_atomic_state *state, |
| 13391 | bool nonblock) |
| 13392 | { |
| 13393 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13394 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13395 | int ret = 0; |
| 13396 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13397 | drm_atomic_state_get(state); |
| 13398 | i915_sw_fence_init(&intel_state->commit_ready, |
| 13399 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13400 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13401 | /* |
| 13402 | * The intel_legacy_cursor_update() fast path takes care |
| 13403 | * of avoiding the vblank waits for simple cursor |
| 13404 | * movement and flips. For cursor on/off and size changes, |
| 13405 | * we want to perform the vblank waits so that watermark |
| 13406 | * updates happen during the correct frames. Gen9+ have |
| 13407 | * double buffered watermarks and so shouldn't need this. |
| 13408 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13409 | * Unset state->legacy_cursor_update before the call to |
| 13410 | * drm_atomic_helper_setup_commit() because otherwise |
| 13411 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 13412 | * we get FIFO underruns because we didn't wait |
| 13413 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13414 | * |
| 13415 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 13416 | * (assuming we had any) would solve these problems. |
| 13417 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 13418 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 13419 | struct intel_crtc_state *new_crtc_state; |
| 13420 | struct intel_crtc *crtc; |
| 13421 | int i; |
| 13422 | |
| 13423 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 13424 | if (new_crtc_state->wm.need_postvbl_update || |
| 13425 | new_crtc_state->update_wm_post) |
| 13426 | state->legacy_cursor_update = false; |
| 13427 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13428 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13429 | ret = intel_atomic_prepare_commit(dev, state); |
| 13430 | if (ret) { |
| 13431 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 13432 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13433 | return ret; |
| 13434 | } |
| 13435 | |
| 13436 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 13437 | if (!ret) |
| 13438 | ret = drm_atomic_helper_swap_state(state, true); |
| 13439 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13440 | if (ret) { |
| 13441 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13442 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13443 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13444 | return ret; |
| 13445 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13446 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 13447 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13448 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13449 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13450 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 13451 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 13452 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 13453 | memcpy(dev_priv->min_voltage_level, |
| 13454 | intel_state->min_voltage_level, |
| 13455 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13456 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 13457 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 13458 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13459 | } |
| 13460 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 13461 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13462 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13463 | |
| 13464 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13465 | if (nonblock && intel_state->modeset) { |
| 13466 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 13467 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13468 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13469 | } else { |
| 13470 | if (intel_state->modeset) |
| 13471 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13472 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13473 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13474 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13475 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13476 | } |
| 13477 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13478 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 13479 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13480 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13481 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 13482 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13483 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13484 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 13485 | .set_crc_source = intel_crtc_set_crc_source, |
Mahesh Kumar | a8c2083 | 2018-07-13 19:29:38 +0530 | [diff] [blame] | 13486 | .verify_crc_source = intel_crtc_verify_crc_source, |
Mahesh Kumar | 260bc55 | 2018-07-13 19:29:39 +0530 | [diff] [blame] | 13487 | .get_crc_sources = intel_crtc_get_crc_sources, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13488 | }; |
| 13489 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13490 | struct wait_rps_boost { |
| 13491 | struct wait_queue_entry wait; |
| 13492 | |
| 13493 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13494 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13495 | }; |
| 13496 | |
| 13497 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 13498 | unsigned mode, int sync, void *key) |
| 13499 | { |
| 13500 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13501 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13502 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13503 | /* |
| 13504 | * If we missed the vblank, but the request is already running it |
| 13505 | * is reasonable to assume that it will complete before the next |
| 13506 | * vblank without our intervention, so leave RPS alone. |
| 13507 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13508 | if (!i915_request_started(rq)) |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13509 | gen6_rps_boost(rq, NULL); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13510 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13511 | |
| 13512 | drm_crtc_vblank_put(wait->crtc); |
| 13513 | |
| 13514 | list_del(&wait->wait.entry); |
| 13515 | kfree(wait); |
| 13516 | return 1; |
| 13517 | } |
| 13518 | |
| 13519 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 13520 | struct dma_fence *fence) |
| 13521 | { |
| 13522 | struct wait_rps_boost *wait; |
| 13523 | |
| 13524 | if (!dma_fence_is_i915(fence)) |
| 13525 | return; |
| 13526 | |
| 13527 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 13528 | return; |
| 13529 | |
| 13530 | if (drm_crtc_vblank_get(crtc)) |
| 13531 | return; |
| 13532 | |
| 13533 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 13534 | if (!wait) { |
| 13535 | drm_crtc_vblank_put(crtc); |
| 13536 | return; |
| 13537 | } |
| 13538 | |
| 13539 | wait->request = to_request(dma_fence_get(fence)); |
| 13540 | wait->crtc = crtc; |
| 13541 | |
| 13542 | wait->wait.func = do_rps_boost; |
| 13543 | wait->wait.flags = 0; |
| 13544 | |
| 13545 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 13546 | } |
| 13547 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13548 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 13549 | { |
| 13550 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 13551 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 13552 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 13553 | struct i915_vma *vma; |
| 13554 | |
| 13555 | if (plane->id == PLANE_CURSOR && |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 13556 | INTEL_INFO(dev_priv)->display.cursor_needs_physical) { |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13557 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13558 | const int align = intel_cursor_alignment(dev_priv); |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13559 | int err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13560 | |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13561 | err = i915_gem_object_attach_phys(obj, align); |
| 13562 | if (err) |
| 13563 | return err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13564 | } |
| 13565 | |
| 13566 | vma = intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 13567 | &plane_state->view, |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13568 | intel_plane_uses_fence(plane_state), |
| 13569 | &plane_state->flags); |
| 13570 | if (IS_ERR(vma)) |
| 13571 | return PTR_ERR(vma); |
| 13572 | |
| 13573 | plane_state->vma = vma; |
| 13574 | |
| 13575 | return 0; |
| 13576 | } |
| 13577 | |
| 13578 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 13579 | { |
| 13580 | struct i915_vma *vma; |
| 13581 | |
| 13582 | vma = fetch_and_zero(&old_plane_state->vma); |
| 13583 | if (vma) |
| 13584 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 13585 | } |
| 13586 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 13587 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 13588 | { |
| 13589 | struct i915_sched_attr attr = { |
| 13590 | .priority = I915_PRIORITY_DISPLAY, |
| 13591 | }; |
| 13592 | |
| 13593 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 13594 | } |
| 13595 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13596 | /** |
| 13597 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13598 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13599 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13600 | * |
| 13601 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13602 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13603 | * bits. Some older platforms need special physical address handling for |
| 13604 | * cursor planes. |
| 13605 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13606 | * Must be called with struct_mutex held. |
| 13607 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13608 | * Returns 0 on success, negative error code on failure. |
| 13609 | */ |
| 13610 | int |
| 13611 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13612 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13613 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13614 | struct intel_atomic_state *intel_state = |
| 13615 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 13616 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13617 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13618 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13619 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13620 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13621 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13622 | if (old_obj) { |
| 13623 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13624 | drm_atomic_get_new_crtc_state(new_state->state, |
| 13625 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13626 | |
| 13627 | /* Big Hammer, we also need to ensure that any pending |
| 13628 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13629 | * current scanout is retired before unpinning the old |
| 13630 | * framebuffer. Note that we rely on userspace rendering |
| 13631 | * into the buffer attached to the pipe they are waiting |
| 13632 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13633 | * point to the MI_WAIT_FOR_EVENT. |
| 13634 | * |
| 13635 | * This should only fail upon a hung GPU, in which case we |
| 13636 | * can safely continue. |
| 13637 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13638 | if (needs_modeset(crtc_state)) { |
| 13639 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13640 | old_obj->resv, NULL, |
| 13641 | false, 0, |
| 13642 | GFP_KERNEL); |
| 13643 | if (ret < 0) |
| 13644 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13645 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13646 | } |
| 13647 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13648 | if (new_state->fence) { /* explicit fencing */ |
| 13649 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 13650 | new_state->fence, |
| 13651 | I915_FENCE_TIMEOUT, |
| 13652 | GFP_KERNEL); |
| 13653 | if (ret < 0) |
| 13654 | return ret; |
| 13655 | } |
| 13656 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 13657 | if (!obj) |
| 13658 | return 0; |
| 13659 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13660 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13661 | if (ret) |
| 13662 | return ret; |
| 13663 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13664 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13665 | if (ret) { |
| 13666 | i915_gem_object_unpin_pages(obj); |
| 13667 | return ret; |
| 13668 | } |
| 13669 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13670 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13671 | |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13672 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13673 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13674 | if (ret) |
| 13675 | return ret; |
| 13676 | |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 13677 | fb_obj_bump_render_priority(obj); |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13678 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 13679 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13680 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13681 | struct dma_fence *fence; |
| 13682 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13683 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13684 | obj->resv, NULL, |
| 13685 | false, I915_FENCE_TIMEOUT, |
| 13686 | GFP_KERNEL); |
| 13687 | if (ret < 0) |
| 13688 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13689 | |
| 13690 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 13691 | if (fence) { |
| 13692 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 13693 | dma_fence_put(fence); |
| 13694 | } |
| 13695 | } else { |
| 13696 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13697 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13698 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13699 | /* |
| 13700 | * We declare pageflips to be interactive and so merit a small bias |
| 13701 | * towards upclocking to deliver the frame on time. By only changing |
| 13702 | * the RPS thresholds to sample more regularly and aim for higher |
| 13703 | * clocks we can hopefully deliver low power workloads (like kodi) |
| 13704 | * that are not quite steady state without resorting to forcing |
| 13705 | * maximum clocks following a vblank miss (see do_rps_boost()). |
| 13706 | */ |
| 13707 | if (!intel_state->rps_interactive) { |
| 13708 | intel_rps_mark_interactive(dev_priv, true); |
| 13709 | intel_state->rps_interactive = true; |
| 13710 | } |
| 13711 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 13712 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13713 | } |
| 13714 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13715 | /** |
| 13716 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13717 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13718 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13719 | * |
| 13720 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13721 | * |
| 13722 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13723 | */ |
| 13724 | void |
| 13725 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13726 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13727 | { |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13728 | struct intel_atomic_state *intel_state = |
| 13729 | to_intel_atomic_state(old_state->state); |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13730 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13731 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13732 | if (intel_state->rps_interactive) { |
| 13733 | intel_rps_mark_interactive(dev_priv, false); |
| 13734 | intel_state->rps_interactive = false; |
| 13735 | } |
| 13736 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 13737 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13738 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 13739 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 13740 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13741 | } |
| 13742 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13743 | int |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13744 | skl_max_scale(const struct intel_crtc_state *crtc_state, |
| 13745 | u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13746 | { |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13747 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 13748 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13749 | int max_scale, mult; |
| 13750 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13751 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13752 | if (!crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13753 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13754 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13755 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 13756 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 13757 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 13758 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13759 | max_dotclk *= 2; |
| 13760 | |
| 13761 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13762 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13763 | |
| 13764 | /* |
| 13765 | * skl max scale is lower of: |
| 13766 | * close to 3 but not 3, -1 is for that purpose |
| 13767 | * or |
| 13768 | * cdclk/crtc_clock |
| 13769 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13770 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 13771 | tmpclk1 = (1 << 16) * mult - 1; |
| 13772 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 13773 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13774 | |
| 13775 | return max_scale; |
| 13776 | } |
| 13777 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13778 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13779 | struct drm_crtc_state *old_crtc_state) |
| 13780 | { |
| 13781 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13782 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13783 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13784 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13785 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13786 | struct intel_atomic_state *old_intel_state = |
| 13787 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13788 | struct intel_crtc_state *intel_cstate = |
| 13789 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13790 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13791 | |
| 13792 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13793 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13794 | |
| 13795 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13796 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13797 | |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 13798 | if (intel_cstate->base.color_mgmt_changed || |
| 13799 | intel_cstate->update_pipe) |
| 13800 | intel_color_commit(intel_cstate); |
| 13801 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13802 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13803 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13804 | else if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 13805 | skl_detach_scalers(intel_cstate); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13806 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13807 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13808 | if (dev_priv->display.atomic_update_watermarks) |
| 13809 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13810 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13811 | } |
| 13812 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13813 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13814 | struct intel_crtc_state *crtc_state) |
| 13815 | { |
| 13816 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13817 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 13818 | if (!IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13819 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13820 | |
| 13821 | if (crtc_state->has_pch_encoder) { |
| 13822 | enum pipe pch_transcoder = |
| 13823 | intel_crtc_pch_transcoder(crtc); |
| 13824 | |
| 13825 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13826 | } |
| 13827 | } |
| 13828 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13829 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13830 | struct drm_crtc_state *old_crtc_state) |
| 13831 | { |
| 13832 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13833 | struct intel_atomic_state *old_intel_state = |
| 13834 | to_intel_atomic_state(old_crtc_state->state); |
| 13835 | struct intel_crtc_state *new_crtc_state = |
| 13836 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13837 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13838 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13839 | |
| 13840 | if (new_crtc_state->update_pipe && |
| 13841 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13842 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13843 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13844 | } |
| 13845 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13846 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13847 | * intel_plane_destroy - destroy a plane |
| 13848 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13849 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13850 | * Common destruction function for all types of planes (primary, cursor, |
| 13851 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13852 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13853 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13854 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13855 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13856 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13857 | } |
| 13858 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13859 | static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane, |
| 13860 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13861 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13862 | switch (modifier) { |
| 13863 | case DRM_FORMAT_MOD_LINEAR: |
| 13864 | case I915_FORMAT_MOD_X_TILED: |
| 13865 | break; |
| 13866 | default: |
| 13867 | return false; |
| 13868 | } |
| 13869 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13870 | switch (format) { |
| 13871 | case DRM_FORMAT_C8: |
| 13872 | case DRM_FORMAT_RGB565: |
| 13873 | case DRM_FORMAT_XRGB1555: |
| 13874 | case DRM_FORMAT_XRGB8888: |
| 13875 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13876 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13877 | default: |
| 13878 | return false; |
| 13879 | } |
| 13880 | } |
| 13881 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13882 | static bool i965_plane_format_mod_supported(struct drm_plane *_plane, |
| 13883 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13884 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13885 | switch (modifier) { |
| 13886 | case DRM_FORMAT_MOD_LINEAR: |
| 13887 | case I915_FORMAT_MOD_X_TILED: |
| 13888 | break; |
| 13889 | default: |
| 13890 | return false; |
| 13891 | } |
| 13892 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13893 | switch (format) { |
| 13894 | case DRM_FORMAT_C8: |
| 13895 | case DRM_FORMAT_RGB565: |
| 13896 | case DRM_FORMAT_XRGB8888: |
| 13897 | case DRM_FORMAT_XBGR8888: |
| 13898 | case DRM_FORMAT_XRGB2101010: |
| 13899 | case DRM_FORMAT_XBGR2101010: |
| 13900 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13901 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13902 | default: |
| 13903 | return false; |
| 13904 | } |
| 13905 | } |
| 13906 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13907 | static bool intel_cursor_format_mod_supported(struct drm_plane *_plane, |
| 13908 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13909 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13910 | return modifier == DRM_FORMAT_MOD_LINEAR && |
| 13911 | format == DRM_FORMAT_ARGB8888; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13912 | } |
| 13913 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13914 | static const struct drm_plane_funcs i965_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13915 | .update_plane = drm_atomic_helper_update_plane, |
| 13916 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13917 | .destroy = intel_plane_destroy, |
| 13918 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13919 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13920 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13921 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13922 | .format_mod_supported = i965_plane_format_mod_supported, |
| 13923 | }; |
| 13924 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13925 | static const struct drm_plane_funcs i8xx_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13926 | .update_plane = drm_atomic_helper_update_plane, |
| 13927 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13928 | .destroy = intel_plane_destroy, |
| 13929 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13930 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13931 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13932 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13933 | .format_mod_supported = i8xx_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13934 | }; |
| 13935 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13936 | static int |
| 13937 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13938 | struct drm_crtc *crtc, |
| 13939 | struct drm_framebuffer *fb, |
| 13940 | int crtc_x, int crtc_y, |
| 13941 | unsigned int crtc_w, unsigned int crtc_h, |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 13942 | u32 src_x, u32 src_y, |
| 13943 | u32 src_w, u32 src_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13944 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13945 | { |
| 13946 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13947 | int ret; |
| 13948 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13949 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13950 | struct drm_framebuffer *old_fb; |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13951 | struct intel_crtc_state *crtc_state = |
| 13952 | to_intel_crtc_state(crtc->state); |
| 13953 | struct intel_crtc_state *new_crtc_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13954 | |
| 13955 | /* |
| 13956 | * When crtc is inactive or there is a modeset pending, |
| 13957 | * wait for it to complete in the slowpath |
| 13958 | */ |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13959 | if (!crtc_state->base.active || needs_modeset(&crtc_state->base) || |
| 13960 | crtc_state->update_pipe) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13961 | goto slow; |
| 13962 | |
| 13963 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13964 | /* |
| 13965 | * Don't do an async update if there is an outstanding commit modifying |
| 13966 | * the plane. This prevents our async update's changes from getting |
| 13967 | * overridden by a previous synchronous update's state. |
| 13968 | */ |
| 13969 | if (old_plane_state->commit && |
| 13970 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 13971 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13972 | |
| 13973 | /* |
| 13974 | * If any parameters change that may affect watermarks, |
| 13975 | * take the slowpath. Only changing fb or position should be |
| 13976 | * in the fastpath. |
| 13977 | */ |
| 13978 | if (old_plane_state->crtc != crtc || |
| 13979 | old_plane_state->src_w != src_w || |
| 13980 | old_plane_state->src_h != src_h || |
| 13981 | old_plane_state->crtc_w != crtc_w || |
| 13982 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13983 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13984 | goto slow; |
| 13985 | |
| 13986 | new_plane_state = intel_plane_duplicate_state(plane); |
| 13987 | if (!new_plane_state) |
| 13988 | return -ENOMEM; |
| 13989 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13990 | new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc)); |
| 13991 | if (!new_crtc_state) { |
| 13992 | ret = -ENOMEM; |
| 13993 | goto out_free; |
| 13994 | } |
| 13995 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13996 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 13997 | |
| 13998 | new_plane_state->src_x = src_x; |
| 13999 | new_plane_state->src_y = src_y; |
| 14000 | new_plane_state->src_w = src_w; |
| 14001 | new_plane_state->src_h = src_h; |
| 14002 | new_plane_state->crtc_x = crtc_x; |
| 14003 | new_plane_state->crtc_y = crtc_y; |
| 14004 | new_plane_state->crtc_w = crtc_w; |
| 14005 | new_plane_state->crtc_h = crtc_h; |
| 14006 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14007 | ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state, |
| 14008 | to_intel_plane_state(old_plane_state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14009 | to_intel_plane_state(new_plane_state)); |
| 14010 | if (ret) |
| 14011 | goto out_free; |
| 14012 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14013 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 14014 | if (ret) |
| 14015 | goto out_free; |
| 14016 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 14017 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 14018 | if (ret) |
| 14019 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14020 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 14021 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14022 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 14023 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14024 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 14025 | intel_plane->frontbuffer_bit); |
| 14026 | |
| 14027 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 14028 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14029 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14030 | /* |
| 14031 | * We cannot swap crtc_state as it may be in use by an atomic commit or |
| 14032 | * page flip that's running simultaneously. If we swap crtc_state and |
| 14033 | * destroy the old state, we will cause a use-after-free there. |
| 14034 | * |
| 14035 | * Only update active_planes, which is needed for our internal |
| 14036 | * bookkeeping. Either value will do the right thing when updating |
| 14037 | * planes atomically. If the cursor was part of the atomic update then |
| 14038 | * we would have taken the slowpath. |
| 14039 | */ |
| 14040 | crtc_state->active_planes = new_crtc_state->active_planes; |
| 14041 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 14042 | if (plane->state->visible) { |
| 14043 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14044 | intel_plane->update_plane(intel_plane, crtc_state, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 14045 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 14046 | } else { |
| 14047 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 14048 | intel_plane->disable_plane(intel_plane, crtc_state); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 14049 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14050 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 14051 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14052 | |
| 14053 | out_unlock: |
| 14054 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 14055 | out_free: |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14056 | if (new_crtc_state) |
| 14057 | intel_crtc_destroy_state(crtc, &new_crtc_state->base); |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 14058 | if (ret) |
| 14059 | intel_plane_destroy_state(plane, new_plane_state); |
| 14060 | else |
| 14061 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14062 | return ret; |
| 14063 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14064 | slow: |
| 14065 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 14066 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 14067 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14068 | } |
| 14069 | |
| 14070 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 14071 | .update_plane = intel_legacy_cursor_update, |
| 14072 | .disable_plane = drm_atomic_helper_disable_plane, |
| 14073 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14074 | .atomic_get_property = intel_plane_atomic_get_property, |
| 14075 | .atomic_set_property = intel_plane_atomic_set_property, |
| 14076 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 14077 | .atomic_destroy_state = intel_plane_destroy_state, |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14078 | .format_mod_supported = intel_cursor_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14079 | }; |
| 14080 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14081 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 14082 | enum i9xx_plane_id i9xx_plane) |
| 14083 | { |
| 14084 | if (!HAS_FBC(dev_priv)) |
| 14085 | return false; |
| 14086 | |
| 14087 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 14088 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 14089 | else if (IS_IVYBRIDGE(dev_priv)) |
| 14090 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 14091 | i9xx_plane == PLANE_C; |
| 14092 | else if (INTEL_GEN(dev_priv) >= 4) |
| 14093 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 14094 | else |
| 14095 | return i9xx_plane == PLANE_A; |
| 14096 | } |
| 14097 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14098 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14099 | intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14100 | { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14101 | struct intel_plane *plane; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14102 | const struct drm_plane_funcs *plane_funcs; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14103 | unsigned int supported_rotations; |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14104 | unsigned int possible_crtcs; |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14105 | const u64 *modifiers; |
| 14106 | const u32 *formats; |
| 14107 | int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14108 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14109 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14110 | if (INTEL_GEN(dev_priv) >= 9) |
| 14111 | return skl_universal_plane_create(dev_priv, pipe, |
| 14112 | PLANE_PRIMARY); |
| 14113 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14114 | plane = intel_plane_alloc(); |
| 14115 | if (IS_ERR(plane)) |
| 14116 | return plane; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14117 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14118 | plane->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 14119 | /* |
| 14120 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 14121 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 14122 | */ |
| 14123 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14124 | plane->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 14125 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14126 | plane->i9xx_plane = (enum i9xx_plane_id) pipe; |
| 14127 | plane->id = PLANE_PRIMARY; |
| 14128 | plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14129 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14130 | plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane); |
| 14131 | if (plane->has_fbc) { |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14132 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 14133 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14134 | fbc->possible_framebuffer_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14135 | } |
| 14136 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14137 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14138 | formats = i965_primary_formats; |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 14139 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14140 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14141 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14142 | plane->max_stride = i9xx_plane_max_stride; |
| 14143 | plane->update_plane = i9xx_update_plane; |
| 14144 | plane->disable_plane = i9xx_disable_plane; |
| 14145 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 14146 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14147 | |
| 14148 | plane_funcs = &i965_plane_funcs; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14149 | } else { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14150 | formats = i8xx_primary_formats; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14151 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14152 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14153 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14154 | plane->max_stride = i9xx_plane_max_stride; |
| 14155 | plane->update_plane = i9xx_update_plane; |
| 14156 | plane->disable_plane = i9xx_disable_plane; |
| 14157 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 14158 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14159 | |
| 14160 | plane_funcs = &i8xx_plane_funcs; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14161 | } |
| 14162 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14163 | possible_crtcs = BIT(pipe); |
| 14164 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14165 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14166 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14167 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14168 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14169 | DRM_PLANE_TYPE_PRIMARY, |
| 14170 | "primary %c", pipe_name(pipe)); |
| 14171 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14172 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14173 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14174 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14175 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 14176 | "plane %c", |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14177 | plane_name(plane->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14178 | if (ret) |
| 14179 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14180 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14181 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 14182 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14183 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 14184 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14185 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14186 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14187 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14188 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14189 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14190 | } |
| 14191 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14192 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14193 | drm_plane_create_rotation_property(&plane->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14194 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14195 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14196 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14197 | drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14198 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14199 | return plane; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14200 | |
| 14201 | fail: |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14202 | intel_plane_free(plane); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14203 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14204 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14205 | } |
| 14206 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14207 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14208 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 14209 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14210 | { |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14211 | unsigned int possible_crtcs; |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14212 | struct intel_plane *cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14213 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14214 | |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14215 | cursor = intel_plane_alloc(); |
| 14216 | if (IS_ERR(cursor)) |
| 14217 | return cursor; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14218 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14219 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 14220 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 14221 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 14222 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14223 | |
| 14224 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14225 | cursor->max_stride = i845_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14226 | cursor->update_plane = i845_update_cursor; |
| 14227 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14228 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14229 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14230 | } else { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14231 | cursor->max_stride = i9xx_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14232 | cursor->update_plane = i9xx_update_cursor; |
| 14233 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14234 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14235 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14236 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14237 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 14238 | cursor->cursor.base = ~0; |
| 14239 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 14240 | |
| 14241 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 14242 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14243 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14244 | possible_crtcs = BIT(pipe); |
| 14245 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14246 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14247 | possible_crtcs, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14248 | intel_cursor_formats, |
| 14249 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14250 | cursor_format_modifiers, |
| 14251 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14252 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14253 | if (ret) |
| 14254 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14255 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14256 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14257 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14258 | DRM_MODE_ROTATE_0, |
| 14259 | DRM_MODE_ROTATE_0 | |
| 14260 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14261 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14262 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14263 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14264 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14265 | |
| 14266 | fail: |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14267 | intel_plane_free(cursor); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14268 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14269 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14270 | } |
| 14271 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14272 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 14273 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14274 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14275 | struct intel_crtc_scaler_state *scaler_state = |
| 14276 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14277 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14278 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14279 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 14280 | crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe]; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14281 | if (!crtc->num_scalers) |
| 14282 | return; |
| 14283 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14284 | for (i = 0; i < crtc->num_scalers; i++) { |
| 14285 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 14286 | |
| 14287 | scaler->in_use = 0; |
Maarten Lankhorst | 0aaf29b | 2018-09-21 16:44:37 +0200 | [diff] [blame] | 14288 | scaler->mode = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14289 | } |
| 14290 | |
| 14291 | scaler_state->scaler_id = -1; |
| 14292 | } |
| 14293 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14294 | static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14295 | { |
| 14296 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14297 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14298 | struct intel_plane *primary = NULL; |
| 14299 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14300 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14301 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14302 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14303 | if (!intel_crtc) |
| 14304 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14305 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14306 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14307 | if (!crtc_state) { |
| 14308 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14309 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14310 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14311 | intel_crtc->config = crtc_state; |
| 14312 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14313 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14314 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14315 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14316 | if (IS_ERR(primary)) { |
| 14317 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14318 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14319 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14320 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14321 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14322 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14323 | struct intel_plane *plane; |
| 14324 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14325 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14326 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14327 | ret = PTR_ERR(plane); |
| 14328 | goto fail; |
| 14329 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14330 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14331 | } |
| 14332 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14333 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14334 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14335 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14336 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14337 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14338 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14339 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14340 | ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base, |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14341 | &primary->base, &cursor->base, |
| 14342 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 14343 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14344 | if (ret) |
| 14345 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14346 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14347 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14348 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14349 | /* initialize shared scalers */ |
| 14350 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 14351 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 14352 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 14353 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 14354 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 14355 | |
| 14356 | if (INTEL_GEN(dev_priv) < 9) { |
| 14357 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 14358 | |
| 14359 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14360 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 14361 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 14362 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14363 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14364 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14365 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 14366 | intel_color_init(intel_crtc); |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14367 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14368 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14369 | |
| 14370 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14371 | |
| 14372 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14373 | /* |
| 14374 | * drm_mode_config_cleanup() will free up any |
| 14375 | * crtcs/planes already initialized. |
| 14376 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14377 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14378 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14379 | |
| 14380 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14381 | } |
| 14382 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 14383 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 14384 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14385 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14386 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14387 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14388 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14389 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 14390 | drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id); |
Chris Wilson | 71240ed | 2016-06-24 14:00:24 +0100 | [diff] [blame] | 14391 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14392 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14393 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14394 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14395 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14396 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14397 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14398 | } |
| 14399 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14400 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14401 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14402 | struct drm_device *dev = encoder->base.dev; |
| 14403 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14404 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14405 | int entry = 0; |
| 14406 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14407 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14408 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14409 | index_mask |= (1 << entry); |
| 14410 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14411 | entry++; |
| 14412 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14413 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14414 | return index_mask; |
| 14415 | } |
| 14416 | |
Jani Nikula | a5916fd | 2019-01-22 10:23:05 +0200 | [diff] [blame] | 14417 | static bool ilk_has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14418 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14419 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14420 | return false; |
| 14421 | |
| 14422 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14423 | return false; |
| 14424 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14425 | if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14426 | return false; |
| 14427 | |
| 14428 | return true; |
| 14429 | } |
| 14430 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14431 | static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14432 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14433 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14434 | return false; |
| 14435 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 14436 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14437 | return false; |
| 14438 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14439 | if (HAS_PCH_LPT_H(dev_priv) && |
| 14440 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14441 | return false; |
| 14442 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14443 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14444 | if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14445 | return false; |
| 14446 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14447 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14448 | return false; |
| 14449 | |
| 14450 | return true; |
| 14451 | } |
| 14452 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14453 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 14454 | { |
| 14455 | int pps_num; |
| 14456 | int pps_idx; |
| 14457 | |
| 14458 | if (HAS_DDI(dev_priv)) |
| 14459 | return; |
| 14460 | /* |
| 14461 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 14462 | * everywhere where registers can be write protected. |
| 14463 | */ |
| 14464 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14465 | pps_num = 2; |
| 14466 | else |
| 14467 | pps_num = 1; |
| 14468 | |
| 14469 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 14470 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 14471 | |
| 14472 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 14473 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 14474 | } |
| 14475 | } |
| 14476 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14477 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 14478 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 14479 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14480 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 14481 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14482 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 14483 | else |
| 14484 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14485 | |
| 14486 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14487 | } |
| 14488 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14489 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14490 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14491 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14492 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14493 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14494 | intel_pps_init(dev_priv); |
| 14495 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 14496 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | fc0c5a9 | 2018-08-15 21:12:07 +0100 | [diff] [blame] | 14497 | return; |
| 14498 | |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14499 | if (IS_ICELAKE(dev_priv)) { |
| 14500 | intel_ddi_init(dev_priv, PORT_A); |
| 14501 | intel_ddi_init(dev_priv, PORT_B); |
| 14502 | intel_ddi_init(dev_priv, PORT_C); |
| 14503 | intel_ddi_init(dev_priv, PORT_D); |
| 14504 | intel_ddi_init(dev_priv, PORT_E); |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14505 | /* |
| 14506 | * On some ICL SKUs port F is not present. No strap bits for |
| 14507 | * this, so rely on VBT. |
Imre Deak | 2b34e562 | 2018-12-20 17:52:11 +0200 | [diff] [blame] | 14508 | * Work around broken VBTs on SKUs known to have no port F. |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14509 | */ |
Imre Deak | 2b34e562 | 2018-12-20 17:52:11 +0200 | [diff] [blame] | 14510 | if (IS_ICL_WITH_PORT_F(dev_priv) && |
| 14511 | intel_bios_is_port_present(dev_priv, PORT_F)) |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14512 | intel_ddi_init(dev_priv, PORT_F); |
| 14513 | |
Madhav Chauhan | bf4d57f | 2018-10-30 13:56:23 +0200 | [diff] [blame] | 14514 | icl_dsi_init(dev_priv); |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14515 | } else if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14516 | /* |
| 14517 | * FIXME: Broxton doesn't support port detection via the |
| 14518 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14519 | * detect the ports. |
| 14520 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14521 | intel_ddi_init(dev_priv, PORT_A); |
| 14522 | intel_ddi_init(dev_priv, PORT_B); |
| 14523 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14524 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14525 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14526 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14527 | int found; |
| 14528 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14529 | if (intel_ddi_crt_present(dev_priv)) |
| 14530 | intel_crt_init(dev_priv); |
| 14531 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14532 | /* |
| 14533 | * Haswell uses DDI functions to detect digital outputs. |
| 14534 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14535 | * it's there. |
| 14536 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14537 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14538 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14539 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14540 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14541 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14542 | /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14543 | * register */ |
| 14544 | found = I915_READ(SFUSE_STRAP); |
| 14545 | |
| 14546 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14547 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14548 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14549 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14550 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14551 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14552 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 14553 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14554 | /* |
| 14555 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14556 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14557 | if (IS_GEN9_BC(dev_priv) && |
Imre Deak | e9d49bb | 2018-12-20 15:26:02 +0200 | [diff] [blame] | 14558 | intel_bios_is_port_present(dev_priv, PORT_E)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14559 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14560 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14561 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14562 | int found; |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14563 | |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14564 | /* |
| 14565 | * intel_edp_init_connector() depends on this completing first, |
| 14566 | * to prevent the registration of both eDP and LVDS and the |
| 14567 | * incorrect sharing of the PPS. |
| 14568 | */ |
| 14569 | intel_lvds_init(dev_priv); |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14570 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14571 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14572 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14573 | |
Jani Nikula | a5916fd | 2019-01-22 10:23:05 +0200 | [diff] [blame] | 14574 | if (ilk_has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14575 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14576 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14577 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14578 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14579 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14580 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14581 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14582 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14583 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14584 | } |
| 14585 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14586 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14587 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14588 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14589 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14590 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14591 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14592 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14593 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14594 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14595 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14596 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14597 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14598 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 14599 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14600 | if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support) |
| 14601 | intel_crt_init(dev_priv); |
| 14602 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14603 | /* |
| 14604 | * The DP_DETECTED bit is the latched state of the DDC |
| 14605 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14606 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14607 | * eDP ports may have been muxed to an alternate function. |
| 14608 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14609 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14610 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14611 | * |
| 14612 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 14613 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 14614 | * and VBT for the presence of the port. Additionally we can't |
| 14615 | * trust the port type the VBT declares as we've seen at least |
| 14616 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14617 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14618 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14619 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14620 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14621 | has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14622 | if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14623 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14624 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14625 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14626 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14627 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14628 | has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14629 | if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14630 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14631 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14632 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14633 | /* |
| 14634 | * eDP not supported on port D, |
| 14635 | * so no need to worry about it |
| 14636 | */ |
| 14637 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14638 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14639 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14640 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14641 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14642 | } |
| 14643 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14644 | vlv_dsi_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14645 | } else if (IS_PINEVIEW(dev_priv)) { |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14646 | intel_lvds_init(dev_priv); |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14647 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14648 | } else if (IS_GEN_RANGE(dev_priv, 3, 4)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14649 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14650 | |
Jani Nikula | 9bedc7e | 2019-01-22 10:23:03 +0200 | [diff] [blame] | 14651 | if (IS_MOBILE(dev_priv)) |
| 14652 | intel_lvds_init(dev_priv); |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14653 | |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14654 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14655 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14656 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14657 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14658 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14659 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14660 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14661 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14662 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14663 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14664 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14665 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14666 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14667 | |
| 14668 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14669 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14670 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14671 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14672 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14673 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14674 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14675 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14676 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14677 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14678 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14679 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14680 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14681 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14682 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14683 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14684 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14685 | if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14686 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14687 | |
Jani Nikula | d652146 | 2019-01-22 10:23:04 +0200 | [diff] [blame] | 14688 | if (SUPPORTS_TV(dev_priv)) |
| 14689 | intel_tv_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14690 | } else if (IS_GEN(dev_priv, 2)) { |
Jani Nikula | 346073c | 2019-01-22 10:23:06 +0200 | [diff] [blame] | 14691 | if (IS_I85X(dev_priv)) |
Jani Nikula | 9bedc7e | 2019-01-22 10:23:03 +0200 | [diff] [blame] | 14692 | intel_lvds_init(dev_priv); |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14693 | |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14694 | intel_crt_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14695 | intel_dvo_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14696 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14697 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14698 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14699 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14700 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14701 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14702 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14703 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14704 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14705 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14706 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14707 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14708 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14709 | } |
| 14710 | |
| 14711 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14712 | { |
| 14713 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14714 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14715 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14716 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14717 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14718 | i915_gem_object_lock(obj); |
| 14719 | WARN_ON(!obj->framebuffer_references--); |
| 14720 | i915_gem_object_unlock(obj); |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14721 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14722 | i915_gem_object_put(obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14723 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14724 | kfree(intel_fb); |
| 14725 | } |
| 14726 | |
| 14727 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14728 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14729 | unsigned int *handle) |
| 14730 | { |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14731 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14732 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14733 | if (obj->userptr.mm) { |
| 14734 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14735 | return -EINVAL; |
| 14736 | } |
| 14737 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14738 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14739 | } |
| 14740 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14741 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14742 | struct drm_file *file, |
| 14743 | unsigned flags, unsigned color, |
| 14744 | struct drm_clip_rect *clips, |
| 14745 | unsigned num_clips) |
| 14746 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14747 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14748 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14749 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14750 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14751 | |
| 14752 | return 0; |
| 14753 | } |
| 14754 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14755 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14756 | .destroy = intel_user_framebuffer_destroy, |
| 14757 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14758 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14759 | }; |
| 14760 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14761 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14762 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14763 | u32 pixel_format, u64 fb_modifier) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14764 | { |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14765 | struct intel_crtc *crtc; |
| 14766 | struct intel_plane *plane; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14767 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14768 | /* |
| 14769 | * We assume the primary plane for pipe A has |
| 14770 | * the highest stride limits of them all. |
| 14771 | */ |
| 14772 | crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A); |
| 14773 | plane = to_intel_plane(crtc->base.primary); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14774 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14775 | return plane->max_stride(plane, pixel_format, fb_modifier, |
| 14776 | DRM_MODE_ROTATE_0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14777 | } |
| 14778 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14779 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14780 | struct drm_i915_gem_object *obj, |
| 14781 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14782 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14783 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14784 | struct drm_framebuffer *fb = &intel_fb->base; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14785 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14786 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14787 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14788 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14789 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14790 | i915_gem_object_lock(obj); |
| 14791 | obj->framebuffer_references++; |
| 14792 | tiling = i915_gem_object_get_tiling(obj); |
| 14793 | stride = i915_gem_object_get_stride(obj); |
| 14794 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14795 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14796 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14797 | /* |
| 14798 | * If there's a fence, enforce that |
| 14799 | * the fb modifier and tiling mode match. |
| 14800 | */ |
| 14801 | if (tiling != I915_TILING_NONE && |
| 14802 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14803 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14804 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14805 | } |
| 14806 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14807 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14808 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14809 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14810 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14811 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14812 | } |
| 14813 | } |
| 14814 | |
Ville Syrjälä | 17e8fd1 | 2018-10-29 20:34:53 +0200 | [diff] [blame] | 14815 | if (!drm_any_plane_has_format(&dev_priv->drm, |
| 14816 | mode_cmd->pixel_format, |
| 14817 | mode_cmd->modifier[0])) { |
| 14818 | struct drm_format_name_buf format_name; |
| 14819 | |
| 14820 | DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n", |
| 14821 | drm_get_format_name(mode_cmd->pixel_format, |
| 14822 | &format_name), |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14823 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14824 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14825 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14826 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14827 | /* |
| 14828 | * gen2/3 display engine uses the fence if present, |
| 14829 | * so the tiling mode must match the fb modifier exactly. |
| 14830 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14831 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14832 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14833 | DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n"); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14834 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14835 | } |
| 14836 | |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14837 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format, |
| 14838 | mode_cmd->modifier[0]); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14839 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14840 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14841 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14842 | "tiled" : "linear", |
| 14843 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14844 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14845 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14846 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14847 | /* |
| 14848 | * If there's a fence, enforce that |
| 14849 | * the fb pitch and fence stride match. |
| 14850 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14851 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14852 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14853 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14854 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14855 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14856 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14857 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14858 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14859 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14860 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14861 | drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14862 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14863 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14864 | u32 stride_alignment; |
| 14865 | |
| 14866 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14867 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14868 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14869 | } |
| 14870 | |
| 14871 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14872 | |
| 14873 | /* |
| 14874 | * Display WA #0531: skl,bxt,kbl,glk |
| 14875 | * |
| 14876 | * Render decompression and plane width > 3840 |
| 14877 | * combined with horizontal panning requires the |
| 14878 | * plane stride to be a multiple of 4. We'll just |
| 14879 | * require the entire fb to accommodate that to avoid |
| 14880 | * potential runtime errors at plane configuration time. |
| 14881 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14882 | if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 && |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 14883 | is_ccs_modifier(fb->modifier)) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14884 | stride_alignment *= 4; |
| 14885 | |
| 14886 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14887 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14888 | i, fb->pitches[i], stride_alignment); |
| 14889 | goto err; |
| 14890 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14891 | |
Daniel Stone | a268bcd | 2018-05-18 15:30:08 +0100 | [diff] [blame] | 14892 | fb->obj[i] = &obj->base; |
| 14893 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14894 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14895 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14896 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14897 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14898 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14899 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14900 | if (ret) { |
| 14901 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14902 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14903 | } |
| 14904 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14905 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14906 | |
| 14907 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14908 | i915_gem_object_lock(obj); |
| 14909 | obj->framebuffer_references--; |
| 14910 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14911 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14912 | } |
| 14913 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14914 | static struct drm_framebuffer * |
| 14915 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14916 | struct drm_file *filp, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14917 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14918 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14919 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14920 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14921 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14922 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14923 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14924 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14925 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14926 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14927 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14928 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14929 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14930 | |
| 14931 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14932 | } |
| 14933 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14934 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14935 | { |
| 14936 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14937 | |
| 14938 | drm_atomic_state_default_release(state); |
| 14939 | |
| 14940 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14941 | |
| 14942 | kfree(state); |
| 14943 | } |
| 14944 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14945 | static enum drm_mode_status |
| 14946 | intel_mode_valid(struct drm_device *dev, |
| 14947 | const struct drm_display_mode *mode) |
| 14948 | { |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14949 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14950 | int hdisplay_max, htotal_max; |
| 14951 | int vdisplay_max, vtotal_max; |
| 14952 | |
Ville Syrjälä | e4dd27a | 2018-05-24 15:54:03 +0300 | [diff] [blame] | 14953 | /* |
| 14954 | * Can't reject DBLSCAN here because Xorg ddxen can add piles |
| 14955 | * of DBLSCAN modes to the output's mode list when they detect |
| 14956 | * the scaling mode property on the connector. And they don't |
| 14957 | * ask the kernel to validate those modes in any way until |
| 14958 | * modeset time at which point the client gets a protocol error. |
| 14959 | * So in order to not upset those clients we silently ignore the |
| 14960 | * DBLSCAN flag on such connectors. For other connectors we will |
| 14961 | * reject modes with the DBLSCAN flag in encoder->compute_config(). |
| 14962 | * And we always reject DBLSCAN modes in connector->mode_valid() |
| 14963 | * as we never want such modes on the connector's mode list. |
| 14964 | */ |
| 14965 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14966 | if (mode->vscan > 1) |
| 14967 | return MODE_NO_VSCAN; |
| 14968 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14969 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 14970 | return MODE_H_ILLEGAL; |
| 14971 | |
| 14972 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 14973 | DRM_MODE_FLAG_NCSYNC | |
| 14974 | DRM_MODE_FLAG_PCSYNC)) |
| 14975 | return MODE_HSYNC; |
| 14976 | |
| 14977 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 14978 | DRM_MODE_FLAG_PIXMUX | |
| 14979 | DRM_MODE_FLAG_CLKDIV2)) |
| 14980 | return MODE_BAD; |
| 14981 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14982 | if (INTEL_GEN(dev_priv) >= 9 || |
| 14983 | IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { |
| 14984 | hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ |
| 14985 | vdisplay_max = 4096; |
| 14986 | htotal_max = 8192; |
| 14987 | vtotal_max = 8192; |
| 14988 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 14989 | hdisplay_max = 4096; |
| 14990 | vdisplay_max = 4096; |
| 14991 | htotal_max = 8192; |
| 14992 | vtotal_max = 8192; |
| 14993 | } else { |
| 14994 | hdisplay_max = 2048; |
| 14995 | vdisplay_max = 2048; |
| 14996 | htotal_max = 4096; |
| 14997 | vtotal_max = 4096; |
| 14998 | } |
| 14999 | |
| 15000 | if (mode->hdisplay > hdisplay_max || |
| 15001 | mode->hsync_start > htotal_max || |
| 15002 | mode->hsync_end > htotal_max || |
| 15003 | mode->htotal > htotal_max) |
| 15004 | return MODE_H_ILLEGAL; |
| 15005 | |
| 15006 | if (mode->vdisplay > vdisplay_max || |
| 15007 | mode->vsync_start > vtotal_max || |
| 15008 | mode->vsync_end > vtotal_max || |
| 15009 | mode->vtotal > vtotal_max) |
| 15010 | return MODE_V_ILLEGAL; |
| 15011 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 15012 | return MODE_OK; |
| 15013 | } |
| 15014 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15015 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15016 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 15017 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 15018 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 15019 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 15020 | .atomic_check = intel_atomic_check, |
| 15021 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 15022 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 15023 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 15024 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15025 | }; |
| 15026 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15027 | /** |
| 15028 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 15029 | * @dev_priv: device private |
| 15030 | */ |
| 15031 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15032 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 15033 | intel_init_cdclk_hooks(dev_priv); |
| 15034 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 15035 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15036 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15037 | dev_priv->display.get_initial_plane_config = |
| 15038 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15039 | dev_priv->display.crtc_compute_clock = |
| 15040 | haswell_crtc_compute_clock; |
| 15041 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 15042 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15043 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15044 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15045 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 15046 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 15047 | dev_priv->display.crtc_compute_clock = |
| 15048 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 15049 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 15050 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15051 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15052 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15053 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 15054 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 15055 | dev_priv->display.crtc_compute_clock = |
| 15056 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 15057 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 15058 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 15059 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 15060 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15061 | dev_priv->display.get_initial_plane_config = |
| 15062 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 15063 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 15064 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 15065 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 15066 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 15067 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15068 | dev_priv->display.get_initial_plane_config = |
| 15069 | i9xx_get_initial_plane_config; |
| 15070 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 15071 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 15072 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 15073 | } else if (IS_G4X(dev_priv)) { |
| 15074 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15075 | dev_priv->display.get_initial_plane_config = |
| 15076 | i9xx_get_initial_plane_config; |
| 15077 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 15078 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15079 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 15080 | } else if (IS_PINEVIEW(dev_priv)) { |
| 15081 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15082 | dev_priv->display.get_initial_plane_config = |
| 15083 | i9xx_get_initial_plane_config; |
| 15084 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 15085 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15086 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15087 | } else if (!IS_GEN(dev_priv, 2)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15088 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15089 | dev_priv->display.get_initial_plane_config = |
| 15090 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 15091 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 15092 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15093 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 15094 | } else { |
| 15095 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15096 | dev_priv->display.get_initial_plane_config = |
| 15097 | i9xx_get_initial_plane_config; |
| 15098 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 15099 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15100 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 15101 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15102 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15103 | if (IS_GEN(dev_priv, 5)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15104 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15105 | } else if (IS_GEN(dev_priv, 6)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15106 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15107 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15108 | /* FIXME: detect B0+ stepping and use auto training */ |
| 15109 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15110 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15111 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 15112 | } |
| 15113 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 15114 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 15115 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 15116 | else |
| 15117 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15118 | } |
| 15119 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15120 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15121 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15122 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 15123 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15124 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15125 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15126 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 15127 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 15128 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 15129 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15130 | sr1 = inb(VGA_SR_DATA); |
| 15131 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 15132 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15133 | udelay(300); |
| 15134 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 15135 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15136 | POSTING_READ(vga_reg); |
| 15137 | } |
| 15138 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15139 | void intel_modeset_init_hw(struct drm_device *dev) |
| 15140 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15141 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15142 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15143 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 15144 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 15145 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15146 | } |
| 15147 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15148 | /* |
| 15149 | * Calculate what we think the watermarks should be for the state we've read |
| 15150 | * out of the hardware and then immediately program those watermarks so that |
| 15151 | * we ensure the hardware settings match our internal state. |
| 15152 | * |
| 15153 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 15154 | * current state (which was constructed during hardware readout) and running it |
| 15155 | * through the atomic check code to calculate new watermark values in the |
| 15156 | * state object. |
| 15157 | */ |
| 15158 | static void sanitize_watermarks(struct drm_device *dev) |
| 15159 | { |
| 15160 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15161 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15162 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15163 | struct drm_crtc *crtc; |
| 15164 | struct drm_crtc_state *cstate; |
| 15165 | struct drm_modeset_acquire_ctx ctx; |
| 15166 | int ret; |
| 15167 | int i; |
| 15168 | |
| 15169 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15170 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15171 | return; |
| 15172 | |
| 15173 | /* |
| 15174 | * We need to hold connection_mutex before calling duplicate_state so |
| 15175 | * that the connector loop is protected. |
| 15176 | */ |
| 15177 | drm_modeset_acquire_init(&ctx, 0); |
| 15178 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15179 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15180 | if (ret == -EDEADLK) { |
| 15181 | drm_modeset_backoff(&ctx); |
| 15182 | goto retry; |
| 15183 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15184 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15185 | } |
| 15186 | |
| 15187 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 15188 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15189 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15190 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15191 | intel_state = to_intel_atomic_state(state); |
| 15192 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15193 | /* |
| 15194 | * Hardware readout is the only time we don't want to calculate |
| 15195 | * intermediate watermarks (since we don't trust the current |
| 15196 | * watermarks). |
| 15197 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 15198 | if (!HAS_GMCH(dev_priv)) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15199 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15200 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15201 | ret = intel_atomic_check(dev, state); |
| 15202 | if (ret) { |
| 15203 | /* |
| 15204 | * If we fail here, it means that the hardware appears to be |
| 15205 | * programmed in a way that shouldn't be possible, given our |
| 15206 | * understanding of watermark requirements. This might mean a |
| 15207 | * mistake in the hardware readout code or a mistake in the |
| 15208 | * watermark calculations for a given platform. Raise a WARN |
| 15209 | * so that this is noticeable. |
| 15210 | * |
| 15211 | * If this actually happens, we'll have to just leave the |
| 15212 | * BIOS-programmed watermarks untouched and hope for the best. |
| 15213 | */ |
| 15214 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 15215 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15216 | } |
| 15217 | |
| 15218 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 15219 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15220 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 15221 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15222 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15223 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 15224 | |
| 15225 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15226 | } |
| 15227 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 15228 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15229 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15230 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15231 | drm_modeset_drop_locks(&ctx); |
| 15232 | drm_modeset_acquire_fini(&ctx); |
| 15233 | } |
| 15234 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15235 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 15236 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15237 | if (IS_GEN(dev_priv, 5)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15238 | u32 fdi_pll_clk = |
| 15239 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 15240 | |
| 15241 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15242 | } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15243 | dev_priv->fdi_pll_freq = 270000; |
| 15244 | } else { |
| 15245 | return; |
| 15246 | } |
| 15247 | |
| 15248 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 15249 | } |
| 15250 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15251 | static int intel_initial_commit(struct drm_device *dev) |
| 15252 | { |
| 15253 | struct drm_atomic_state *state = NULL; |
| 15254 | struct drm_modeset_acquire_ctx ctx; |
| 15255 | struct drm_crtc *crtc; |
| 15256 | struct drm_crtc_state *crtc_state; |
| 15257 | int ret = 0; |
| 15258 | |
| 15259 | state = drm_atomic_state_alloc(dev); |
| 15260 | if (!state) |
| 15261 | return -ENOMEM; |
| 15262 | |
| 15263 | drm_modeset_acquire_init(&ctx, 0); |
| 15264 | |
| 15265 | retry: |
| 15266 | state->acquire_ctx = &ctx; |
| 15267 | |
| 15268 | drm_for_each_crtc(crtc, dev) { |
| 15269 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 15270 | if (IS_ERR(crtc_state)) { |
| 15271 | ret = PTR_ERR(crtc_state); |
| 15272 | goto out; |
| 15273 | } |
| 15274 | |
| 15275 | if (crtc_state->active) { |
| 15276 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 15277 | if (ret) |
| 15278 | goto out; |
Ville Syrjälä | fa6af514 | 2018-11-20 15:54:49 +0200 | [diff] [blame] | 15279 | |
| 15280 | /* |
| 15281 | * FIXME hack to force a LUT update to avoid the |
| 15282 | * plane update forcing the pipe gamma on without |
| 15283 | * having a proper LUT loaded. Remove once we |
| 15284 | * have readout for pipe gamma enable. |
| 15285 | */ |
| 15286 | crtc_state->color_mgmt_changed = true; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15287 | } |
| 15288 | } |
| 15289 | |
| 15290 | ret = drm_atomic_commit(state); |
| 15291 | |
| 15292 | out: |
| 15293 | if (ret == -EDEADLK) { |
| 15294 | drm_atomic_state_clear(state); |
| 15295 | drm_modeset_backoff(&ctx); |
| 15296 | goto retry; |
| 15297 | } |
| 15298 | |
| 15299 | drm_atomic_state_put(state); |
| 15300 | |
| 15301 | drm_modeset_drop_locks(&ctx); |
| 15302 | drm_modeset_acquire_fini(&ctx); |
| 15303 | |
| 15304 | return ret; |
| 15305 | } |
| 15306 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15307 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15308 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15309 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15310 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15311 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15312 | struct intel_crtc *crtc; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15313 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15314 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15315 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 15316 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15317 | drm_mode_config_init(dev); |
| 15318 | |
| 15319 | dev->mode_config.min_width = 0; |
| 15320 | dev->mode_config.min_height = 0; |
| 15321 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15322 | dev->mode_config.preferred_depth = 24; |
| 15323 | dev->mode_config.prefer_shadow = 1; |
| 15324 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15325 | dev->mode_config.allow_fb_modifiers = true; |
| 15326 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15327 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15328 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 15329 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15330 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 15331 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15332 | |
Jani Nikula | 27a981b | 2018-10-17 12:35:39 +0300 | [diff] [blame] | 15333 | intel_init_quirks(dev_priv); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15334 | |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 15335 | intel_fbc_init(dev_priv); |
| 15336 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 15337 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15338 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15339 | /* |
| 15340 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15341 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15342 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15343 | * indicates as much. |
| 15344 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15345 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15346 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15347 | DREF_SSC1_ENABLE); |
| 15348 | |
| 15349 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15350 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15351 | bios_lvds_use_ssc ? "en" : "dis", |
| 15352 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15353 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15354 | } |
| 15355 | } |
| 15356 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15357 | /* maximum framebuffer dimensions */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15358 | if (IS_GEN(dev_priv, 2)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15359 | dev->mode_config.max_width = 2048; |
| 15360 | dev->mode_config.max_height = 2048; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15361 | } else if (IS_GEN(dev_priv, 3)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15362 | dev->mode_config.max_width = 4096; |
| 15363 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15364 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15365 | dev->mode_config.max_width = 8192; |
| 15366 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15367 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15368 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 15369 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 15370 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15371 | dev->mode_config.cursor_height = 1023; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15372 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15373 | dev->mode_config.cursor_width = 64; |
| 15374 | dev->mode_config.cursor_height = 64; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15375 | } else { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15376 | dev->mode_config.cursor_width = 256; |
| 15377 | dev->mode_config.cursor_height = 256; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15378 | } |
| 15379 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 15380 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15381 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15382 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15383 | INTEL_INFO(dev_priv)->num_pipes, |
| 15384 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15385 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15386 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15387 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15388 | if (ret) { |
| 15389 | drm_mode_config_cleanup(dev); |
| 15390 | return ret; |
| 15391 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15392 | } |
| 15393 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15394 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15395 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15396 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 15397 | intel_update_czclk(dev_priv); |
| 15398 | intel_modeset_init_hw(dev); |
| 15399 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15400 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15401 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15402 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15403 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15404 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15405 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15406 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15407 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15408 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15409 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15410 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15411 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15412 | struct intel_initial_plane_config plane_config = {}; |
| 15413 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15414 | if (!crtc->active) |
| 15415 | continue; |
| 15416 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15417 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15418 | * Note that reserving the BIOS fb up front prevents us |
| 15419 | * from stuffing other stolen allocations like the ring |
| 15420 | * on top. This prevents some ugliness at boot time, and |
| 15421 | * can even allow for smooth boot transitions if the BIOS |
| 15422 | * fb is large enough for the active pipe configuration. |
| 15423 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15424 | dev_priv->display.get_initial_plane_config(crtc, |
| 15425 | &plane_config); |
| 15426 | |
| 15427 | /* |
| 15428 | * If the fb is shared between multiple heads, we'll |
| 15429 | * just get the first one. |
| 15430 | */ |
| 15431 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15432 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15433 | |
| 15434 | /* |
| 15435 | * Make sure hardware watermarks really match the state we read out. |
| 15436 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15437 | * since the watermark calculation done here will use pstate->fb. |
| 15438 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 15439 | if (!HAS_GMCH(dev_priv)) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15440 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15441 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15442 | /* |
| 15443 | * Force all active planes to recompute their states. So that on |
| 15444 | * mode_setcrtc after probe, all the intel_plane_state variables |
| 15445 | * are already calculated and there is no assert_plane warnings |
| 15446 | * during bootup. |
| 15447 | */ |
| 15448 | ret = intel_initial_commit(dev); |
| 15449 | if (ret) |
| 15450 | DRM_DEBUG_KMS("Initial commit in probe failed.\n"); |
| 15451 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15452 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15453 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15454 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15455 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15456 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15457 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15458 | /* 640x480@60Hz, ~25175 kHz */ |
| 15459 | struct dpll clock = { |
| 15460 | .m1 = 18, |
| 15461 | .m2 = 7, |
| 15462 | .p1 = 13, |
| 15463 | .p2 = 4, |
| 15464 | .n = 2, |
| 15465 | }; |
| 15466 | u32 dpll, fp; |
| 15467 | int i; |
| 15468 | |
| 15469 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 15470 | |
| 15471 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 15472 | pipe_name(pipe), clock.vco, clock.dot); |
| 15473 | |
| 15474 | fp = i9xx_dpll_compute_fp(&clock); |
| 15475 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 15476 | DPLL_VGA_MODE_DIS | |
| 15477 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 15478 | PLL_P2_DIVIDE_BY_4 | |
| 15479 | PLL_REF_INPUT_DREFCLK | |
| 15480 | DPLL_VCO_ENABLE; |
| 15481 | |
| 15482 | I915_WRITE(FP0(pipe), fp); |
| 15483 | I915_WRITE(FP1(pipe), fp); |
| 15484 | |
| 15485 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15486 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15487 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15488 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15489 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15490 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15491 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15492 | |
| 15493 | /* |
| 15494 | * Apparently we need to have VGA mode enabled prior to changing |
| 15495 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15496 | * dividers, even though the register value does change. |
| 15497 | */ |
| 15498 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15499 | I915_WRITE(DPLL(pipe), dpll); |
| 15500 | |
| 15501 | /* Wait for the clocks to stabilize. */ |
| 15502 | POSTING_READ(DPLL(pipe)); |
| 15503 | udelay(150); |
| 15504 | |
| 15505 | /* The pixel multiplier can only be updated once the |
| 15506 | * DPLL is enabled and the clocks are stable. |
| 15507 | * |
| 15508 | * So write it again. |
| 15509 | */ |
| 15510 | I915_WRITE(DPLL(pipe), dpll); |
| 15511 | |
| 15512 | /* We do this three times for luck */ |
| 15513 | for (i = 0; i < 3 ; i++) { |
| 15514 | I915_WRITE(DPLL(pipe), dpll); |
| 15515 | POSTING_READ(DPLL(pipe)); |
| 15516 | udelay(150); /* wait for warmup */ |
| 15517 | } |
| 15518 | |
| 15519 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15520 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15521 | |
| 15522 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15523 | } |
| 15524 | |
| 15525 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15526 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15527 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15528 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15529 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15530 | pipe_name(pipe)); |
| 15531 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15532 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15533 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15534 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 15535 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE); |
| 15536 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15537 | |
| 15538 | I915_WRITE(PIPECONF(pipe), 0); |
| 15539 | POSTING_READ(PIPECONF(pipe)); |
| 15540 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15541 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15542 | |
| 15543 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15544 | POSTING_READ(DPLL(pipe)); |
| 15545 | } |
| 15546 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15547 | static void |
| 15548 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15549 | { |
| 15550 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15551 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15552 | if (INTEL_GEN(dev_priv) >= 4) |
| 15553 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15554 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15555 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15556 | struct intel_plane *plane = |
| 15557 | to_intel_plane(crtc->base.primary); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15558 | struct intel_crtc *plane_crtc; |
| 15559 | enum pipe pipe; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15560 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15561 | if (!plane->get_hw_state(plane, &pipe)) |
| 15562 | continue; |
| 15563 | |
| 15564 | if (pipe == crtc->pipe) |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15565 | continue; |
| 15566 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15567 | DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", |
| 15568 | plane->base.base.id, plane->base.name); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15569 | |
| 15570 | plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15571 | intel_plane_disable_noatomic(plane_crtc, plane); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15572 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15573 | } |
| 15574 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15575 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15576 | { |
| 15577 | struct drm_device *dev = crtc->base.dev; |
| 15578 | struct intel_encoder *encoder; |
| 15579 | |
| 15580 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15581 | return true; |
| 15582 | |
| 15583 | return false; |
| 15584 | } |
| 15585 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15586 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15587 | { |
| 15588 | struct drm_device *dev = encoder->base.dev; |
| 15589 | struct intel_connector *connector; |
| 15590 | |
| 15591 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15592 | return connector; |
| 15593 | |
| 15594 | return NULL; |
| 15595 | } |
| 15596 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15597 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15598 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15599 | { |
| 15600 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15601 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15602 | } |
| 15603 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15604 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15605 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15606 | { |
| 15607 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15608 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15609 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15610 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15611 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15612 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Ville Syrjälä | 738a814 | 2017-11-15 22:04:42 +0200 | [diff] [blame] | 15613 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15614 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15615 | |
| 15616 | I915_WRITE(reg, |
| 15617 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15618 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15619 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15620 | if (crtc_state->base.active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15621 | struct intel_plane *plane; |
| 15622 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15623 | /* Disable everything but the primary plane */ |
| 15624 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15625 | const struct intel_plane_state *plane_state = |
| 15626 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15627 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15628 | if (plane_state->base.visible && |
| 15629 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15630 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15631 | } |
Matt Roper | c055030 | 2019-01-30 10:51:20 -0800 | [diff] [blame] | 15632 | |
| 15633 | /* |
| 15634 | * Disable any background color set by the BIOS, but enable the |
| 15635 | * gamma and CSC to match how we program our planes. |
| 15636 | */ |
| 15637 | if (INTEL_GEN(dev_priv) >= 9) |
| 15638 | I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe), |
| 15639 | SKL_BOTTOM_COLOR_GAMMA_ENABLE | |
| 15640 | SKL_BOTTOM_COLOR_CSC_ENABLE); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15641 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15642 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15643 | /* Adjust the state of the output pipe according to whether we |
| 15644 | * have active connectors/encoders. */ |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15645 | if (crtc_state->base.active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15646 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15647 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 15648 | if (crtc_state->base.active || HAS_GMCH(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15649 | /* |
| 15650 | * We start out with underrun reporting disabled to avoid races. |
| 15651 | * For correct bookkeeping mark this on active crtcs. |
| 15652 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15653 | * Also on gmch platforms we dont have any hardware bits to |
| 15654 | * disable the underrun reporting. Which means we need to start |
| 15655 | * out with underrun reporting disabled also on inactive pipes, |
| 15656 | * since otherwise we'll complain about the garbage we read when |
| 15657 | * e.g. coming up after runtime pm. |
| 15658 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15659 | * No protection against concurrent access is required - at |
| 15660 | * worst a fifo underrun happens which also sets this to false. |
| 15661 | */ |
| 15662 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15663 | /* |
| 15664 | * We track the PCH trancoder underrun reporting state |
| 15665 | * within the crtc. With crtc for pipe A housing the underrun |
| 15666 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15667 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15668 | * and marking underrun reporting as disabled for the non-existing |
| 15669 | * PCH transcoders B and C would prevent enabling the south |
| 15670 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15671 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15672 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15673 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15674 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15675 | } |
| 15676 | |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15677 | static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state) |
| 15678 | { |
| 15679 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 15680 | |
| 15681 | /* |
| 15682 | * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram |
| 15683 | * the hardware when a high res displays plugged in. DPLL P |
| 15684 | * divider is zero, and the pipe timings are bonkers. We'll |
| 15685 | * try to disable everything in that case. |
| 15686 | * |
| 15687 | * FIXME would be nice to be able to sanitize this state |
| 15688 | * without several WARNs, but for now let's take the easy |
| 15689 | * road. |
| 15690 | */ |
| 15691 | return IS_GEN(dev_priv, 6) && |
| 15692 | crtc_state->base.active && |
| 15693 | crtc_state->shared_dpll && |
| 15694 | crtc_state->port_clock == 0; |
| 15695 | } |
| 15696 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15697 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15698 | { |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15699 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15700 | struct intel_connector *connector; |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15701 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 15702 | struct intel_crtc_state *crtc_state = crtc ? |
| 15703 | to_intel_crtc_state(crtc->base.state) : NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15704 | |
| 15705 | /* We need to check both for a crtc link (meaning that the |
| 15706 | * encoder is active and trying to read from a pipe) and the |
| 15707 | * pipe itself being active. */ |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15708 | bool has_active_crtc = crtc_state && |
| 15709 | crtc_state->base.active; |
| 15710 | |
| 15711 | if (crtc_state && has_bogus_dpll_config(crtc_state)) { |
| 15712 | DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n", |
| 15713 | pipe_name(crtc->pipe)); |
| 15714 | has_active_crtc = false; |
| 15715 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15716 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15717 | connector = intel_encoder_find_connector(encoder); |
| 15718 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15719 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15720 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15721 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15722 | |
| 15723 | /* Connector is active, but has no active pipe. This is |
| 15724 | * fallout from our resume register restoring. Disable |
| 15725 | * the encoder manually again. */ |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15726 | if (crtc_state) { |
| 15727 | struct drm_encoder *best_encoder; |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15728 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15729 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15730 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15731 | encoder->base.name); |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15732 | |
| 15733 | /* avoid oopsing in case the hooks consult best_encoder */ |
| 15734 | best_encoder = connector->base.state->best_encoder; |
| 15735 | connector->base.state->best_encoder = &encoder->base; |
| 15736 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 15737 | if (encoder->disable) |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15738 | encoder->disable(encoder, crtc_state, |
| 15739 | connector->base.state); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15740 | if (encoder->post_disable) |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15741 | encoder->post_disable(encoder, crtc_state, |
| 15742 | connector->base.state); |
| 15743 | |
| 15744 | connector->base.state->best_encoder = best_encoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15745 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15746 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15747 | |
| 15748 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15749 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15750 | * in our code, like the register restore mess on resume. Clamp |
| 15751 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15752 | |
| 15753 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15754 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15755 | } |
Maarten Lankhorst | d6cae4a | 2018-05-16 10:50:38 +0200 | [diff] [blame] | 15756 | |
| 15757 | /* notify opregion of the sanitized encoder state */ |
| 15758 | intel_opregion_notify_encoder(encoder, connector && has_active_crtc); |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15759 | |
| 15760 | if (INTEL_GEN(dev_priv) >= 11) |
| 15761 | icl_sanitize_encoder_pll_mapping(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15762 | } |
| 15763 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15764 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15765 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15766 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15767 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15768 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15769 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15770 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15771 | } |
| 15772 | } |
| 15773 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15774 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15775 | { |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15776 | intel_wakeref_t wakeref; |
| 15777 | |
| 15778 | /* |
| 15779 | * This function can be called both from intel_modeset_setup_hw_state or |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15780 | * at a very early point in our resume sequence, where the power well |
| 15781 | * structures are not yet restored. Since this function is at a very |
| 15782 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15783 | * level, just check if the power well is enabled instead of trying to |
| 15784 | * follow the "don't touch the power well if we don't need it" policy |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15785 | * the rest of the driver uses. |
| 15786 | */ |
| 15787 | wakeref = intel_display_power_get_if_enabled(dev_priv, |
| 15788 | POWER_DOMAIN_VGA); |
| 15789 | if (!wakeref) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15790 | return; |
| 15791 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15792 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15793 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15794 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15795 | } |
| 15796 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15797 | /* FIXME read out full plane state for all planes */ |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15798 | static void readout_plane_state(struct drm_i915_private *dev_priv) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15799 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15800 | struct intel_plane *plane; |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15801 | struct intel_crtc *crtc; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15802 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15803 | for_each_intel_plane(&dev_priv->drm, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15804 | struct intel_plane_state *plane_state = |
| 15805 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15806 | struct intel_crtc_state *crtc_state; |
| 15807 | enum pipe pipe = PIPE_A; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 15808 | bool visible; |
| 15809 | |
| 15810 | visible = plane->get_hw_state(plane, &pipe); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15811 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15812 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15813 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15814 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15815 | intel_set_plane_visible(crtc_state, plane_state, visible); |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15816 | |
| 15817 | DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n", |
| 15818 | plane->base.base.id, plane->base.name, |
| 15819 | enableddisabled(visible), pipe_name(pipe)); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15820 | } |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15821 | |
| 15822 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15823 | struct intel_crtc_state *crtc_state = |
| 15824 | to_intel_crtc_state(crtc->base.state); |
| 15825 | |
| 15826 | fixup_active_planes(crtc_state); |
| 15827 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15828 | } |
| 15829 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15830 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15831 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15832 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15833 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15834 | struct intel_crtc *crtc; |
| 15835 | struct intel_encoder *encoder; |
| 15836 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15837 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15838 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15839 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15840 | dev_priv->active_crtcs = 0; |
| 15841 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15842 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15843 | struct intel_crtc_state *crtc_state = |
| 15844 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15845 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15846 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15847 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15848 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15849 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15850 | crtc_state->base.active = crtc_state->base.enable = |
| 15851 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15852 | |
| 15853 | crtc->base.enabled = crtc_state->base.enable; |
| 15854 | crtc->active = crtc_state->base.active; |
| 15855 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15856 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15857 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15858 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15859 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15860 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15861 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15862 | } |
| 15863 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15864 | readout_plane_state(dev_priv); |
| 15865 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15866 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15867 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15868 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15869 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15870 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15871 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15872 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15873 | struct intel_crtc_state *crtc_state = |
| 15874 | to_intel_crtc_state(crtc->base.state); |
| 15875 | |
| 15876 | if (crtc_state->base.active && |
| 15877 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15878 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15879 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15880 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15881 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15882 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 15883 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15884 | } |
| 15885 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15886 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15887 | pipe = 0; |
| 15888 | |
| 15889 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15890 | struct intel_crtc_state *crtc_state; |
| 15891 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15892 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15893 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15894 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15895 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15896 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15897 | } else { |
| 15898 | encoder->base.crtc = NULL; |
| 15899 | } |
| 15900 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15901 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15902 | encoder->base.base.id, encoder->base.name, |
| 15903 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15904 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15905 | } |
| 15906 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15907 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15908 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15909 | if (connector->get_hw_state(connector)) { |
| 15910 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15911 | |
| 15912 | encoder = connector->encoder; |
| 15913 | connector->base.encoder = &encoder->base; |
| 15914 | |
| 15915 | if (encoder->base.crtc && |
| 15916 | encoder->base.crtc->state->active) { |
| 15917 | /* |
| 15918 | * This has to be done during hardware readout |
| 15919 | * because anything calling .crtc_disable may |
| 15920 | * rely on the connector_mask being accurate. |
| 15921 | */ |
| 15922 | encoder->base.crtc->state->connector_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15923 | drm_connector_mask(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15924 | encoder->base.crtc->state->encoder_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15925 | drm_encoder_mask(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15926 | } |
| 15927 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15928 | } else { |
| 15929 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15930 | connector->base.encoder = NULL; |
| 15931 | } |
| 15932 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15933 | connector->base.base.id, connector->base.name, |
| 15934 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15935 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15936 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15937 | |
| 15938 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15939 | struct intel_crtc_state *crtc_state = |
| 15940 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15941 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15942 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15943 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15944 | if (crtc_state->base.active) { |
| 15945 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15946 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15947 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15948 | intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15949 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15950 | |
| 15951 | /* |
| 15952 | * The initial mode needs to be set in order to keep |
| 15953 | * the atomic core happy. It wants a valid mode if the |
| 15954 | * crtc's enabled, so we do the above call. |
| 15955 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 15956 | * But we don't set all the derived state fully, hence |
| 15957 | * set a flag to indicate that a full recalculation is |
| 15958 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15959 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15960 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15961 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 15962 | intel_crtc_compute_pixel_rate(crtc_state); |
| 15963 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15964 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15965 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15966 | if (WARN_ON(min_cdclk < 0)) |
| 15967 | min_cdclk = 0; |
| 15968 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15969 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 15970 | drm_calc_timestamping_constants(&crtc->base, |
| 15971 | &crtc_state->base.adjusted_mode); |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 15972 | update_scanline_offset(crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15973 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15974 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15975 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 15976 | dev_priv->min_voltage_level[crtc->pipe] = |
| 15977 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15978 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15979 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15980 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15981 | } |
| 15982 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15983 | static void |
| 15984 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 15985 | { |
| 15986 | struct intel_encoder *encoder; |
| 15987 | |
| 15988 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 15989 | u64 get_domains; |
| 15990 | enum intel_display_power_domain domain; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15991 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15992 | |
| 15993 | if (!encoder->get_power_domains) |
| 15994 | continue; |
| 15995 | |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15996 | /* |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15997 | * MST-primary and inactive encoders don't have a crtc state |
| 15998 | * and neither of these require any power domain references. |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15999 | */ |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 16000 | if (!encoder->base.crtc) |
| 16001 | continue; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16002 | |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 16003 | crtc_state = to_intel_crtc_state(encoder->base.crtc->state); |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16004 | get_domains = encoder->get_power_domains(encoder, crtc_state); |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 16005 | for_each_power_domain(domain, get_domains) |
| 16006 | intel_display_power_get(dev_priv, domain); |
| 16007 | } |
| 16008 | } |
| 16009 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 16010 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 16011 | { |
| 16012 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 16013 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 16014 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 16015 | DARBF_GATING_DIS); |
| 16016 | |
| 16017 | if (IS_HASWELL(dev_priv)) { |
| 16018 | /* |
| 16019 | * WaRsPkgCStateDisplayPMReq:hsw |
| 16020 | * System hang if this isn't done before disabling all planes! |
| 16021 | */ |
| 16022 | I915_WRITE(CHICKEN_PAR1_1, |
| 16023 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 16024 | } |
| 16025 | } |
| 16026 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 16027 | static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv, |
| 16028 | enum port port, i915_reg_t hdmi_reg) |
| 16029 | { |
| 16030 | u32 val = I915_READ(hdmi_reg); |
| 16031 | |
| 16032 | if (val & SDVO_ENABLE || |
| 16033 | (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A)) |
| 16034 | return; |
| 16035 | |
| 16036 | DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n", |
| 16037 | port_name(port)); |
| 16038 | |
| 16039 | val &= ~SDVO_PIPE_SEL_MASK; |
| 16040 | val |= SDVO_PIPE_SEL(PIPE_A); |
| 16041 | |
| 16042 | I915_WRITE(hdmi_reg, val); |
| 16043 | } |
| 16044 | |
| 16045 | static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv, |
| 16046 | enum port port, i915_reg_t dp_reg) |
| 16047 | { |
| 16048 | u32 val = I915_READ(dp_reg); |
| 16049 | |
| 16050 | if (val & DP_PORT_EN || |
| 16051 | (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A)) |
| 16052 | return; |
| 16053 | |
| 16054 | DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n", |
| 16055 | port_name(port)); |
| 16056 | |
| 16057 | val &= ~DP_PIPE_SEL_MASK; |
| 16058 | val |= DP_PIPE_SEL(PIPE_A); |
| 16059 | |
| 16060 | I915_WRITE(dp_reg, val); |
| 16061 | } |
| 16062 | |
| 16063 | static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv) |
| 16064 | { |
| 16065 | /* |
| 16066 | * The BIOS may select transcoder B on some of the PCH |
| 16067 | * ports even it doesn't enable the port. This would trip |
| 16068 | * assert_pch_dp_disabled() and assert_pch_hdmi_disabled(). |
| 16069 | * Sanitize the transcoder select bits to prevent that. We |
| 16070 | * assume that the BIOS never actually enabled the port, |
| 16071 | * because if it did we'd actually have to toggle the port |
| 16072 | * on and back off to make the transcoder A select stick |
| 16073 | * (see. intel_dp_link_down(), intel_disable_hdmi(), |
| 16074 | * intel_disable_sdvo()). |
| 16075 | */ |
| 16076 | ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B); |
| 16077 | ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C); |
| 16078 | ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D); |
| 16079 | |
| 16080 | /* PCH SDVOB multiplex with HDMIB */ |
| 16081 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB); |
| 16082 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC); |
| 16083 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID); |
| 16084 | } |
| 16085 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16086 | /* Scan out the current hw modeset state, |
| 16087 | * and sanitizes it to the current state |
| 16088 | */ |
| 16089 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 16090 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 16091 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16092 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16093 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16094 | struct intel_crtc_state *crtc_state; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16095 | struct intel_encoder *encoder; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 16096 | struct intel_crtc *crtc; |
| 16097 | intel_wakeref_t wakeref; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16098 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16099 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 16100 | wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 16101 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 16102 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16103 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16104 | |
| 16105 | /* HW state is read out, now we need to sanitize this mess. */ |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 16106 | get_encoder_power_domains(dev_priv); |
| 16107 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 16108 | if (HAS_PCH_IBX(dev_priv)) |
| 16109 | ibx_sanitize_pch_ports(dev_priv); |
| 16110 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16111 | /* |
| 16112 | * intel_sanitize_plane_mapping() may need to do vblank |
| 16113 | * waits, so we need vblank interrupts restored beforehand. |
| 16114 | */ |
| 16115 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 16116 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 16117 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16118 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 16119 | |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 16120 | if (crtc_state->base.active) |
| 16121 | intel_crtc_vblank_on(crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16122 | } |
| 16123 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16124 | intel_sanitize_plane_mapping(dev_priv); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 16125 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16126 | for_each_intel_encoder(dev, encoder) |
| 16127 | intel_sanitize_encoder(encoder); |
| 16128 | |
| 16129 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16130 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 16131 | intel_sanitize_crtc(crtc, ctx); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16132 | intel_dump_pipe_config(crtc, crtc_state, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 16133 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16134 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 16135 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 16136 | intel_modeset_update_connector_atomic_state(dev); |
| 16137 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16138 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 16139 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 16140 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 16141 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16142 | continue; |
| 16143 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 16144 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 16145 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16146 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 16147 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16148 | pll->on = false; |
| 16149 | } |
| 16150 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 16151 | if (IS_G4X(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16152 | g4x_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 16153 | g4x_wm_sanitize(dev_priv); |
| 16154 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16155 | vlv_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 16156 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 16157 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16158 | skl_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 16159 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16160 | ilk_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 16161 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16162 | |
| 16163 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 16164 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16165 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16166 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 16167 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16168 | if (WARN_ON(put_domains)) |
| 16169 | modeset_put_power_domains(dev_priv, put_domains); |
| 16170 | } |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 16171 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 16172 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 16173 | |
| 16174 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16175 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 16176 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16177 | void intel_display_resume(struct drm_device *dev) |
| 16178 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16179 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 16180 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 16181 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16182 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 16183 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16184 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16185 | if (state) |
| 16186 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16187 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16188 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16189 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16190 | while (1) { |
| 16191 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 16192 | if (ret != -EDEADLK) |
| 16193 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16194 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16195 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16196 | } |
| 16197 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16198 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 16199 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16200 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 16201 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16202 | drm_modeset_drop_locks(&ctx); |
| 16203 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16204 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 16205 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16206 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 16207 | if (state) |
| 16208 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 16209 | } |
| 16210 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16211 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 16212 | { |
| 16213 | struct intel_connector *connector; |
| 16214 | struct drm_connector_list_iter conn_iter; |
| 16215 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 16216 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16217 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 16218 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 16219 | if (connector->modeset_retry_work.func) |
| 16220 | cancel_work_sync(&connector->modeset_retry_work); |
Ramalingam C | d3dacc7 | 2018-10-29 15:15:46 +0530 | [diff] [blame] | 16221 | if (connector->hdcp.shim) { |
| 16222 | cancel_delayed_work_sync(&connector->hdcp.check_work); |
| 16223 | cancel_work_sync(&connector->hdcp.prop_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 16224 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16225 | } |
| 16226 | drm_connector_list_iter_end(&conn_iter); |
| 16227 | } |
| 16228 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16229 | void intel_modeset_cleanup(struct drm_device *dev) |
| 16230 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16231 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 16232 | |
Chris Wilson | 8bcf9f7 | 2018-07-10 10:44:20 +0100 | [diff] [blame] | 16233 | flush_workqueue(dev_priv->modeset_wq); |
| 16234 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 16235 | flush_work(&dev_priv->atomic_helper.free_work); |
| 16236 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 16237 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16238 | /* |
| 16239 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 16240 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16241 | * experience fancy races otherwise. |
| 16242 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 16243 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 16244 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16245 | /* |
| 16246 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 16247 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 16248 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16249 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16250 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 16251 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 16252 | intel_fbdev_fini(dev_priv); |
| 16253 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 16254 | intel_unregister_dsm_handler(); |
| 16255 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 16256 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 16257 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 16258 | /* flush any delayed tasks or pending work */ |
| 16259 | flush_scheduled_work(); |
| 16260 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16261 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 16262 | |
José Roberto de Souza | 58db08a7 | 2018-11-07 16:16:47 -0800 | [diff] [blame] | 16263 | intel_overlay_cleanup(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16264 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 16265 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 16266 | |
| 16267 | destroy_workqueue(dev_priv->modeset_wq); |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 16268 | |
| 16269 | intel_fbc_cleanup_cfb(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16270 | } |
| 16271 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16272 | /* |
| 16273 | * set vga decode state - true == enable VGA decode |
| 16274 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16275 | int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state) |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16276 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16277 | unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16278 | u16 gmch_ctrl; |
| 16279 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16280 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 16281 | DRM_ERROR("failed to read control word\n"); |
| 16282 | return -EIO; |
| 16283 | } |
| 16284 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 16285 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 16286 | return 0; |
| 16287 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16288 | if (state) |
| 16289 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 16290 | else |
| 16291 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16292 | |
| 16293 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 16294 | DRM_ERROR("failed to write control word\n"); |
| 16295 | return -EIO; |
| 16296 | } |
| 16297 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16298 | return 0; |
| 16299 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16300 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16301 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 16302 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16303 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16304 | |
| 16305 | u32 power_well_driver; |
| 16306 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16307 | int num_transcoders; |
| 16308 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16309 | struct intel_cursor_error_state { |
| 16310 | u32 control; |
| 16311 | u32 position; |
| 16312 | u32 base; |
| 16313 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16314 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16315 | |
| 16316 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16317 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16318 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16319 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16320 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16321 | |
| 16322 | struct intel_plane_error_state { |
| 16323 | u32 control; |
| 16324 | u32 stride; |
| 16325 | u32 size; |
| 16326 | u32 pos; |
| 16327 | u32 addr; |
| 16328 | u32 surface; |
| 16329 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16330 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16331 | |
| 16332 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16333 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16334 | enum transcoder cpu_transcoder; |
| 16335 | |
| 16336 | u32 conf; |
| 16337 | |
| 16338 | u32 htotal; |
| 16339 | u32 hblank; |
| 16340 | u32 hsync; |
| 16341 | u32 vtotal; |
| 16342 | u32 vblank; |
| 16343 | u32 vsync; |
| 16344 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16345 | }; |
| 16346 | |
| 16347 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16348 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16349 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16350 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16351 | int transcoders[] = { |
| 16352 | TRANSCODER_A, |
| 16353 | TRANSCODER_B, |
| 16354 | TRANSCODER_C, |
| 16355 | TRANSCODER_EDP, |
| 16356 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16357 | int i; |
| 16358 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 16359 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16360 | return NULL; |
| 16361 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16362 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16363 | if (error == NULL) |
| 16364 | return NULL; |
| 16365 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16366 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 16367 | error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16368 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16369 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16370 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16371 | __intel_display_power_is_enabled(dev_priv, |
| 16372 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16373 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16374 | continue; |
| 16375 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16376 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16377 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16378 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16379 | |
| 16380 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16381 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16382 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16383 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16384 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16385 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16386 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16387 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16388 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16389 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16390 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16391 | } |
| 16392 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16393 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16394 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 16395 | if (HAS_GMCH(dev_priv)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16396 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16397 | } |
| 16398 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16399 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16400 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 16401 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16402 | error->num_transcoders++; /* Account for eDP. */ |
| 16403 | |
| 16404 | for (i = 0; i < error->num_transcoders; i++) { |
| 16405 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16406 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16407 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16408 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16409 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16410 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16411 | continue; |
| 16412 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16413 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16414 | |
| 16415 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16416 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16417 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16418 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16419 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16420 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16421 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16422 | } |
| 16423 | |
| 16424 | return error; |
| 16425 | } |
| 16426 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16427 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16428 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16429 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16430 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16431 | struct intel_display_error_state *error) |
| 16432 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 16433 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16434 | int i; |
| 16435 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16436 | if (!error) |
| 16437 | return; |
| 16438 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16439 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 16440 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16441 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16442 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16443 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16444 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16445 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16446 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16447 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16448 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16449 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16450 | err_printf(m, "Plane [%d]:\n", i); |
| 16451 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16452 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16453 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16454 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16455 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16456 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 16457 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16458 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16459 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16460 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16461 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16462 | } |
| 16463 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16464 | err_printf(m, "Cursor [%d]:\n", i); |
| 16465 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16466 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16467 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16468 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16469 | |
| 16470 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16471 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16472 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16473 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16474 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16475 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16476 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16477 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16478 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16479 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16480 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16481 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16482 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16483 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16484 | |
| 16485 | #endif |