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 | |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 32 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 33 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include "intel_drv.h" |
Chris Wilson | 5d723d7 | 2016-08-04 16:32:35 +0100 | [diff] [blame] | 36 | #include "intel_frontbuffer.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 38 | #include "i915_drv.h" |
Chris Wilson | 57822dc | 2017-02-22 11:40:48 +0000 | [diff] [blame] | 39 | #include "i915_gem_clflush.h" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 40 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 41 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 42 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 43 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 44 | #include <drm/drm_dp_helper.h> |
| 45 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 46 | #include <drm/drm_plane_helper.h> |
| 47 | #include <drm/drm_rect.h> |
Daniel Vetter | 72fdb40 | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 48 | #include <drm/drm_atomic_uapi.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 49 | #include <linux/dma_remapping.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 50 | #include <linux/reservation.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 51 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 52 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 53 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 54 | DRM_FORMAT_C8, |
| 55 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 56 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 57 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 61 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 62 | DRM_FORMAT_C8, |
| 63 | DRM_FORMAT_RGB565, |
| 64 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 65 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 66 | DRM_FORMAT_XRGB2101010, |
| 67 | DRM_FORMAT_XBGR2101010, |
| 68 | }; |
| 69 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 70 | static const uint64_t i9xx_format_modifiers[] = { |
| 71 | I915_FORMAT_MOD_X_TILED, |
| 72 | DRM_FORMAT_MOD_LINEAR, |
| 73 | DRM_FORMAT_MOD_INVALID |
| 74 | }; |
| 75 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 76 | /* Cursor formats */ |
| 77 | static const uint32_t intel_cursor_formats[] = { |
| 78 | DRM_FORMAT_ARGB8888, |
| 79 | }; |
| 80 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 81 | static const uint64_t cursor_format_modifiers[] = { |
| 82 | DRM_FORMAT_MOD_LINEAR, |
| 83 | DRM_FORMAT_MOD_INVALID |
| 84 | }; |
| 85 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 86 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 87 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 88 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 89 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 90 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 91 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
| 92 | struct drm_i915_gem_object *obj, |
| 93 | struct drm_mode_fb_cmd2 *mode_cmd); |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 94 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state); |
| 95 | 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] | 96 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 97 | const struct intel_link_m_n *m_n, |
| 98 | const struct intel_link_m_n *m2_n2); |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 99 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 100 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 101 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 102 | 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] | 103 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 104 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 105 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 106 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 107 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 108 | 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] | 109 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 110 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 111 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state); |
| 112 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state); |
| 113 | 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] | 114 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 115 | struct drm_modeset_acquire_ctx *ctx); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 116 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 117 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 118 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 119 | struct { |
| 120 | int min, max; |
| 121 | } dot, vco, n, m, m1, m2, p, p1; |
| 122 | |
| 123 | struct { |
| 124 | int dot_limit; |
| 125 | int p2_slow, p2_fast; |
| 126 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 127 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 128 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 129 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 130 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 131 | { |
| 132 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 133 | |
| 134 | /* Obtain SKU information */ |
| 135 | mutex_lock(&dev_priv->sb_lock); |
| 136 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 137 | CCK_FUSE_HPLL_FREQ_MASK; |
| 138 | mutex_unlock(&dev_priv->sb_lock); |
| 139 | |
| 140 | return vco_freq[hpll_freq] * 1000; |
| 141 | } |
| 142 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 143 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 144 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 145 | { |
| 146 | u32 val; |
| 147 | int divider; |
| 148 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 149 | mutex_lock(&dev_priv->sb_lock); |
| 150 | val = vlv_cck_read(dev_priv, reg); |
| 151 | mutex_unlock(&dev_priv->sb_lock); |
| 152 | |
| 153 | divider = val & CCK_FREQUENCY_VALUES; |
| 154 | |
| 155 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 156 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 157 | "%s change in progress\n", name); |
| 158 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 159 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 160 | } |
| 161 | |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 162 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 163 | const char *name, u32 reg) |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 164 | { |
| 165 | if (dev_priv->hpll_freq == 0) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 166 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 167 | |
| 168 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 169 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 170 | } |
| 171 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 172 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 173 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 174 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 175 | return; |
| 176 | |
| 177 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 178 | CCK_CZ_CLOCK_CONTROL); |
| 179 | |
| 180 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 181 | } |
| 182 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 183 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 184 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 185 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 186 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 187 | if (HAS_DDI(dev_priv)) |
| 188 | return pipe_config->port_clock; /* SPLL */ |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 189 | else |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 190 | return dev_priv->fdi_pll_freq; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 193 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 194 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 195 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 196 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 197 | .m = { .min = 96, .max = 140 }, |
| 198 | .m1 = { .min = 18, .max = 26 }, |
| 199 | .m2 = { .min = 6, .max = 16 }, |
| 200 | .p = { .min = 4, .max = 128 }, |
| 201 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 202 | .p2 = { .dot_limit = 165000, |
| 203 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 206 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 207 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 208 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 209 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 210 | .m = { .min = 96, .max = 140 }, |
| 211 | .m1 = { .min = 18, .max = 26 }, |
| 212 | .m2 = { .min = 6, .max = 16 }, |
| 213 | .p = { .min = 4, .max = 128 }, |
| 214 | .p1 = { .min = 2, .max = 33 }, |
| 215 | .p2 = { .dot_limit = 165000, |
| 216 | .p2_slow = 4, .p2_fast = 4 }, |
| 217 | }; |
| 218 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 219 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 220 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 221 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 222 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 223 | .m = { .min = 96, .max = 140 }, |
| 224 | .m1 = { .min = 18, .max = 26 }, |
| 225 | .m2 = { .min = 6, .max = 16 }, |
| 226 | .p = { .min = 4, .max = 128 }, |
| 227 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 228 | .p2 = { .dot_limit = 165000, |
| 229 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 230 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 231 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 232 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 233 | .dot = { .min = 20000, .max = 400000 }, |
| 234 | .vco = { .min = 1400000, .max = 2800000 }, |
| 235 | .n = { .min = 1, .max = 6 }, |
| 236 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 237 | .m1 = { .min = 8, .max = 18 }, |
| 238 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 239 | .p = { .min = 5, .max = 80 }, |
| 240 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 241 | .p2 = { .dot_limit = 200000, |
| 242 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 245 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 246 | .dot = { .min = 20000, .max = 400000 }, |
| 247 | .vco = { .min = 1400000, .max = 2800000 }, |
| 248 | .n = { .min = 1, .max = 6 }, |
| 249 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 250 | .m1 = { .min = 8, .max = 18 }, |
| 251 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 252 | .p = { .min = 7, .max = 98 }, |
| 253 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 254 | .p2 = { .dot_limit = 112000, |
| 255 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 258 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 259 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 260 | .dot = { .min = 25000, .max = 270000 }, |
| 261 | .vco = { .min = 1750000, .max = 3500000}, |
| 262 | .n = { .min = 1, .max = 4 }, |
| 263 | .m = { .min = 104, .max = 138 }, |
| 264 | .m1 = { .min = 17, .max = 23 }, |
| 265 | .m2 = { .min = 5, .max = 11 }, |
| 266 | .p = { .min = 10, .max = 30 }, |
| 267 | .p1 = { .min = 1, .max = 3}, |
| 268 | .p2 = { .dot_limit = 270000, |
| 269 | .p2_slow = 10, |
| 270 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 271 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 274 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 275 | .dot = { .min = 22000, .max = 400000 }, |
| 276 | .vco = { .min = 1750000, .max = 3500000}, |
| 277 | .n = { .min = 1, .max = 4 }, |
| 278 | .m = { .min = 104, .max = 138 }, |
| 279 | .m1 = { .min = 16, .max = 23 }, |
| 280 | .m2 = { .min = 5, .max = 11 }, |
| 281 | .p = { .min = 5, .max = 80 }, |
| 282 | .p1 = { .min = 1, .max = 8}, |
| 283 | .p2 = { .dot_limit = 165000, |
| 284 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 287 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 288 | .dot = { .min = 20000, .max = 115000 }, |
| 289 | .vco = { .min = 1750000, .max = 3500000 }, |
| 290 | .n = { .min = 1, .max = 3 }, |
| 291 | .m = { .min = 104, .max = 138 }, |
| 292 | .m1 = { .min = 17, .max = 23 }, |
| 293 | .m2 = { .min = 5, .max = 11 }, |
| 294 | .p = { .min = 28, .max = 112 }, |
| 295 | .p1 = { .min = 2, .max = 8 }, |
| 296 | .p2 = { .dot_limit = 0, |
| 297 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 298 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 299 | }; |
| 300 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 301 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 302 | .dot = { .min = 80000, .max = 224000 }, |
| 303 | .vco = { .min = 1750000, .max = 3500000 }, |
| 304 | .n = { .min = 1, .max = 3 }, |
| 305 | .m = { .min = 104, .max = 138 }, |
| 306 | .m1 = { .min = 17, .max = 23 }, |
| 307 | .m2 = { .min = 5, .max = 11 }, |
| 308 | .p = { .min = 14, .max = 42 }, |
| 309 | .p1 = { .min = 2, .max = 6 }, |
| 310 | .p2 = { .dot_limit = 0, |
| 311 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 312 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 315 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 316 | .dot = { .min = 20000, .max = 400000}, |
| 317 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 318 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 319 | .n = { .min = 3, .max = 6 }, |
| 320 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 321 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 322 | .m1 = { .min = 0, .max = 0 }, |
| 323 | .m2 = { .min = 0, .max = 254 }, |
| 324 | .p = { .min = 5, .max = 80 }, |
| 325 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 326 | .p2 = { .dot_limit = 200000, |
| 327 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 328 | }; |
| 329 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 330 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 331 | .dot = { .min = 20000, .max = 400000 }, |
| 332 | .vco = { .min = 1700000, .max = 3500000 }, |
| 333 | .n = { .min = 3, .max = 6 }, |
| 334 | .m = { .min = 2, .max = 256 }, |
| 335 | .m1 = { .min = 0, .max = 0 }, |
| 336 | .m2 = { .min = 0, .max = 254 }, |
| 337 | .p = { .min = 7, .max = 112 }, |
| 338 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 339 | .p2 = { .dot_limit = 112000, |
| 340 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 341 | }; |
| 342 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 343 | /* Ironlake / Sandybridge |
| 344 | * |
| 345 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 346 | * the range value for them is (actual_value - 2). |
| 347 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 348 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 349 | .dot = { .min = 25000, .max = 350000 }, |
| 350 | .vco = { .min = 1760000, .max = 3510000 }, |
| 351 | .n = { .min = 1, .max = 5 }, |
| 352 | .m = { .min = 79, .max = 127 }, |
| 353 | .m1 = { .min = 12, .max = 22 }, |
| 354 | .m2 = { .min = 5, .max = 9 }, |
| 355 | .p = { .min = 5, .max = 80 }, |
| 356 | .p1 = { .min = 1, .max = 8 }, |
| 357 | .p2 = { .dot_limit = 225000, |
| 358 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 361 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 362 | .dot = { .min = 25000, .max = 350000 }, |
| 363 | .vco = { .min = 1760000, .max = 3510000 }, |
| 364 | .n = { .min = 1, .max = 3 }, |
| 365 | .m = { .min = 79, .max = 118 }, |
| 366 | .m1 = { .min = 12, .max = 22 }, |
| 367 | .m2 = { .min = 5, .max = 9 }, |
| 368 | .p = { .min = 28, .max = 112 }, |
| 369 | .p1 = { .min = 2, .max = 8 }, |
| 370 | .p2 = { .dot_limit = 225000, |
| 371 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 372 | }; |
| 373 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 374 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 375 | .dot = { .min = 25000, .max = 350000 }, |
| 376 | .vco = { .min = 1760000, .max = 3510000 }, |
| 377 | .n = { .min = 1, .max = 3 }, |
| 378 | .m = { .min = 79, .max = 127 }, |
| 379 | .m1 = { .min = 12, .max = 22 }, |
| 380 | .m2 = { .min = 5, .max = 9 }, |
| 381 | .p = { .min = 14, .max = 56 }, |
| 382 | .p1 = { .min = 2, .max = 8 }, |
| 383 | .p2 = { .dot_limit = 225000, |
| 384 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 385 | }; |
| 386 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 387 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 388 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 389 | .dot = { .min = 25000, .max = 350000 }, |
| 390 | .vco = { .min = 1760000, .max = 3510000 }, |
| 391 | .n = { .min = 1, .max = 2 }, |
| 392 | .m = { .min = 79, .max = 126 }, |
| 393 | .m1 = { .min = 12, .max = 22 }, |
| 394 | .m2 = { .min = 5, .max = 9 }, |
| 395 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 396 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 397 | .p2 = { .dot_limit = 225000, |
| 398 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 399 | }; |
| 400 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 401 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 402 | .dot = { .min = 25000, .max = 350000 }, |
| 403 | .vco = { .min = 1760000, .max = 3510000 }, |
| 404 | .n = { .min = 1, .max = 3 }, |
| 405 | .m = { .min = 79, .max = 126 }, |
| 406 | .m1 = { .min = 12, .max = 22 }, |
| 407 | .m2 = { .min = 5, .max = 9 }, |
| 408 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 409 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 410 | .p2 = { .dot_limit = 225000, |
| 411 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 412 | }; |
| 413 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 414 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 415 | /* |
| 416 | * These are the data rate limits (measured in fast clocks) |
| 417 | * since those are the strictest limits we have. The fast |
| 418 | * clock and actual rate limits are more relaxed, so checking |
| 419 | * them would make no difference. |
| 420 | */ |
| 421 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 422 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 423 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 424 | .m1 = { .min = 2, .max = 3 }, |
| 425 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 426 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 427 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 430 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 431 | /* |
| 432 | * These are the data rate limits (measured in fast clocks) |
| 433 | * since those are the strictest limits we have. The fast |
| 434 | * clock and actual rate limits are more relaxed, so checking |
| 435 | * them would make no difference. |
| 436 | */ |
| 437 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 438 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 439 | .n = { .min = 1, .max = 1 }, |
| 440 | .m1 = { .min = 2, .max = 2 }, |
| 441 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 442 | .p1 = { .min = 2, .max = 4 }, |
| 443 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 444 | }; |
| 445 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 446 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 447 | /* FIXME: find real dot limits */ |
| 448 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 449 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 450 | .n = { .min = 1, .max = 1 }, |
| 451 | .m1 = { .min = 2, .max = 2 }, |
| 452 | /* FIXME: find real m2 limits */ |
| 453 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 454 | .p1 = { .min = 2, .max = 4 }, |
| 455 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 456 | }; |
| 457 | |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 458 | static void |
| 459 | skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 460 | { |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 461 | if (enable) |
| 462 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 463 | DUPS1_GATING_DIS | DUPS2_GATING_DIS); |
| 464 | else |
| 465 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 466 | I915_READ(CLKGATE_DIS_PSL(pipe)) & |
| 467 | ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); |
| 468 | } |
| 469 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 470 | static bool |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 471 | needs_modeset(const struct drm_crtc_state *state) |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 472 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 473 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 476 | /* |
| 477 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 478 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 479 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 480 | * The helpers' return value is the rate of the clock that is fed to the |
| 481 | * display engine's pipe which can be the above fast dot clock rate or a |
| 482 | * divided-down version of it. |
| 483 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 484 | /* 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] | 485 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 486 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 487 | clock->m = clock->m2 + 2; |
| 488 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 489 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 490 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 491 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 492 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 493 | |
| 494 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 495 | } |
| 496 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 497 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 498 | { |
| 499 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 500 | } |
| 501 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 502 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 503 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 504 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 505 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 506 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 507 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 508 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 509 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 510 | |
| 511 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 514 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 515 | { |
| 516 | clock->m = clock->m1 * clock->m2; |
| 517 | clock->p = clock->p1 * clock->p2; |
| 518 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 519 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 520 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 521 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 522 | |
| 523 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 524 | } |
| 525 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 526 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 527 | { |
| 528 | clock->m = clock->m1 * clock->m2; |
| 529 | clock->p = clock->p1 * clock->p2; |
| 530 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 531 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 532 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 533 | clock->n << 22); |
| 534 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 535 | |
| 536 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 537 | } |
| 538 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 539 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 540 | |
| 541 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 542 | * Returns whether the given set of divisors are valid for a given refclk with |
| 543 | * the given connectors. |
| 544 | */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 545 | 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] | 546 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 547 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 548 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 549 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 550 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 551 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 552 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 553 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 554 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 555 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 556 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 557 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 558 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 559 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 560 | if (clock->m1 <= clock->m2) |
| 561 | INTELPllInvalid("m1 <= m2\n"); |
| 562 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 563 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 564 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 565 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 566 | INTELPllInvalid("p out of range\n"); |
| 567 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 568 | INTELPllInvalid("m out of range\n"); |
| 569 | } |
| 570 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 571 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 572 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 573 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 574 | * connector, etc., rather than just a single range. |
| 575 | */ |
| 576 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 577 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 578 | |
| 579 | return true; |
| 580 | } |
| 581 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 582 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 583 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 584 | const struct intel_crtc_state *crtc_state, |
| 585 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 586 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 587 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 588 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 589 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 590 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 591 | * For LVDS just rely on its current settings for dual-channel. |
| 592 | * We haven't figured out how to reliably set up different |
| 593 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 594 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 595 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 596 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 597 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 598 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | } else { |
| 600 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 601 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 602 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 603 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 604 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 605 | } |
| 606 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 607 | /* |
| 608 | * Returns a set of divisors for the desired target clock with the given |
| 609 | * refclk, or FALSE. The returned values represent the clock equation: |
| 610 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 611 | * |
| 612 | * Target and reference clocks are specified in kHz. |
| 613 | * |
| 614 | * If match_clock is provided, then best_clock P divider must match the P |
| 615 | * divider from @match_clock used for LVDS downclocking. |
| 616 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 617 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 618 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 619 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 620 | int target, int refclk, struct dpll *match_clock, |
| 621 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 622 | { |
| 623 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 624 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 625 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 626 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 627 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 628 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 629 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 630 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 631 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 632 | clock.m1++) { |
| 633 | for (clock.m2 = limit->m2.min; |
| 634 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 635 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 636 | break; |
| 637 | for (clock.n = limit->n.min; |
| 638 | clock.n <= limit->n.max; clock.n++) { |
| 639 | for (clock.p1 = limit->p1.min; |
| 640 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 641 | int this_err; |
| 642 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 643 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 644 | if (!intel_PLL_is_valid(to_i915(dev), |
| 645 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 646 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 647 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 648 | if (match_clock && |
| 649 | clock.p != match_clock->p) |
| 650 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 651 | |
| 652 | this_err = abs(clock.dot - target); |
| 653 | if (this_err < err) { |
| 654 | *best_clock = clock; |
| 655 | err = this_err; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | return (err != target); |
| 663 | } |
| 664 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 665 | /* |
| 666 | * Returns a set of divisors for the desired target clock with the given |
| 667 | * refclk, or FALSE. The returned values represent the clock equation: |
| 668 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 669 | * |
| 670 | * Target and reference clocks are specified in kHz. |
| 671 | * |
| 672 | * If match_clock is provided, then best_clock P divider must match the P |
| 673 | * divider from @match_clock used for LVDS downclocking. |
| 674 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 675 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 676 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 677 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 678 | int target, int refclk, struct dpll *match_clock, |
| 679 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 680 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 681 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 682 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 683 | int err = target; |
| 684 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 685 | memset(best_clock, 0, sizeof(*best_clock)); |
| 686 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 687 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 688 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 689 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 690 | clock.m1++) { |
| 691 | for (clock.m2 = limit->m2.min; |
| 692 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 693 | for (clock.n = limit->n.min; |
| 694 | clock.n <= limit->n.max; clock.n++) { |
| 695 | for (clock.p1 = limit->p1.min; |
| 696 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 697 | int this_err; |
| 698 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 699 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 700 | if (!intel_PLL_is_valid(to_i915(dev), |
| 701 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 702 | &clock)) |
| 703 | continue; |
| 704 | if (match_clock && |
| 705 | clock.p != match_clock->p) |
| 706 | continue; |
| 707 | |
| 708 | this_err = abs(clock.dot - target); |
| 709 | if (this_err < err) { |
| 710 | *best_clock = clock; |
| 711 | err = this_err; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | return (err != target); |
| 719 | } |
| 720 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 721 | /* |
| 722 | * Returns a set of divisors for the desired target clock with the given |
| 723 | * refclk, or FALSE. The returned values represent the clock equation: |
| 724 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 725 | * |
| 726 | * Target and reference clocks are specified in kHz. |
| 727 | * |
| 728 | * If match_clock is provided, then best_clock P divider must match the P |
| 729 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 730 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 731 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 732 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 733 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 734 | int target, int refclk, struct dpll *match_clock, |
| 735 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 736 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 737 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 738 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 739 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 740 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 741 | /* approximately equals target * 0.00585 */ |
| 742 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 743 | |
| 744 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 745 | |
| 746 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 747 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 748 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 749 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 750 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 751 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 752 | for (clock.m1 = limit->m1.max; |
| 753 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 754 | for (clock.m2 = limit->m2.max; |
| 755 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 756 | for (clock.p1 = limit->p1.max; |
| 757 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 758 | int this_err; |
| 759 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 760 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 761 | if (!intel_PLL_is_valid(to_i915(dev), |
| 762 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 763 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 764 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 765 | |
| 766 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 767 | if (this_err < err_most) { |
| 768 | *best_clock = clock; |
| 769 | err_most = this_err; |
| 770 | max_n = clock.n; |
| 771 | found = true; |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 777 | return found; |
| 778 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 779 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 780 | /* |
| 781 | * Check if the calculated PLL configuration is more optimal compared to the |
| 782 | * best configuration and error found so far. Return the calculated error. |
| 783 | */ |
| 784 | 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] | 785 | const struct dpll *calculated_clock, |
| 786 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 787 | unsigned int best_error_ppm, |
| 788 | unsigned int *error_ppm) |
| 789 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 790 | /* |
| 791 | * For CHV ignore the error and consider only the P value. |
| 792 | * Prefer a bigger P value based on HW requirements. |
| 793 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 794 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 795 | *error_ppm = 0; |
| 796 | |
| 797 | return calculated_clock->p > best_clock->p; |
| 798 | } |
| 799 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 800 | if (WARN_ON_ONCE(!target_freq)) |
| 801 | return false; |
| 802 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 803 | *error_ppm = div_u64(1000000ULL * |
| 804 | abs(target_freq - calculated_clock->dot), |
| 805 | target_freq); |
| 806 | /* |
| 807 | * Prefer a better P value over a better (smaller) error if the error |
| 808 | * is small. Ensure this preference for future configurations too by |
| 809 | * setting the error to 0. |
| 810 | */ |
| 811 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 812 | *error_ppm = 0; |
| 813 | |
| 814 | return true; |
| 815 | } |
| 816 | |
| 817 | return *error_ppm + 10 < best_error_ppm; |
| 818 | } |
| 819 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 820 | /* |
| 821 | * Returns a set of divisors for the desired target clock with the given |
| 822 | * refclk, or FALSE. The returned values represent the clock equation: |
| 823 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 824 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 825 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 826 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 827 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 828 | int target, int refclk, struct dpll *match_clock, |
| 829 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 830 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 831 | 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] | 832 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 833 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 834 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 835 | /* min update 19.2 MHz */ |
| 836 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 837 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 838 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 839 | target *= 5; /* fast clock */ |
| 840 | |
| 841 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 842 | |
| 843 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 844 | 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] | 845 | 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] | 846 | 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] | 847 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 848 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 849 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 850 | 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] | 851 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 852 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 853 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 854 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 855 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 856 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 857 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 858 | if (!intel_PLL_is_valid(to_i915(dev), |
| 859 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 860 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 861 | continue; |
| 862 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 863 | if (!vlv_PLL_is_optimal(dev, target, |
| 864 | &clock, |
| 865 | best_clock, |
| 866 | bestppm, &ppm)) |
| 867 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 868 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 869 | *best_clock = clock; |
| 870 | bestppm = ppm; |
| 871 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | } |
| 875 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 876 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 877 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 878 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 879 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 880 | /* |
| 881 | * Returns a set of divisors for the desired target clock with the given |
| 882 | * refclk, or FALSE. The returned values represent the clock equation: |
| 883 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 884 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 885 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 886 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 887 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 888 | int target, int refclk, struct dpll *match_clock, |
| 889 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 890 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 891 | 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] | 892 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 893 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 894 | struct dpll clock; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 895 | uint64_t m2; |
| 896 | int found = false; |
| 897 | |
| 898 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 899 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 900 | |
| 901 | /* |
| 902 | * Based on hardware doc, the n always set to 1, and m1 always |
| 903 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 904 | * revisit this because n may not 1 anymore. |
| 905 | */ |
| 906 | clock.n = 1, clock.m1 = 2; |
| 907 | target *= 5; /* fast clock */ |
| 908 | |
| 909 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 910 | for (clock.p2 = limit->p2.p2_fast; |
| 911 | clock.p2 >= limit->p2.p2_slow; |
| 912 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 913 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 914 | |
| 915 | clock.p = clock.p1 * clock.p2; |
| 916 | |
| 917 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 918 | clock.n) << 22, refclk * clock.m1); |
| 919 | |
| 920 | if (m2 > INT_MAX/clock.m1) |
| 921 | continue; |
| 922 | |
| 923 | clock.m2 = m2; |
| 924 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 925 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 926 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 927 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 928 | continue; |
| 929 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 930 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 931 | best_error_ppm, &error_ppm)) |
| 932 | continue; |
| 933 | |
| 934 | *best_clock = clock; |
| 935 | best_error_ppm = error_ppm; |
| 936 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
| 940 | return found; |
| 941 | } |
| 942 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 943 | 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] | 944 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 945 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 946 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 947 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 948 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 949 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 950 | target_clock, refclk, NULL, best_clock); |
| 951 | } |
| 952 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 953 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 954 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 955 | /* Be paranoid as we can arrive here with only partial |
| 956 | * state retrieved from the hardware during setup. |
| 957 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 958 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 959 | * as Haswell has gained clock readout/fastboot support. |
| 960 | * |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 961 | * 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] | 962 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 963 | * |
| 964 | * FIXME: The intel_crtc->active here should be switched to |
| 965 | * crtc->state->active once we have proper CRTC states wired up |
| 966 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 967 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 968 | return crtc->active && crtc->base.primary->state->fb && |
| 969 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 970 | } |
| 971 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 972 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 973 | enum pipe pipe) |
| 974 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 975 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 976 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 977 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 978 | } |
| 979 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 980 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
| 981 | enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 982 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 983 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 984 | u32 line1, line2; |
| 985 | u32 line_mask; |
| 986 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 987 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 988 | line_mask = DSL_LINEMASK_GEN2; |
| 989 | else |
| 990 | line_mask = DSL_LINEMASK_GEN3; |
| 991 | |
| 992 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 993 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 994 | line2 = I915_READ(reg) & line_mask; |
| 995 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 996 | return line1 != line2; |
| 997 | } |
| 998 | |
| 999 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) |
| 1000 | { |
| 1001 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1002 | enum pipe pipe = crtc->pipe; |
| 1003 | |
| 1004 | /* Wait for the display line to settle/start moving */ |
| 1005 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) |
| 1006 | DRM_ERROR("pipe %c scanline %s wait timed out\n", |
| 1007 | pipe_name(pipe), onoff(state)); |
| 1008 | } |
| 1009 | |
| 1010 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) |
| 1011 | { |
| 1012 | wait_for_pipe_scanline_moving(crtc, false); |
| 1013 | } |
| 1014 | |
| 1015 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) |
| 1016 | { |
| 1017 | wait_for_pipe_scanline_moving(crtc, true); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1018 | } |
| 1019 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1020 | static void |
| 1021 | 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] | 1022 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1023 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1024 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1025 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1026 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1027 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1028 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1029 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1030 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1031 | if (intel_wait_for_register(dev_priv, |
| 1032 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1033 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1034 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1035 | } else { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1036 | intel_wait_for_pipe_scanline_stopped(crtc); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1037 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1040 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1041 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1042 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1043 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1044 | u32 val; |
| 1045 | bool cur_state; |
| 1046 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1047 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1048 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1049 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1050 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1051 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1052 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1053 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1054 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1055 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1056 | { |
| 1057 | u32 val; |
| 1058 | bool cur_state; |
| 1059 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1060 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1061 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1062 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1063 | |
| 1064 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1065 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1066 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1067 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1068 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1069 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1070 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1071 | enum pipe pipe, bool state) |
| 1072 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1073 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1074 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1075 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1076 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1077 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1078 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1079 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1080 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1081 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1082 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1083 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1084 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1085 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1086 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1087 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1088 | } |
| 1089 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1090 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1091 | |
| 1092 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1093 | enum pipe pipe, bool state) |
| 1094 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1095 | u32 val; |
| 1096 | bool cur_state; |
| 1097 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1098 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1099 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1100 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1101 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1102 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1103 | } |
| 1104 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1105 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1106 | |
| 1107 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1108 | enum pipe pipe) |
| 1109 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1110 | u32 val; |
| 1111 | |
| 1112 | /* ILK FDI PLL is always enabled */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1113 | if (IS_GEN(dev_priv, 5)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1114 | return; |
| 1115 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1116 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1117 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1118 | return; |
| 1119 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1120 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1121 | 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] | 1122 | } |
| 1123 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1124 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1125 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1126 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1127 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1128 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1129 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1130 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1131 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1132 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1133 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1134 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1137 | 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] | 1138 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1139 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1140 | u32 val; |
Ville Syrjälä | 10ed55e | 2018-05-23 17:57:18 +0300 | [diff] [blame] | 1141 | enum pipe panel_pipe = INVALID_PIPE; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1142 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1143 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1144 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1145 | return; |
| 1146 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1147 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1148 | u32 port_sel; |
| 1149 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1150 | pp_reg = PP_CONTROL(0); |
| 1151 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1152 | |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1153 | switch (port_sel) { |
| 1154 | case PANEL_PORT_SELECT_LVDS: |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1155 | intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe); |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1156 | break; |
| 1157 | case PANEL_PORT_SELECT_DPA: |
| 1158 | intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe); |
| 1159 | break; |
| 1160 | case PANEL_PORT_SELECT_DPC: |
| 1161 | intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe); |
| 1162 | break; |
| 1163 | case PANEL_PORT_SELECT_DPD: |
| 1164 | intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe); |
| 1165 | break; |
| 1166 | default: |
| 1167 | MISSING_CASE(port_sel); |
| 1168 | break; |
| 1169 | } |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1170 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1171 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1172 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1173 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1174 | } else { |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1175 | u32 port_sel; |
| 1176 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1177 | pp_reg = PP_CONTROL(0); |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1178 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
| 1179 | |
| 1180 | WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS); |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1181 | intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | val = I915_READ(pp_reg); |
| 1185 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1186 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1187 | locked = false; |
| 1188 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1189 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1190 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1191 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1194 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1195 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1196 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1197 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1198 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1199 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1200 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1201 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1202 | /* we keep both pipes enabled on 830 */ |
| 1203 | if (IS_I830(dev_priv)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1204 | state = true; |
| 1205 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1206 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1207 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1208 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1209 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1210 | |
| 1211 | intel_display_power_put(dev_priv, power_domain); |
| 1212 | } else { |
| 1213 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1216 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1217 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1218 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1221 | static void assert_plane(struct intel_plane *plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1222 | { |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 1223 | enum pipe pipe; |
| 1224 | bool cur_state; |
| 1225 | |
| 1226 | cur_state = plane->get_hw_state(plane, &pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1227 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1228 | I915_STATE_WARN(cur_state != state, |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1229 | "%s assertion failure (expected %s, current %s)\n", |
| 1230 | plane->base.name, onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1231 | } |
| 1232 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1233 | #define assert_plane_enabled(p) assert_plane(p, true) |
| 1234 | #define assert_plane_disabled(p) assert_plane(p, false) |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1235 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1236 | static void assert_planes_disabled(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1237 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1238 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1239 | struct intel_plane *plane; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1240 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1241 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
| 1242 | assert_plane_disabled(plane); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1245 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1246 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1247 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1248 | drm_crtc_vblank_put(crtc); |
| 1249 | } |
| 1250 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1251 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1252 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1253 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1254 | u32 val; |
| 1255 | bool enabled; |
| 1256 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1257 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1258 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1259 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1260 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1261 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1264 | 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] | 1265 | enum pipe pipe, enum port port, |
| 1266 | i915_reg_t dp_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1267 | { |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1268 | enum pipe port_pipe; |
| 1269 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1270 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1271 | state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe); |
| 1272 | |
| 1273 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1274 | "PCH DP %c enabled on transcoder %c, should be disabled\n", |
| 1275 | port_name(port), pipe_name(pipe)); |
| 1276 | |
| 1277 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1278 | "IBX PCH DP %c still using transcoder B\n", |
| 1279 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | 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] | 1283 | enum pipe pipe, enum port port, |
| 1284 | i915_reg_t hdmi_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1285 | { |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1286 | enum pipe port_pipe; |
| 1287 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1288 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1289 | state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe); |
| 1290 | |
| 1291 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1292 | "PCH HDMI %c enabled on transcoder %c, should be disabled\n", |
| 1293 | port_name(port), pipe_name(pipe)); |
| 1294 | |
| 1295 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1296 | "IBX PCH HDMI %c still using transcoder B\n", |
| 1297 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1301 | enum pipe pipe) |
| 1302 | { |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1303 | enum pipe port_pipe; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1304 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1305 | assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B); |
| 1306 | assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C); |
| 1307 | assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1308 | |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1309 | I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) && |
| 1310 | port_pipe == pipe, |
| 1311 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
| 1312 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1313 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1314 | I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) && |
| 1315 | port_pipe == pipe, |
| 1316 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
| 1317 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1318 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 1319 | /* PCH SDVOB multiplex with HDMIB */ |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1320 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB); |
| 1321 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC); |
| 1322 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1323 | } |
| 1324 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1325 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1326 | const struct intel_crtc_state *pipe_config) |
| 1327 | { |
| 1328 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1329 | enum pipe pipe = crtc->pipe; |
| 1330 | |
| 1331 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1332 | POSTING_READ(DPLL(pipe)); |
| 1333 | udelay(150); |
| 1334 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1335 | if (intel_wait_for_register(dev_priv, |
| 1336 | DPLL(pipe), |
| 1337 | DPLL_LOCK_VLV, |
| 1338 | DPLL_LOCK_VLV, |
| 1339 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1340 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1341 | } |
| 1342 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1343 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1344 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1345 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1346 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1347 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1348 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1349 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1350 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1351 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1352 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1353 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1354 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1355 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1356 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1357 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1358 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1359 | } |
| 1360 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1361 | |
| 1362 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1363 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1364 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1365 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1366 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1367 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1368 | u32 tmp; |
| 1369 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1370 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1371 | |
| 1372 | /* Enable back the 10bit clock to display controller */ |
| 1373 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1374 | tmp |= DPIO_DCLKP_EN; |
| 1375 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1376 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1377 | mutex_unlock(&dev_priv->sb_lock); |
| 1378 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1379 | /* |
| 1380 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1381 | */ |
| 1382 | udelay(1); |
| 1383 | |
| 1384 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1385 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1386 | |
| 1387 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1388 | if (intel_wait_for_register(dev_priv, |
| 1389 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1390 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1391 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1395 | const struct intel_crtc_state *pipe_config) |
| 1396 | { |
| 1397 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1398 | enum pipe pipe = crtc->pipe; |
| 1399 | |
| 1400 | assert_pipe_disabled(dev_priv, pipe); |
| 1401 | |
| 1402 | /* PLL is protected by panel, make sure we can write it */ |
| 1403 | assert_panel_unlocked(dev_priv, pipe); |
| 1404 | |
| 1405 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1406 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1407 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1408 | if (pipe != PIPE_A) { |
| 1409 | /* |
| 1410 | * WaPixelRepeatModeFixForC0:chv |
| 1411 | * |
| 1412 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1413 | * the value from DPLLBMD to either pipe B or C. |
| 1414 | */ |
Ville Syrjälä | dfa311f | 2017-09-13 17:08:54 +0300 | [diff] [blame] | 1415 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1416 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1417 | I915_WRITE(CBR4_VLV, 0); |
| 1418 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1419 | |
| 1420 | /* |
| 1421 | * DPLLB VGA mode also seems to cause problems. |
| 1422 | * We should always have it disabled. |
| 1423 | */ |
| 1424 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1425 | } else { |
| 1426 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1427 | POSTING_READ(DPLL_MD(pipe)); |
| 1428 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1429 | } |
| 1430 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1431 | 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] | 1432 | { |
| 1433 | struct intel_crtc *crtc; |
| 1434 | int count = 0; |
| 1435 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1436 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1437 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1438 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1439 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1440 | |
| 1441 | return count; |
| 1442 | } |
| 1443 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1444 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
| 1445 | const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1446 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1447 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1448 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1449 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1450 | int i; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1451 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1452 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1453 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1454 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1455 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1456 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1457 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1458 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1459 | 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] | 1460 | /* |
| 1461 | * It appears to be important that we don't enable this |
| 1462 | * for the current pipe before otherwise configuring the |
| 1463 | * PLL. No idea how this should be handled if multiple |
| 1464 | * DVO outputs are enabled simultaneosly. |
| 1465 | */ |
| 1466 | dpll |= DPLL_DVO_2X_MODE; |
| 1467 | I915_WRITE(DPLL(!crtc->pipe), |
| 1468 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1469 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1470 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1471 | /* |
| 1472 | * Apparently we need to have VGA mode enabled prior to changing |
| 1473 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1474 | * dividers, even though the register value does change. |
| 1475 | */ |
| 1476 | I915_WRITE(reg, 0); |
| 1477 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1478 | I915_WRITE(reg, dpll); |
| 1479 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1480 | /* Wait for the clocks to stabilize. */ |
| 1481 | POSTING_READ(reg); |
| 1482 | udelay(150); |
| 1483 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1484 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1485 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1486 | crtc_state->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1487 | } else { |
| 1488 | /* The pixel multiplier can only be updated once the |
| 1489 | * DPLL is enabled and the clocks are stable. |
| 1490 | * |
| 1491 | * So write it again. |
| 1492 | */ |
| 1493 | I915_WRITE(reg, dpll); |
| 1494 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1495 | |
| 1496 | /* We do this three times for luck */ |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1497 | for (i = 0; i < 3; i++) { |
| 1498 | I915_WRITE(reg, dpll); |
| 1499 | POSTING_READ(reg); |
| 1500 | udelay(150); /* wait for warmup */ |
| 1501 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1504 | static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1505 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1506 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1507 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1508 | enum pipe pipe = crtc->pipe; |
| 1509 | |
| 1510 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1511 | if (IS_I830(dev_priv) && |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1512 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1513 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1514 | I915_WRITE(DPLL(PIPE_B), |
| 1515 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1516 | I915_WRITE(DPLL(PIPE_A), |
| 1517 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1518 | } |
| 1519 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1520 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1521 | if (IS_I830(dev_priv)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1522 | return; |
| 1523 | |
| 1524 | /* Make sure the pipe isn't still relying on us */ |
| 1525 | assert_pipe_disabled(dev_priv, pipe); |
| 1526 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1527 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1528 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1529 | } |
| 1530 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1531 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1532 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1533 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1534 | |
| 1535 | /* Make sure the pipe isn't still relying on us */ |
| 1536 | assert_pipe_disabled(dev_priv, pipe); |
| 1537 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1538 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1539 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1540 | if (pipe != PIPE_A) |
| 1541 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1542 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1543 | I915_WRITE(DPLL(pipe), val); |
| 1544 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1548 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1549 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1550 | u32 val; |
| 1551 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1552 | /* Make sure the pipe isn't still relying on us */ |
| 1553 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1554 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1555 | val = DPLL_SSC_REF_CLK_CHV | |
| 1556 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1557 | if (pipe != PIPE_A) |
| 1558 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1559 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1560 | I915_WRITE(DPLL(pipe), val); |
| 1561 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1562 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1563 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1564 | |
| 1565 | /* Disable 10bit clock to display controller */ |
| 1566 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1567 | val &= ~DPIO_DCLKP_EN; |
| 1568 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1569 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1570 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1573 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1574 | struct intel_digital_port *dport, |
| 1575 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1576 | { |
| 1577 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1578 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1579 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1580 | switch (dport->base.port) { |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1581 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1582 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1583 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1584 | break; |
| 1585 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1586 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1587 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1588 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1589 | break; |
| 1590 | case PORT_D: |
| 1591 | port_mask = DPLL_PORTD_READY_MASK; |
| 1592 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1593 | break; |
| 1594 | default: |
| 1595 | BUG(); |
| 1596 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1597 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1598 | if (intel_wait_for_register(dev_priv, |
| 1599 | dpll_reg, port_mask, expected_mask, |
| 1600 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1601 | 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] | 1602 | port_name(dport->base.port), |
| 1603 | I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1606 | 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] | 1607 | { |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1608 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1609 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1610 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1611 | i915_reg_t reg; |
| 1612 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1613 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1614 | /* Make sure PCH DPLL is enabled */ |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1615 | assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1616 | |
| 1617 | /* FDI must be feeding us bits for PCH ports */ |
| 1618 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1619 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1620 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1621 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1622 | /* Workaround: Set the timing override bit before enabling the |
| 1623 | * pch transcoder. */ |
| 1624 | reg = TRANS_CHICKEN2(pipe); |
| 1625 | val = I915_READ(reg); |
| 1626 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1627 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1628 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1629 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1630 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1631 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1632 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1633 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1634 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1635 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1636 | * Make the BPC in transcoder be consistent with |
| 1637 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1638 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1639 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1640 | val &= ~PIPECONF_BPC_MASK; |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1641 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1642 | val |= PIPECONF_8BPC; |
| 1643 | else |
| 1644 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1645 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1646 | |
| 1647 | val &= ~TRANS_INTERLACE_MASK; |
| 1648 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1649 | if (HAS_PCH_IBX(dev_priv) && |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1650 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1651 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1652 | else |
| 1653 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1654 | else |
| 1655 | val |= TRANS_PROGRESSIVE; |
| 1656 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1657 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1658 | if (intel_wait_for_register(dev_priv, |
| 1659 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1660 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1661 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1662 | } |
| 1663 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1664 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1665 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1666 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1667 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1668 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1669 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1670 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1671 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1672 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1673 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1674 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1675 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1676 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1677 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1678 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1679 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1680 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1681 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1682 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1683 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1684 | else |
| 1685 | val |= TRANS_PROGRESSIVE; |
| 1686 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1687 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1688 | if (intel_wait_for_register(dev_priv, |
| 1689 | LPT_TRANSCONF, |
| 1690 | TRANS_STATE_ENABLE, |
| 1691 | TRANS_STATE_ENABLE, |
| 1692 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1693 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1694 | } |
| 1695 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1696 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1697 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1698 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1699 | i915_reg_t reg; |
| 1700 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1701 | |
| 1702 | /* FDI relies on the transcoder */ |
| 1703 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1704 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1705 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1706 | /* Ports must be off as well */ |
| 1707 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1708 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1709 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1710 | val = I915_READ(reg); |
| 1711 | val &= ~TRANS_ENABLE; |
| 1712 | I915_WRITE(reg, val); |
| 1713 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1714 | if (intel_wait_for_register(dev_priv, |
| 1715 | reg, TRANS_STATE_ENABLE, 0, |
| 1716 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1717 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1718 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1719 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1720 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1721 | reg = TRANS_CHICKEN2(pipe); |
| 1722 | val = I915_READ(reg); |
| 1723 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1724 | I915_WRITE(reg, val); |
| 1725 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1726 | } |
| 1727 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1728 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1729 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1730 | u32 val; |
| 1731 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1732 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1733 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1734 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1735 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1736 | if (intel_wait_for_register(dev_priv, |
| 1737 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1738 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1739 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1740 | |
| 1741 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1742 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1743 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1744 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1745 | } |
| 1746 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1747 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1748 | { |
| 1749 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1750 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1751 | if (HAS_PCH_LPT(dev_priv)) |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1752 | return PIPE_A; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1753 | else |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1754 | return crtc->pipe; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1755 | } |
| 1756 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1757 | 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] | 1758 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1759 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1760 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1761 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1762 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1763 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1764 | u32 val; |
| 1765 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1766 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1767 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1768 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1769 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1770 | /* |
| 1771 | * A pipe without a PLL won't actually be able to drive bits from |
| 1772 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1773 | * need the check. |
| 1774 | */ |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1775 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1776 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1777 | assert_dsi_pll_enabled(dev_priv); |
| 1778 | else |
| 1779 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1780 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1781 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1782 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1783 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1784 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1785 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1786 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1787 | } |
| 1788 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1789 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1790 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1791 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1792 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1793 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1794 | /* we keep both pipes enabled on 830 */ |
| 1795 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1796 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1797 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1798 | |
| 1799 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1800 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1801 | |
| 1802 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1803 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1804 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1805 | * resets to its proper value. That also messes up the frame count |
| 1806 | * when it's derived from the timestamps. So let's wait for the |
| 1807 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1808 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1809 | if (dev_priv->drm.max_vblank_count == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1810 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1813 | 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] | 1814 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1815 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1816 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1817 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1818 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1819 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1820 | u32 val; |
| 1821 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1822 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1823 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1824 | /* |
| 1825 | * Make sure planes won't keep trying to pump pixels to us, |
| 1826 | * or we might hang the display. |
| 1827 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1828 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1829 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1830 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1831 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1832 | if ((val & PIPECONF_ENABLE) == 0) |
| 1833 | return; |
| 1834 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1835 | /* |
| 1836 | * Double wide has implications for planes |
| 1837 | * so best keep it disabled when not needed. |
| 1838 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1839 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1840 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1841 | |
| 1842 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1843 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1844 | val &= ~PIPECONF_ENABLE; |
| 1845 | |
| 1846 | I915_WRITE(reg, val); |
| 1847 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1848 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1849 | } |
| 1850 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1851 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1852 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1853 | return IS_GEN(dev_priv, 2) ? 2048 : 4096; |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1856 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1857 | 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] | 1858 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1859 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1860 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1861 | |
| 1862 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1863 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1864 | return cpp; |
| 1865 | case I915_FORMAT_MOD_X_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1866 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1867 | return 128; |
| 1868 | else |
| 1869 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1870 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1871 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1872 | return 128; |
| 1873 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1874 | case I915_FORMAT_MOD_Y_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1875 | 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] | 1876 | return 128; |
| 1877 | else |
| 1878 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1879 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1880 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1881 | return 128; |
| 1882 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1883 | case I915_FORMAT_MOD_Yf_TILED: |
| 1884 | switch (cpp) { |
| 1885 | case 1: |
| 1886 | return 64; |
| 1887 | case 2: |
| 1888 | case 4: |
| 1889 | return 128; |
| 1890 | case 8: |
| 1891 | case 16: |
| 1892 | return 256; |
| 1893 | default: |
| 1894 | MISSING_CASE(cpp); |
| 1895 | return cpp; |
| 1896 | } |
| 1897 | break; |
| 1898 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1899 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1900 | return cpp; |
| 1901 | } |
| 1902 | } |
| 1903 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1904 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1905 | intel_tile_height(const struct drm_framebuffer *fb, int color_plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1906 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1907 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1908 | return 1; |
| 1909 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1910 | return intel_tile_size(to_i915(fb->dev)) / |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1911 | intel_tile_width_bytes(fb, color_plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1914 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1915 | 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] | 1916 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1917 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1918 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1919 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane); |
| 1920 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1921 | |
| 1922 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1923 | *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] | 1924 | } |
| 1925 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1926 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1927 | intel_fb_align_height(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1928 | int color_plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1929 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1930 | unsigned int tile_height = intel_tile_height(fb, color_plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1931 | |
| 1932 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1933 | } |
| 1934 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1935 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1936 | { |
| 1937 | unsigned int size = 0; |
| 1938 | int i; |
| 1939 | |
| 1940 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1941 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1942 | |
| 1943 | return size; |
| 1944 | } |
| 1945 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 1946 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 1947 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 1948 | const struct drm_framebuffer *fb, |
| 1949 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 1950 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1951 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 1952 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1953 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 1954 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1958 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 1959 | { |
| 1960 | if (IS_I830(dev_priv)) |
| 1961 | return 16 * 1024; |
| 1962 | else if (IS_I85X(dev_priv)) |
| 1963 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 1964 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 1965 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1966 | else |
| 1967 | return 4 * 1024; |
| 1968 | } |
| 1969 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1970 | 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] | 1971 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1972 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1973 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 1974 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1975 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1976 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1977 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1978 | return 4 * 1024; |
| 1979 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 1980 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1981 | } |
| 1982 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1983 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1984 | int color_plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1985 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1986 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 1987 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 1988 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1989 | if (color_plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 1990 | return 4096; |
| 1991 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1992 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1993 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1994 | return intel_linear_alignment(dev_priv); |
| 1995 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1996 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1997 | return 256 * 1024; |
| 1998 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1999 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2000 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2001 | case I915_FORMAT_MOD_Y_TILED: |
| 2002 | case I915_FORMAT_MOD_Yf_TILED: |
| 2003 | return 1 * 1024 * 1024; |
| 2004 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2005 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2006 | return 0; |
| 2007 | } |
| 2008 | } |
| 2009 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2010 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2011 | { |
| 2012 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2013 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2014 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2015 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2018 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2019 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2020 | const struct i915_ggtt_view *view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2021 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2022 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2023 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2024 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2025 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2026 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2027 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2028 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2029 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2030 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2031 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2032 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2033 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2034 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2035 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2036 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2037 | * we should always have valid PTE following the scanout preventing |
| 2038 | * the VT-d warning. |
| 2039 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2040 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2041 | alignment = 256 * 1024; |
| 2042 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2043 | /* |
| 2044 | * Global gtt pte registers are special registers which actually forward |
| 2045 | * writes to a chunk of system memory. Which means that there is no risk |
| 2046 | * that the register values disappear as soon as we call |
| 2047 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2048 | * pin/unpin/fence and not more. |
| 2049 | */ |
| 2050 | intel_runtime_pm_get(dev_priv); |
| 2051 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2052 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2053 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2054 | pinctl = 0; |
| 2055 | |
| 2056 | /* Valleyview is definitely limited to scanning out the first |
| 2057 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2058 | * g4x display engine and that all earlier gen are similarly |
| 2059 | * limited. Testing suggests that it is a little more |
| 2060 | * complicated than this. For example, Cherryview appears quite |
| 2061 | * happy to scanout from anywhere within its global aperture. |
| 2062 | */ |
| 2063 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 2064 | pinctl |= PIN_MAPPABLE; |
| 2065 | |
| 2066 | vma = i915_gem_object_pin_to_display_plane(obj, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2067 | alignment, view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2068 | if (IS_ERR(vma)) |
| 2069 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2070 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2071 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2072 | int ret; |
| 2073 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2074 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2075 | * fence, whereas 965+ only requires a fence if using |
| 2076 | * framebuffer compression. For simplicity, we always, when |
| 2077 | * possible, install a fence as the cost is not that onerous. |
| 2078 | * |
| 2079 | * If we fail to fence the tiled scanout, then either the |
| 2080 | * modeset will reject the change (which is highly unlikely as |
| 2081 | * the affected systems, all but one, do not have unmappable |
| 2082 | * space) or we will not be able to enable full powersaving |
| 2083 | * techniques (also likely not to apply due to various limits |
| 2084 | * FBC and the like impose on the size of the buffer, which |
| 2085 | * presumably we violated anyway with this unmappable buffer). |
| 2086 | * Anyway, it is presumably better to stumble onwards with |
| 2087 | * something and try to run the system in a "less than optimal" |
| 2088 | * mode that matches the user configuration. |
| 2089 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2090 | ret = i915_vma_pin_fence(vma); |
| 2091 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2092 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2093 | vma = ERR_PTR(ret); |
| 2094 | goto err; |
| 2095 | } |
| 2096 | |
| 2097 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2098 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2099 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2100 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2101 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2102 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2103 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2104 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2105 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2106 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2107 | } |
| 2108 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2109 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2110 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2111 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2112 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2113 | if (flags & PLANE_HAS_FENCE) |
| 2114 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2115 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2116 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2119 | 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] | 2120 | unsigned int rotation) |
| 2121 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2122 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2123 | return to_intel_framebuffer(fb)->rotated[color_plane].pitch; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2124 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2125 | return fb->pitches[color_plane]; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2126 | } |
| 2127 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2128 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2129 | * Convert the x/y offsets into a linear offset. |
| 2130 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2131 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2132 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2133 | */ |
| 2134 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2135 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2136 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2137 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2138 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2139 | unsigned int cpp = fb->format->cpp[color_plane]; |
| 2140 | unsigned int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2141 | |
| 2142 | return y * pitch + x * cpp; |
| 2143 | } |
| 2144 | |
| 2145 | /* |
| 2146 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2147 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2148 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2149 | */ |
| 2150 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2151 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2152 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2153 | |
| 2154 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2155 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2156 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2157 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2158 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2159 | *x += intel_fb->rotated[color_plane].x; |
| 2160 | *y += intel_fb->rotated[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2161 | } else { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2162 | *x += intel_fb->normal[color_plane].x; |
| 2163 | *y += intel_fb->normal[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2164 | } |
| 2165 | } |
| 2166 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2167 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2168 | unsigned int tile_width, |
| 2169 | unsigned int tile_height, |
| 2170 | unsigned int tile_size, |
| 2171 | unsigned int pitch_tiles, |
| 2172 | u32 old_offset, |
| 2173 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2174 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2175 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2176 | unsigned int tiles; |
| 2177 | |
| 2178 | WARN_ON(old_offset & (tile_size - 1)); |
| 2179 | WARN_ON(new_offset & (tile_size - 1)); |
| 2180 | WARN_ON(new_offset > old_offset); |
| 2181 | |
| 2182 | tiles = (old_offset - new_offset) / tile_size; |
| 2183 | |
| 2184 | *y += tiles / pitch_tiles * tile_height; |
| 2185 | *x += tiles % pitch_tiles * tile_width; |
| 2186 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2187 | /* minimize x in case it got needlessly big */ |
| 2188 | *y += *x / pitch_pixels * tile_height; |
| 2189 | *x %= pitch_pixels; |
| 2190 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2191 | return new_offset; |
| 2192 | } |
| 2193 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2194 | static bool is_surface_linear(u64 modifier, int color_plane) |
| 2195 | { |
| 2196 | return modifier == DRM_FORMAT_MOD_LINEAR; |
| 2197 | } |
| 2198 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2199 | static u32 intel_adjust_aligned_offset(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2200 | const struct drm_framebuffer *fb, |
| 2201 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2202 | unsigned int rotation, |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2203 | unsigned int pitch, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2204 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2205 | { |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2206 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2207 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2208 | |
| 2209 | WARN_ON(new_offset > old_offset); |
| 2210 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2211 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2212 | unsigned int tile_size, tile_width, tile_height; |
| 2213 | unsigned int pitch_tiles; |
| 2214 | |
| 2215 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2216 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2217 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2218 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2219 | pitch_tiles = pitch / tile_height; |
| 2220 | swap(tile_width, tile_height); |
| 2221 | } else { |
| 2222 | pitch_tiles = pitch / (tile_width * cpp); |
| 2223 | } |
| 2224 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2225 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2226 | tile_size, pitch_tiles, |
| 2227 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2228 | } else { |
| 2229 | old_offset += *y * pitch + *x * cpp; |
| 2230 | |
| 2231 | *y = (old_offset - new_offset) / pitch; |
| 2232 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2233 | } |
| 2234 | |
| 2235 | return new_offset; |
| 2236 | } |
| 2237 | |
| 2238 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2239 | * Adjust the tile offset by moving the difference into |
| 2240 | * the x/y offsets. |
| 2241 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2242 | static u32 intel_plane_adjust_aligned_offset(int *x, int *y, |
| 2243 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2244 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2245 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2246 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2247 | 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] | 2248 | state->base.rotation, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2249 | state->color_plane[color_plane].stride, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2250 | old_offset, new_offset); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | /* |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2254 | * Computes the aligned offset to the base tile and adjusts |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2255 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2256 | * |
| 2257 | * In the 90/270 rotated case, x and y are assumed |
| 2258 | * to be already rotated to match the rotated GTT view, and |
| 2259 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2260 | * |
| 2261 | * This function is used when computing the derived information |
| 2262 | * under intel_framebuffer, so using any of that information |
| 2263 | * here is not allowed. Anything under drm_framebuffer can be |
| 2264 | * used. This is why the user has to pass in the pitch since it |
| 2265 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2266 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2267 | static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv, |
| 2268 | int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2269 | const struct drm_framebuffer *fb, |
| 2270 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2271 | unsigned int pitch, |
| 2272 | unsigned int rotation, |
| 2273 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2274 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2275 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2276 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2277 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2278 | if (alignment) |
| 2279 | alignment--; |
| 2280 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2281 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2282 | unsigned int tile_size, tile_width, tile_height; |
| 2283 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2284 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2285 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2286 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2287 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2288 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2289 | pitch_tiles = pitch / tile_height; |
| 2290 | swap(tile_width, tile_height); |
| 2291 | } else { |
| 2292 | pitch_tiles = pitch / (tile_width * cpp); |
| 2293 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2294 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2295 | tile_rows = *y / tile_height; |
| 2296 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2297 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2298 | tiles = *x / tile_width; |
| 2299 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2300 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2301 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2302 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2303 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2304 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2305 | tile_size, pitch_tiles, |
| 2306 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2307 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2308 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2309 | offset_aligned = offset & ~alignment; |
| 2310 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2311 | *y = (offset & alignment) / pitch; |
| 2312 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2313 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2314 | |
| 2315 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2316 | } |
| 2317 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2318 | static u32 intel_plane_compute_aligned_offset(int *x, int *y, |
| 2319 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2320 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2321 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2322 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2323 | 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] | 2324 | const struct drm_framebuffer *fb = state->base.fb; |
| 2325 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2326 | int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2327 | u32 alignment; |
| 2328 | |
| 2329 | if (intel_plane->id == PLANE_CURSOR) |
| 2330 | alignment = intel_cursor_alignment(dev_priv); |
| 2331 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2332 | alignment = intel_surf_alignment(fb, color_plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2333 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2334 | 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] | 2335 | pitch, rotation, alignment); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2336 | } |
| 2337 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2338 | /* Convert the fb->offset[] into x/y offsets */ |
| 2339 | static int intel_fb_offset_to_xy(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2340 | const struct drm_framebuffer *fb, |
| 2341 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2342 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2343 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2344 | unsigned int height; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2345 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2346 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2347 | fb->offsets[color_plane] % intel_tile_size(dev_priv)) { |
| 2348 | DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n", |
| 2349 | fb->offsets[color_plane], color_plane); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2350 | return -EINVAL; |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | height = drm_framebuffer_plane_height(fb->height, fb, color_plane); |
| 2354 | height = ALIGN(height, intel_tile_height(fb, color_plane)); |
| 2355 | |
| 2356 | /* Catch potential overflows early */ |
| 2357 | if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]), |
| 2358 | fb->offsets[color_plane])) { |
| 2359 | DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n", |
| 2360 | fb->offsets[color_plane], fb->pitches[color_plane], |
| 2361 | color_plane); |
| 2362 | return -ERANGE; |
| 2363 | } |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2364 | |
| 2365 | *x = 0; |
| 2366 | *y = 0; |
| 2367 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2368 | intel_adjust_aligned_offset(x, y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2369 | fb, color_plane, DRM_MODE_ROTATE_0, |
| 2370 | fb->pitches[color_plane], |
| 2371 | fb->offsets[color_plane], 0); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2372 | |
| 2373 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2374 | } |
| 2375 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2376 | static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier) |
| 2377 | { |
| 2378 | switch (fb_modifier) { |
| 2379 | case I915_FORMAT_MOD_X_TILED: |
| 2380 | return I915_TILING_X; |
| 2381 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2382 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2383 | return I915_TILING_Y; |
| 2384 | default: |
| 2385 | return I915_TILING_NONE; |
| 2386 | } |
| 2387 | } |
| 2388 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2389 | /* |
| 2390 | * From the Sky Lake PRM: |
| 2391 | * "The Color Control Surface (CCS) contains the compression status of |
| 2392 | * the cache-line pairs. The compression state of the cache-line pair |
| 2393 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2394 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2395 | * cache-line-pairs. CCS is always Y tiled." |
| 2396 | * |
| 2397 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2398 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2399 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2400 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2401 | * main surface. |
| 2402 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2403 | static const struct drm_format_info ccs_formats[] = { |
| 2404 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2405 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2406 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2407 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2408 | }; |
| 2409 | |
| 2410 | static const struct drm_format_info * |
| 2411 | lookup_format_info(const struct drm_format_info formats[], |
| 2412 | int num_formats, u32 format) |
| 2413 | { |
| 2414 | int i; |
| 2415 | |
| 2416 | for (i = 0; i < num_formats; i++) { |
| 2417 | if (formats[i].format == format) |
| 2418 | return &formats[i]; |
| 2419 | } |
| 2420 | |
| 2421 | return NULL; |
| 2422 | } |
| 2423 | |
| 2424 | static const struct drm_format_info * |
| 2425 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2426 | { |
| 2427 | switch (cmd->modifier[0]) { |
| 2428 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2429 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2430 | return lookup_format_info(ccs_formats, |
| 2431 | ARRAY_SIZE(ccs_formats), |
| 2432 | cmd->pixel_format); |
| 2433 | default: |
| 2434 | return NULL; |
| 2435 | } |
| 2436 | } |
| 2437 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2438 | bool is_ccs_modifier(u64 modifier) |
| 2439 | { |
| 2440 | return modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2441 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 2442 | } |
| 2443 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2444 | static int |
| 2445 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2446 | struct drm_framebuffer *fb) |
| 2447 | { |
| 2448 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2449 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2450 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2451 | u32 gtt_offset_rotated = 0; |
| 2452 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2453 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2454 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2455 | |
| 2456 | for (i = 0; i < num_planes; i++) { |
| 2457 | unsigned int width, height; |
| 2458 | unsigned int cpp, size; |
| 2459 | u32 offset; |
| 2460 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2461 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2462 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2463 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2464 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2465 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2466 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2467 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2468 | if (ret) { |
| 2469 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2470 | i, fb->offsets[i]); |
| 2471 | return ret; |
| 2472 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2473 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2474 | if (is_ccs_modifier(fb->modifier) && i == 1) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2475 | int hsub = fb->format->hsub; |
| 2476 | int vsub = fb->format->vsub; |
| 2477 | int tile_width, tile_height; |
| 2478 | int main_x, main_y; |
| 2479 | int ccs_x, ccs_y; |
| 2480 | |
| 2481 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2482 | tile_width *= hsub; |
| 2483 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2484 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2485 | ccs_x = (x * hsub) % tile_width; |
| 2486 | ccs_y = (y * vsub) % tile_height; |
| 2487 | main_x = intel_fb->normal[0].x % tile_width; |
| 2488 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2489 | |
| 2490 | /* |
| 2491 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2492 | * x/y offsets must match between CCS and the main surface. |
| 2493 | */ |
| 2494 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2495 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2496 | main_x, main_y, |
| 2497 | ccs_x, ccs_y, |
| 2498 | intel_fb->normal[0].x, |
| 2499 | intel_fb->normal[0].y, |
| 2500 | x, y); |
| 2501 | return -EINVAL; |
| 2502 | } |
| 2503 | } |
| 2504 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2505 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2506 | * The fence (if used) is aligned to the start of the object |
| 2507 | * so having the framebuffer wrap around across the edge of the |
| 2508 | * fenced region doesn't really work. We have no API to configure |
| 2509 | * the fence start offset within the object (nor could we probably |
| 2510 | * on gen2/3). So it's just easier if we just require that the |
| 2511 | * fb layout agrees with the fence layout. We already check that the |
| 2512 | * fb stride matches the fence stride elsewhere. |
| 2513 | */ |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2514 | if (i == 0 && i915_gem_object_is_tiled(obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2515 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2516 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2517 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2518 | return -EINVAL; |
| 2519 | } |
| 2520 | |
| 2521 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2522 | * First pixel of the framebuffer from |
| 2523 | * the start of the normal gtt mapping. |
| 2524 | */ |
| 2525 | intel_fb->normal[i].x = x; |
| 2526 | intel_fb->normal[i].y = y; |
| 2527 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2528 | offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i, |
| 2529 | fb->pitches[i], |
| 2530 | DRM_MODE_ROTATE_0, |
| 2531 | tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2532 | offset /= tile_size; |
| 2533 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2534 | if (!is_surface_linear(fb->modifier, i)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2535 | unsigned int tile_width, tile_height; |
| 2536 | unsigned int pitch_tiles; |
| 2537 | struct drm_rect r; |
| 2538 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2539 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2540 | |
| 2541 | rot_info->plane[i].offset = offset; |
| 2542 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2543 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2544 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2545 | |
| 2546 | intel_fb->rotated[i].pitch = |
| 2547 | rot_info->plane[i].height * tile_height; |
| 2548 | |
| 2549 | /* how many tiles does this plane need */ |
| 2550 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2551 | /* |
| 2552 | * If the plane isn't horizontally tile aligned, |
| 2553 | * we need one more tile. |
| 2554 | */ |
| 2555 | if (x != 0) |
| 2556 | size++; |
| 2557 | |
| 2558 | /* rotate the x/y offsets to match the GTT view */ |
| 2559 | r.x1 = x; |
| 2560 | r.y1 = y; |
| 2561 | r.x2 = x + width; |
| 2562 | r.y2 = y + height; |
| 2563 | drm_rect_rotate(&r, |
| 2564 | rot_info->plane[i].width * tile_width, |
| 2565 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2566 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2567 | x = r.x1; |
| 2568 | y = r.y1; |
| 2569 | |
| 2570 | /* rotate the tile dimensions to match the GTT view */ |
| 2571 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2572 | swap(tile_width, tile_height); |
| 2573 | |
| 2574 | /* |
| 2575 | * We only keep the x/y offsets, so push all of the |
| 2576 | * gtt offset into the x/y offsets. |
| 2577 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2578 | intel_adjust_tile_offset(&x, &y, |
| 2579 | tile_width, tile_height, |
| 2580 | tile_size, pitch_tiles, |
| 2581 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2582 | |
| 2583 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2584 | |
| 2585 | /* |
| 2586 | * First pixel of the framebuffer from |
| 2587 | * the start of the rotated gtt mapping. |
| 2588 | */ |
| 2589 | intel_fb->rotated[i].x = x; |
| 2590 | intel_fb->rotated[i].y = y; |
| 2591 | } else { |
| 2592 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2593 | x * cpp, tile_size); |
| 2594 | } |
| 2595 | |
| 2596 | /* how many tiles in total needed in the bo */ |
| 2597 | max_size = max(max_size, offset + size); |
| 2598 | } |
| 2599 | |
Ville Syrjälä | 4e05047 | 2018-09-12 21:04:43 +0300 | [diff] [blame] | 2600 | if (mul_u32_u32(max_size, tile_size) > obj->base.size) { |
| 2601 | DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n", |
| 2602 | mul_u32_u32(max_size, tile_size), obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2603 | return -EINVAL; |
| 2604 | } |
| 2605 | |
| 2606 | return 0; |
| 2607 | } |
| 2608 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2609 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2610 | { |
| 2611 | switch (format) { |
| 2612 | case DISPPLANE_8BPP: |
| 2613 | return DRM_FORMAT_C8; |
| 2614 | case DISPPLANE_BGRX555: |
| 2615 | return DRM_FORMAT_XRGB1555; |
| 2616 | case DISPPLANE_BGRX565: |
| 2617 | return DRM_FORMAT_RGB565; |
| 2618 | default: |
| 2619 | case DISPPLANE_BGRX888: |
| 2620 | return DRM_FORMAT_XRGB8888; |
| 2621 | case DISPPLANE_RGBX888: |
| 2622 | return DRM_FORMAT_XBGR8888; |
| 2623 | case DISPPLANE_BGRX101010: |
| 2624 | return DRM_FORMAT_XRGB2101010; |
| 2625 | case DISPPLANE_RGBX101010: |
| 2626 | return DRM_FORMAT_XBGR2101010; |
| 2627 | } |
| 2628 | } |
| 2629 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2630 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2631 | { |
| 2632 | switch (format) { |
| 2633 | case PLANE_CTL_FORMAT_RGB_565: |
| 2634 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2635 | case PLANE_CTL_FORMAT_NV12: |
| 2636 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2637 | default: |
| 2638 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2639 | if (rgb_order) { |
| 2640 | if (alpha) |
| 2641 | return DRM_FORMAT_ABGR8888; |
| 2642 | else |
| 2643 | return DRM_FORMAT_XBGR8888; |
| 2644 | } else { |
| 2645 | if (alpha) |
| 2646 | return DRM_FORMAT_ARGB8888; |
| 2647 | else |
| 2648 | return DRM_FORMAT_XRGB8888; |
| 2649 | } |
| 2650 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2651 | if (rgb_order) |
| 2652 | return DRM_FORMAT_XBGR2101010; |
| 2653 | else |
| 2654 | return DRM_FORMAT_XRGB2101010; |
| 2655 | } |
| 2656 | } |
| 2657 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2658 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2659 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2660 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2661 | { |
| 2662 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2663 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2664 | struct drm_i915_gem_object *obj = NULL; |
| 2665 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2666 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2667 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2668 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2669 | PAGE_SIZE); |
| 2670 | |
| 2671 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2672 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2673 | if (plane_config->size == 0) |
| 2674 | return false; |
| 2675 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2676 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2677 | * important and we should probably use that space with FBC or other |
| 2678 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2679 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2680 | return false; |
| 2681 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2682 | switch (fb->modifier) { |
| 2683 | case DRM_FORMAT_MOD_LINEAR: |
| 2684 | case I915_FORMAT_MOD_X_TILED: |
| 2685 | case I915_FORMAT_MOD_Y_TILED: |
| 2686 | break; |
| 2687 | default: |
| 2688 | DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n", |
| 2689 | fb->modifier); |
| 2690 | return false; |
| 2691 | } |
| 2692 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2693 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2694 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2695 | base_aligned, |
| 2696 | base_aligned, |
| 2697 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2698 | mutex_unlock(&dev->struct_mutex); |
| 2699 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2700 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2701 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2702 | switch (plane_config->tiling) { |
| 2703 | case I915_TILING_NONE: |
| 2704 | break; |
| 2705 | case I915_TILING_X: |
| 2706 | case I915_TILING_Y: |
| 2707 | obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling; |
| 2708 | break; |
| 2709 | default: |
| 2710 | MISSING_CASE(plane_config->tiling); |
| 2711 | return false; |
| 2712 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2713 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2714 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2715 | mode_cmd.width = fb->width; |
| 2716 | mode_cmd.height = fb->height; |
| 2717 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2718 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2719 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2720 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2721 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2722 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2723 | goto out_unref_obj; |
| 2724 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2725 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2726 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2727 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2728 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2729 | |
| 2730 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2731 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2732 | return false; |
| 2733 | } |
| 2734 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2735 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2736 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2737 | struct intel_plane_state *plane_state, |
| 2738 | bool visible) |
| 2739 | { |
| 2740 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2741 | |
| 2742 | plane_state->base.visible = visible; |
| 2743 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2744 | if (visible) |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2745 | crtc_state->base.plane_mask |= drm_plane_mask(&plane->base); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2746 | else |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2747 | crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2748 | } |
| 2749 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2750 | static void fixup_active_planes(struct intel_crtc_state *crtc_state) |
| 2751 | { |
| 2752 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2753 | struct drm_plane *plane; |
| 2754 | |
| 2755 | /* |
| 2756 | * Active_planes aliases if multiple "primary" or cursor planes |
| 2757 | * have been used on the same (or wrong) pipe. plane_mask uses |
| 2758 | * unique ids, hence we can use that to reconstruct active_planes. |
| 2759 | */ |
| 2760 | crtc_state->active_planes = 0; |
| 2761 | |
| 2762 | drm_for_each_plane_mask(plane, &dev_priv->drm, |
| 2763 | crtc_state->base.plane_mask) |
| 2764 | crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); |
| 2765 | } |
| 2766 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2767 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2768 | struct intel_plane *plane) |
| 2769 | { |
| 2770 | struct intel_crtc_state *crtc_state = |
| 2771 | to_intel_crtc_state(crtc->base.state); |
| 2772 | struct intel_plane_state *plane_state = |
| 2773 | to_intel_plane_state(plane->base.state); |
| 2774 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 2775 | DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", |
| 2776 | plane->base.base.id, plane->base.name, |
| 2777 | crtc->base.base.id, crtc->base.name); |
| 2778 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2779 | intel_set_plane_visible(crtc_state, plane_state, false); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2780 | fixup_active_planes(crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2781 | |
| 2782 | if (plane->id == PLANE_PRIMARY) |
| 2783 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2784 | |
| 2785 | trace_intel_disable_plane(&plane->base, crtc); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 2786 | plane->disable_plane(plane, crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2787 | } |
| 2788 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2789 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2790 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2791 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2792 | { |
| 2793 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2794 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2795 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2796 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2797 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2798 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2799 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2800 | struct intel_plane_state *intel_state = |
| 2801 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2802 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2803 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2804 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2805 | return; |
| 2806 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2807 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2808 | fb = &plane_config->fb->base; |
| 2809 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2810 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2811 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2812 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2813 | |
| 2814 | /* |
| 2815 | * Failed to alloc the obj, check to see if we should share |
| 2816 | * an fb with another CRTC instead |
| 2817 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2818 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2819 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2820 | |
| 2821 | if (c == &intel_crtc->base) |
| 2822 | continue; |
| 2823 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2824 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2825 | continue; |
| 2826 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2827 | state = to_intel_plane_state(c->primary->state); |
| 2828 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2829 | continue; |
| 2830 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2831 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2832 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2833 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2834 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2835 | } |
| 2836 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2837 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2838 | /* |
| 2839 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2840 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2841 | * which will lead to problems later if we don't fix it up. The |
| 2842 | * simplest solution is to just disable the primary plane now and |
| 2843 | * pretend the BIOS never had it enabled. |
| 2844 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2845 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2846 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2847 | return; |
| 2848 | |
| 2849 | valid_fb: |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 2850 | intel_state->base.rotation = plane_config->rotation; |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2851 | intel_fill_fb_ggtt_view(&intel_state->view, fb, |
| 2852 | intel_state->base.rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2853 | intel_state->color_plane[0].stride = |
| 2854 | intel_fb_pitch(fb, 0, intel_state->base.rotation); |
| 2855 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2856 | mutex_lock(&dev->struct_mutex); |
| 2857 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2858 | intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2859 | &intel_state->view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2860 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2861 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2862 | mutex_unlock(&dev->struct_mutex); |
| 2863 | if (IS_ERR(intel_state->vma)) { |
| 2864 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2865 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2866 | |
| 2867 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2868 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2869 | return; |
| 2870 | } |
| 2871 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2872 | obj = intel_fb_obj(fb); |
| 2873 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2874 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2875 | plane_state->src_x = 0; |
| 2876 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2877 | plane_state->src_w = fb->width << 16; |
| 2878 | plane_state->src_h = fb->height << 16; |
| 2879 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2880 | plane_state->crtc_x = 0; |
| 2881 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2882 | plane_state->crtc_w = fb->width; |
| 2883 | plane_state->crtc_h = fb->height; |
| 2884 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2885 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2886 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2887 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2888 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2889 | dev_priv->preserve_bios_swizzle = true; |
| 2890 | |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 2891 | plane_state->fb = fb; |
| 2892 | plane_state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2893 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2894 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2895 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2896 | } |
| 2897 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2898 | static int skl_max_plane_width(const struct drm_framebuffer *fb, |
| 2899 | int color_plane, |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2900 | unsigned int rotation) |
| 2901 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2902 | int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2903 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2904 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2905 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2906 | case I915_FORMAT_MOD_X_TILED: |
| 2907 | switch (cpp) { |
| 2908 | case 8: |
| 2909 | return 4096; |
| 2910 | case 4: |
| 2911 | case 2: |
| 2912 | case 1: |
| 2913 | return 8192; |
| 2914 | default: |
| 2915 | MISSING_CASE(cpp); |
| 2916 | break; |
| 2917 | } |
| 2918 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2919 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2920 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2921 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2922 | case I915_FORMAT_MOD_Y_TILED: |
| 2923 | case I915_FORMAT_MOD_Yf_TILED: |
| 2924 | switch (cpp) { |
| 2925 | case 8: |
| 2926 | return 2048; |
| 2927 | case 4: |
| 2928 | return 4096; |
| 2929 | case 2: |
| 2930 | case 1: |
| 2931 | return 8192; |
| 2932 | default: |
| 2933 | MISSING_CASE(cpp); |
| 2934 | break; |
| 2935 | } |
| 2936 | break; |
| 2937 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2938 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | return 2048; |
| 2942 | } |
| 2943 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2944 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2945 | int main_x, int main_y, u32 main_offset) |
| 2946 | { |
| 2947 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2948 | int hsub = fb->format->hsub; |
| 2949 | int vsub = fb->format->vsub; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2950 | int aux_x = plane_state->color_plane[1].x; |
| 2951 | int aux_y = plane_state->color_plane[1].y; |
| 2952 | u32 aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2953 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2954 | |
| 2955 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2956 | int x, y; |
| 2957 | |
| 2958 | if (aux_x == main_x && aux_y == main_y) |
| 2959 | break; |
| 2960 | |
| 2961 | if (aux_offset == 0) |
| 2962 | break; |
| 2963 | |
| 2964 | x = aux_x / hsub; |
| 2965 | y = aux_y / vsub; |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2966 | aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1, |
| 2967 | aux_offset, aux_offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2968 | aux_x = x * hsub + aux_x % hsub; |
| 2969 | aux_y = y * vsub + aux_y % vsub; |
| 2970 | } |
| 2971 | |
| 2972 | if (aux_x != main_x || aux_y != main_y) |
| 2973 | return false; |
| 2974 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2975 | plane_state->color_plane[1].offset = aux_offset; |
| 2976 | plane_state->color_plane[1].x = aux_x; |
| 2977 | plane_state->color_plane[1].y = aux_y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2978 | |
| 2979 | return true; |
| 2980 | } |
| 2981 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 2982 | 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] | 2983 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2984 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2985 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2986 | int x = plane_state->base.src.x1 >> 16; |
| 2987 | int y = plane_state->base.src.y1 >> 16; |
| 2988 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 2989 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2990 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 2991 | int max_height = 4096; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2992 | u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2993 | |
| 2994 | if (w > max_width || h > max_height) { |
| 2995 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 2996 | w, h, max_width, max_height); |
| 2997 | return -EINVAL; |
| 2998 | } |
| 2999 | |
| 3000 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3001 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3002 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3003 | |
| 3004 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3005 | * AUX surface offset is specified as the distance from the |
| 3006 | * main surface offset, and it must be non-negative. Make |
| 3007 | * sure that is what we will get. |
| 3008 | */ |
| 3009 | if (offset > aux_offset) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3010 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3011 | offset, aux_offset & ~(alignment - 1)); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3012 | |
| 3013 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3014 | * When using an X-tiled surface, the plane blows up |
| 3015 | * if the x offset + width exceed the stride. |
| 3016 | * |
| 3017 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 3018 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3019 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3020 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3021 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3022 | while ((x + w) * cpp > plane_state->color_plane[0].stride) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3023 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3024 | 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] | 3025 | return -EINVAL; |
| 3026 | } |
| 3027 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3028 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3029 | offset, offset - alignment); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3033 | /* |
| 3034 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3035 | * they match with the main surface x/y offsets. |
| 3036 | */ |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3037 | if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3038 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3039 | if (offset == 0) |
| 3040 | break; |
| 3041 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3042 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3043 | offset, offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3046 | 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] | 3047 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3048 | return -EINVAL; |
| 3049 | } |
| 3050 | } |
| 3051 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3052 | plane_state->color_plane[0].offset = offset; |
| 3053 | plane_state->color_plane[0].x = x; |
| 3054 | plane_state->color_plane[0].y = y; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3055 | |
| 3056 | return 0; |
| 3057 | } |
| 3058 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3059 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3060 | { |
| 3061 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3062 | unsigned int rotation = plane_state->base.rotation; |
| 3063 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3064 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3065 | int x = plane_state->base.src.x1 >> 17; |
| 3066 | int y = plane_state->base.src.y1 >> 17; |
| 3067 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3068 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3069 | u32 offset; |
| 3070 | |
| 3071 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3072 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3073 | |
| 3074 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3075 | if (w > max_width || h > max_height) { |
| 3076 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3077 | w, h, max_width, max_height); |
| 3078 | return -EINVAL; |
| 3079 | } |
| 3080 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3081 | plane_state->color_plane[1].offset = offset; |
| 3082 | plane_state->color_plane[1].x = x; |
| 3083 | plane_state->color_plane[1].y = y; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3084 | |
| 3085 | return 0; |
| 3086 | } |
| 3087 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3088 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3089 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3090 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3091 | int src_x = plane_state->base.src.x1 >> 16; |
| 3092 | int src_y = plane_state->base.src.y1 >> 16; |
| 3093 | int hsub = fb->format->hsub; |
| 3094 | int vsub = fb->format->vsub; |
| 3095 | int x = src_x / hsub; |
| 3096 | int y = src_y / vsub; |
| 3097 | u32 offset; |
| 3098 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3099 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3100 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3101 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3102 | plane_state->color_plane[1].offset = offset; |
| 3103 | plane_state->color_plane[1].x = x * hsub + src_x % hsub; |
| 3104 | plane_state->color_plane[1].y = y * vsub + src_y % vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3105 | |
| 3106 | return 0; |
| 3107 | } |
| 3108 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3109 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3110 | { |
| 3111 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3112 | unsigned int rotation = plane_state->base.rotation; |
| 3113 | int ret; |
| 3114 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3115 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3116 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3117 | plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation); |
| 3118 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3119 | ret = intel_plane_check_stride(plane_state); |
| 3120 | if (ret) |
| 3121 | return ret; |
| 3122 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3123 | if (!plane_state->base.visible) |
| 3124 | return 0; |
| 3125 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3126 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3127 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3128 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3129 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3130 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3131 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3132 | /* |
| 3133 | * Handle the AUX surface first since |
| 3134 | * the main surface setup depends on it. |
| 3135 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3136 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3137 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3138 | if (ret) |
| 3139 | return ret; |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3140 | } else if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3141 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3142 | if (ret) |
| 3143 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3144 | } else { |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3145 | plane_state->color_plane[1].offset = ~0xfff; |
| 3146 | plane_state->color_plane[1].x = 0; |
| 3147 | plane_state->color_plane[1].y = 0; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3148 | } |
| 3149 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3150 | ret = skl_check_main_surface(plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3151 | if (ret) |
| 3152 | return ret; |
| 3153 | |
| 3154 | return 0; |
| 3155 | } |
| 3156 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3157 | unsigned int |
| 3158 | i9xx_plane_max_stride(struct intel_plane *plane, |
| 3159 | u32 pixel_format, u64 modifier, |
| 3160 | unsigned int rotation) |
| 3161 | { |
| 3162 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3163 | |
| 3164 | if (!HAS_GMCH_DISPLAY(dev_priv)) { |
| 3165 | return 32*1024; |
| 3166 | } else if (INTEL_GEN(dev_priv) >= 4) { |
| 3167 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3168 | return 16*1024; |
| 3169 | else |
| 3170 | return 32*1024; |
| 3171 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 3172 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3173 | return 8*1024; |
| 3174 | else |
| 3175 | return 16*1024; |
| 3176 | } else { |
| 3177 | if (plane->i9xx_plane == PLANE_C) |
| 3178 | return 4*1024; |
| 3179 | else |
| 3180 | return 8*1024; |
| 3181 | } |
| 3182 | } |
| 3183 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3184 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3185 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3186 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3187 | struct drm_i915_private *dev_priv = |
| 3188 | to_i915(plane_state->base.plane->dev); |
| 3189 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3190 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3191 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3192 | u32 dspcntr; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3193 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3194 | dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3195 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3196 | if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) || |
| 3197 | IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3198 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3199 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3200 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 3201 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3202 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3203 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3204 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3205 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3206 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3207 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3208 | dspcntr |= DISPPLANE_8BPP; |
| 3209 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3210 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3211 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3212 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3213 | case DRM_FORMAT_RGB565: |
| 3214 | dspcntr |= DISPPLANE_BGRX565; |
| 3215 | break; |
| 3216 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3217 | dspcntr |= DISPPLANE_BGRX888; |
| 3218 | break; |
| 3219 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3220 | dspcntr |= DISPPLANE_RGBX888; |
| 3221 | break; |
| 3222 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3223 | dspcntr |= DISPPLANE_BGRX101010; |
| 3224 | break; |
| 3225 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3226 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3227 | break; |
| 3228 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3229 | MISSING_CASE(fb->format->format); |
| 3230 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3231 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3232 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3233 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3234 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3235 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3236 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3237 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3238 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3239 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3240 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3241 | dspcntr |= DISPPLANE_MIRROR; |
| 3242 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3243 | return dspcntr; |
| 3244 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3245 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3246 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3247 | { |
| 3248 | struct drm_i915_private *dev_priv = |
| 3249 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3250 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3251 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3252 | int src_x = plane_state->base.src.x1 >> 16; |
| 3253 | int src_y = plane_state->base.src.y1 >> 16; |
| 3254 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3255 | int ret; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3256 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3257 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3258 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3259 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3260 | ret = intel_plane_check_stride(plane_state); |
| 3261 | if (ret) |
| 3262 | return ret; |
| 3263 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3264 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3265 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3266 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3267 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 3268 | plane_state, 0); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3269 | else |
| 3270 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3271 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3272 | /* HSW/BDW do this automagically in hardware */ |
| 3273 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3274 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3275 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3276 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3277 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3278 | src_x += src_w - 1; |
| 3279 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3280 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3281 | src_x += src_w - 1; |
| 3282 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3283 | } |
| 3284 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3285 | plane_state->color_plane[0].offset = offset; |
| 3286 | plane_state->color_plane[0].x = src_x; |
| 3287 | plane_state->color_plane[0].y = src_y; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3288 | |
| 3289 | return 0; |
| 3290 | } |
| 3291 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3292 | static int |
| 3293 | i9xx_plane_check(struct intel_crtc_state *crtc_state, |
| 3294 | struct intel_plane_state *plane_state) |
| 3295 | { |
| 3296 | int ret; |
| 3297 | |
Ville Syrjälä | 25721f8 | 2018-09-07 18:24:12 +0300 | [diff] [blame] | 3298 | ret = chv_plane_check_rotation(plane_state); |
| 3299 | if (ret) |
| 3300 | return ret; |
| 3301 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3302 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 3303 | &crtc_state->base, |
| 3304 | DRM_PLANE_HELPER_NO_SCALING, |
| 3305 | DRM_PLANE_HELPER_NO_SCALING, |
| 3306 | false, true); |
| 3307 | if (ret) |
| 3308 | return ret; |
| 3309 | |
| 3310 | if (!plane_state->base.visible) |
| 3311 | return 0; |
| 3312 | |
| 3313 | ret = intel_plane_check_src_coordinates(plane_state); |
| 3314 | if (ret) |
| 3315 | return ret; |
| 3316 | |
| 3317 | ret = i9xx_check_plane_surface(plane_state); |
| 3318 | if (ret) |
| 3319 | return ret; |
| 3320 | |
| 3321 | plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state); |
| 3322 | |
| 3323 | return 0; |
| 3324 | } |
| 3325 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3326 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3327 | const struct intel_crtc_state *crtc_state, |
| 3328 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3329 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3330 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3331 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3332 | u32 linear_offset; |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 3333 | u32 dspcntr = plane_state->ctl; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3334 | int x = plane_state->color_plane[0].x; |
| 3335 | int y = plane_state->color_plane[0].y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3336 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3337 | u32 dspaddr_offset; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3338 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3339 | 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] | 3340 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3341 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3342 | dspaddr_offset = plane_state->color_plane[0].offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3343 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3344 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3345 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3346 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3347 | |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3348 | I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride); |
| 3349 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3350 | if (INTEL_GEN(dev_priv) < 4) { |
| 3351 | /* pipesrc and dspsize control the size that is scaled from, |
| 3352 | * which should always be the user's requested size. |
| 3353 | */ |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3354 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3355 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3356 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3357 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3358 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3359 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3360 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3361 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3362 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3363 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3364 | } |
| 3365 | |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3366 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3367 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3368 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3369 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
| 3370 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3371 | } |
| 3372 | |
| 3373 | /* |
| 3374 | * The control register self-arms if the plane was previously |
| 3375 | * disabled. Try to make the plane enable atomic by writing |
| 3376 | * the control register just before the surface register. |
| 3377 | */ |
| 3378 | I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr); |
| 3379 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3380 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3381 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3382 | dspaddr_offset); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3383 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3384 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3385 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3386 | dspaddr_offset); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3387 | |
| 3388 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3391 | static void i9xx_disable_plane(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 3392 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3393 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3394 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3395 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3396 | unsigned long irqflags; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3397 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3398 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3399 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3400 | I915_WRITE_FW(DSPCNTR(i9xx_plane), 0); |
| 3401 | if (INTEL_GEN(dev_priv) >= 4) |
| 3402 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3403 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3404 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3405 | |
| 3406 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3407 | } |
| 3408 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3409 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane, |
| 3410 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3411 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3412 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3413 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3414 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3415 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3416 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3417 | |
| 3418 | /* |
| 3419 | * Not 100% correct for planes that can move between pipes, |
| 3420 | * but that's only the case for gen2-4 which don't have any |
| 3421 | * display power wells. |
| 3422 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3423 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3424 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 3425 | return false; |
| 3426 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3427 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 3428 | |
| 3429 | ret = val & DISPLAY_PLANE_ENABLE; |
| 3430 | |
| 3431 | if (INTEL_GEN(dev_priv) >= 5) |
| 3432 | *pipe = plane->pipe; |
| 3433 | else |
| 3434 | *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 3435 | DISPPLANE_SEL_PIPE_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3436 | |
| 3437 | intel_display_power_put(dev_priv, power_domain); |
| 3438 | |
| 3439 | return ret; |
| 3440 | } |
| 3441 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3442 | static u32 |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3443 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3444 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3445 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3446 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3447 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3448 | return intel_tile_width_bytes(fb, color_plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3451 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3452 | { |
| 3453 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3454 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3455 | |
| 3456 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3457 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3458 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3459 | } |
| 3460 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3461 | /* |
| 3462 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3463 | */ |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3464 | static void skl_detach_scalers(const struct intel_crtc_state *crtc_state) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3465 | { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3466 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3467 | const struct intel_crtc_scaler_state *scaler_state = |
| 3468 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3469 | int i; |
| 3470 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3471 | /* loop through and disable scalers that aren't in use */ |
| 3472 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3473 | if (!scaler_state->scalers[i].in_use) |
| 3474 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3475 | } |
| 3476 | } |
| 3477 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3478 | static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb, |
| 3479 | int color_plane, unsigned int rotation) |
| 3480 | { |
| 3481 | /* |
| 3482 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3483 | * linear buffers or in number of tiles for tiled buffers. |
| 3484 | */ |
| 3485 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
| 3486 | return 64; |
| 3487 | else if (drm_rotation_90_or_270(rotation)) |
| 3488 | return intel_tile_height(fb, color_plane); |
| 3489 | else |
| 3490 | return intel_tile_width_bytes(fb, color_plane); |
| 3491 | } |
| 3492 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3493 | u32 skl_plane_stride(const struct intel_plane_state *plane_state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3494 | int color_plane) |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3495 | { |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3496 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3497 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3498 | u32 stride = plane_state->color_plane[color_plane].stride; |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3499 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3500 | if (color_plane >= fb->format->num_planes) |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3501 | return 0; |
| 3502 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3503 | return stride / skl_plane_stride_mult(fb, color_plane, rotation); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3504 | } |
| 3505 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3506 | static u32 skl_plane_ctl_format(uint32_t pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3507 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3508 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3509 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3510 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3511 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3512 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3513 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3514 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3515 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3516 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3517 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3518 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3519 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3520 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3521 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3522 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3523 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3524 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3525 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3526 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3527 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3528 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3529 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3530 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3531 | case DRM_FORMAT_NV12: |
| 3532 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3533 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3534 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3535 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3536 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3537 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3540 | 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] | 3541 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3542 | if (!plane_state->base.fb->format->has_alpha) |
| 3543 | return PLANE_CTL_ALPHA_DISABLE; |
| 3544 | |
| 3545 | switch (plane_state->base.pixel_blend_mode) { |
| 3546 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3547 | return PLANE_CTL_ALPHA_DISABLE; |
| 3548 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3549 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3550 | case DRM_MODE_BLEND_COVERAGE: |
| 3551 | return PLANE_CTL_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3552 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3553 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3554 | return PLANE_CTL_ALPHA_DISABLE; |
| 3555 | } |
| 3556 | } |
| 3557 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3558 | 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] | 3559 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3560 | if (!plane_state->base.fb->format->has_alpha) |
| 3561 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3562 | |
| 3563 | switch (plane_state->base.pixel_blend_mode) { |
| 3564 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3565 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3566 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3567 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3568 | case DRM_MODE_BLEND_COVERAGE: |
| 3569 | return PLANE_COLOR_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3570 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3571 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3572 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3573 | } |
| 3574 | } |
| 3575 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3576 | static u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
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 (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3579 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3580 | break; |
| 3581 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3582 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3583 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3584 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3585 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3586 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3587 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3588 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3589 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3590 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3591 | default: |
| 3592 | MISSING_CASE(fb_modifier); |
| 3593 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3594 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3595 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3596 | } |
| 3597 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3598 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3599 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3600 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3601 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3602 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3603 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3604 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3605 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3606 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3607 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3608 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3609 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3610 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3611 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3612 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3613 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3614 | MISSING_CASE(rotate); |
| 3615 | } |
| 3616 | |
| 3617 | return 0; |
| 3618 | } |
| 3619 | |
| 3620 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3621 | { |
| 3622 | switch (reflect) { |
| 3623 | case 0: |
| 3624 | break; |
| 3625 | case DRM_MODE_REFLECT_X: |
| 3626 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3627 | case DRM_MODE_REFLECT_Y: |
| 3628 | default: |
| 3629 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3632 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3633 | } |
| 3634 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3635 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3636 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3637 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3638 | struct drm_i915_private *dev_priv = |
| 3639 | to_i915(plane_state->base.plane->dev); |
| 3640 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3641 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3642 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3643 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3644 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3645 | plane_ctl = PLANE_CTL_ENABLE; |
| 3646 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3647 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3648 | plane_ctl |= skl_plane_ctl_alpha(plane_state); |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3649 | plane_ctl |= |
| 3650 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3651 | PLANE_CTL_PIPE_CSC_ENABLE | |
| 3652 | PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3653 | |
| 3654 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3655 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3656 | |
| 3657 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3658 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3659 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3660 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3661 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3662 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3663 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3664 | |
| 3665 | if (INTEL_GEN(dev_priv) >= 10) |
| 3666 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3667 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3668 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3669 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3670 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3671 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3672 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3673 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3674 | return plane_ctl; |
| 3675 | } |
| 3676 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3677 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3678 | const struct intel_plane_state *plane_state) |
| 3679 | { |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3680 | struct drm_i915_private *dev_priv = |
| 3681 | to_i915(plane_state->base.plane->dev); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3682 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3683 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3684 | u32 plane_color_ctl = 0; |
| 3685 | |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3686 | if (INTEL_GEN(dev_priv) < 11) { |
| 3687 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3688 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
| 3689 | } |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3690 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3691 | plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3692 | |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3693 | if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) { |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3694 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3695 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3696 | else |
| 3697 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3698 | |
| 3699 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3700 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3701 | } else if (fb->format->is_yuv) { |
| 3702 | plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3703 | } |
Ville Syrjälä | 012d79e | 2018-05-21 21:56:12 +0300 | [diff] [blame] | 3704 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3705 | return plane_color_ctl; |
| 3706 | } |
| 3707 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3708 | static int |
| 3709 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3710 | struct drm_atomic_state *state, |
| 3711 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3712 | { |
| 3713 | struct drm_crtc_state *crtc_state; |
| 3714 | struct drm_crtc *crtc; |
| 3715 | int i, ret; |
| 3716 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3717 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3718 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3719 | |
| 3720 | if (!state) |
| 3721 | return 0; |
| 3722 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3723 | /* |
| 3724 | * We've duplicated the state, pointers to the old state are invalid. |
| 3725 | * |
| 3726 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3727 | */ |
| 3728 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3729 | /* |
| 3730 | * Force recalculation even if we restore |
| 3731 | * current state. With fast modeset this may not result |
| 3732 | * in a modeset when the state is compatible. |
| 3733 | */ |
| 3734 | crtc_state->mode_changed = true; |
| 3735 | } |
| 3736 | |
| 3737 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3738 | if (!HAS_GMCH_DISPLAY(to_i915(dev))) |
| 3739 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3740 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3741 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3742 | |
| 3743 | WARN_ON(ret == -EDEADLK); |
| 3744 | return ret; |
| 3745 | } |
| 3746 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3747 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3748 | { |
Chris Wilson | 55277e1 | 2019-01-03 11:21:04 +0000 | [diff] [blame^] | 3749 | return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display && |
| 3750 | intel_has_gpu_reset(dev_priv)); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3751 | } |
| 3752 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3753 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3754 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3755 | struct drm_device *dev = &dev_priv->drm; |
| 3756 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3757 | struct drm_atomic_state *state; |
| 3758 | int ret; |
| 3759 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3760 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3761 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3762 | !gpu_reset_clobbers_display(dev_priv)) |
| 3763 | return; |
| 3764 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3765 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3766 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3767 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3768 | |
| 3769 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3770 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3771 | i915_gem_set_wedged(dev_priv); |
| 3772 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3773 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3774 | /* |
| 3775 | * Need mode_config.mutex so that we don't |
| 3776 | * trample ongoing ->detect() and whatnot. |
| 3777 | */ |
| 3778 | mutex_lock(&dev->mode_config.mutex); |
| 3779 | drm_modeset_acquire_init(ctx, 0); |
| 3780 | while (1) { |
| 3781 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3782 | if (ret != -EDEADLK) |
| 3783 | break; |
| 3784 | |
| 3785 | drm_modeset_backoff(ctx); |
| 3786 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3787 | /* |
| 3788 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3789 | * g33 docs say we should at least disable all the planes. |
| 3790 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3791 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3792 | if (IS_ERR(state)) { |
| 3793 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3794 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3795 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3799 | if (ret) { |
| 3800 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3801 | drm_atomic_state_put(state); |
| 3802 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | dev_priv->modeset_restore_state = state; |
| 3806 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3807 | } |
| 3808 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3809 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3810 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3811 | struct drm_device *dev = &dev_priv->drm; |
| 3812 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3813 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3814 | int ret; |
| 3815 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3816 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3817 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3818 | return; |
| 3819 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3820 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3821 | if (!state) |
| 3822 | goto unlock; |
| 3823 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3824 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3825 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3826 | /* for testing only restore the display */ |
| 3827 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3828 | if (ret) |
| 3829 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3830 | } else { |
| 3831 | /* |
| 3832 | * The display has been reset as well, |
| 3833 | * so need a full re-initialization. |
| 3834 | */ |
| 3835 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3836 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3837 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3838 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3839 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3840 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3841 | |
| 3842 | spin_lock_irq(&dev_priv->irq_lock); |
| 3843 | if (dev_priv->display.hpd_irq_setup) |
| 3844 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3845 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3846 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3847 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3848 | if (ret) |
| 3849 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3850 | |
| 3851 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3852 | } |
| 3853 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3854 | drm_atomic_state_put(state); |
| 3855 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3856 | drm_modeset_drop_locks(ctx); |
| 3857 | drm_modeset_acquire_fini(ctx); |
| 3858 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3859 | |
| 3860 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3861 | } |
| 3862 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3863 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3864 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3865 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3866 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3867 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3868 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3869 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3870 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3871 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3872 | /* |
| 3873 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3874 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3875 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3876 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3877 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3878 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3879 | */ |
| 3880 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3881 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3882 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3883 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3884 | |
| 3885 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3886 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3887 | skl_detach_scalers(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3888 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3889 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3890 | skylake_pfit_enable(new_crtc_state); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3891 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3892 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3893 | ironlake_pfit_enable(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3894 | else if (old_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3895 | ironlake_pfit_disable(old_crtc_state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3896 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3897 | } |
| 3898 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3899 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3900 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3901 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3902 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3903 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3904 | i915_reg_t reg; |
| 3905 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3906 | |
| 3907 | /* enable normal train */ |
| 3908 | reg = FDI_TX_CTL(pipe); |
| 3909 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3910 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3911 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3912 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3913 | } else { |
| 3914 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3915 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3916 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3917 | I915_WRITE(reg, temp); |
| 3918 | |
| 3919 | reg = FDI_RX_CTL(pipe); |
| 3920 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3921 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3922 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3923 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3924 | } else { |
| 3925 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3926 | temp |= FDI_LINK_TRAIN_NONE; |
| 3927 | } |
| 3928 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3929 | |
| 3930 | /* wait one idle pattern time */ |
| 3931 | POSTING_READ(reg); |
| 3932 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3933 | |
| 3934 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3935 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3936 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3937 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3938 | } |
| 3939 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3940 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3941 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 3942 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3943 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3944 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3945 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3946 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3947 | i915_reg_t reg; |
| 3948 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3949 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3950 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3951 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3952 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3953 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3954 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3955 | reg = FDI_RX_IMR(pipe); |
| 3956 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3957 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3958 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3959 | I915_WRITE(reg, temp); |
| 3960 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3961 | udelay(150); |
| 3962 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3963 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3964 | reg = FDI_TX_CTL(pipe); |
| 3965 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3966 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3967 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3968 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3969 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3970 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3971 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3972 | reg = FDI_RX_CTL(pipe); |
| 3973 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3974 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3975 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3976 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3977 | |
| 3978 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3979 | udelay(150); |
| 3980 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3981 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3982 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3983 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3984 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3985 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3986 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3987 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3988 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3989 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3990 | |
| 3991 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3992 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3993 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3994 | break; |
| 3995 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3996 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3997 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3998 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3999 | |
| 4000 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4001 | reg = FDI_TX_CTL(pipe); |
| 4002 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4003 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4004 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4005 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4006 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4007 | reg = FDI_RX_CTL(pipe); |
| 4008 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4009 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4010 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4011 | I915_WRITE(reg, temp); |
| 4012 | |
| 4013 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4014 | udelay(150); |
| 4015 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4016 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4017 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4018 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4019 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4020 | |
| 4021 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4022 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4023 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4024 | break; |
| 4025 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4026 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4027 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4028 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4029 | |
| 4030 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4031 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4032 | } |
| 4033 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4034 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4035 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 4036 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 4037 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 4038 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 4039 | }; |
| 4040 | |
| 4041 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4042 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
| 4043 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4044 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4045 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4046 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4047 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4048 | i915_reg_t reg; |
| 4049 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4050 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4051 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4052 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4053 | reg = FDI_RX_IMR(pipe); |
| 4054 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4055 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4056 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4057 | I915_WRITE(reg, temp); |
| 4058 | |
| 4059 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4060 | udelay(150); |
| 4061 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4062 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4063 | reg = FDI_TX_CTL(pipe); |
| 4064 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4065 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4066 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4067 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4068 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4069 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4070 | /* SNB-B */ |
| 4071 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4072 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4073 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4074 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4075 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4076 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4077 | reg = FDI_RX_CTL(pipe); |
| 4078 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4079 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4080 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4081 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4082 | } else { |
| 4083 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4084 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4085 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4086 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4087 | |
| 4088 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4089 | udelay(150); |
| 4090 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4091 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4092 | reg = FDI_TX_CTL(pipe); |
| 4093 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4094 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4095 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4096 | I915_WRITE(reg, temp); |
| 4097 | |
| 4098 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4099 | udelay(500); |
| 4100 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4101 | for (retry = 0; retry < 5; retry++) { |
| 4102 | reg = FDI_RX_IIR(pipe); |
| 4103 | temp = I915_READ(reg); |
| 4104 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4105 | if (temp & FDI_RX_BIT_LOCK) { |
| 4106 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4107 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4108 | break; |
| 4109 | } |
| 4110 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4111 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4112 | if (retry < 5) |
| 4113 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4114 | } |
| 4115 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4116 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4117 | |
| 4118 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4119 | reg = FDI_TX_CTL(pipe); |
| 4120 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4121 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4122 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4123 | if (IS_GEN(dev_priv, 6)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4124 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4125 | /* SNB-B */ |
| 4126 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4127 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4128 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4129 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4130 | reg = FDI_RX_CTL(pipe); |
| 4131 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4132 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4133 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4134 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4135 | } else { |
| 4136 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4137 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4138 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4139 | I915_WRITE(reg, temp); |
| 4140 | |
| 4141 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4142 | udelay(150); |
| 4143 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4144 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4145 | reg = FDI_TX_CTL(pipe); |
| 4146 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4147 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4148 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4149 | I915_WRITE(reg, temp); |
| 4150 | |
| 4151 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4152 | udelay(500); |
| 4153 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4154 | for (retry = 0; retry < 5; retry++) { |
| 4155 | reg = FDI_RX_IIR(pipe); |
| 4156 | temp = I915_READ(reg); |
| 4157 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4158 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4159 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4160 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4161 | break; |
| 4162 | } |
| 4163 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4164 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4165 | if (retry < 5) |
| 4166 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4167 | } |
| 4168 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4169 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4170 | |
| 4171 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4172 | } |
| 4173 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4174 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4175 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4176 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4177 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4178 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4179 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4180 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4181 | i915_reg_t reg; |
| 4182 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4183 | |
| 4184 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4185 | for train result */ |
| 4186 | reg = FDI_RX_IMR(pipe); |
| 4187 | temp = I915_READ(reg); |
| 4188 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4189 | temp &= ~FDI_RX_BIT_LOCK; |
| 4190 | I915_WRITE(reg, temp); |
| 4191 | |
| 4192 | POSTING_READ(reg); |
| 4193 | udelay(150); |
| 4194 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4195 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4196 | I915_READ(FDI_RX_IIR(pipe))); |
| 4197 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4198 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4199 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4200 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4201 | reg = FDI_TX_CTL(pipe); |
| 4202 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4203 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4204 | temp &= ~FDI_TX_ENABLE; |
| 4205 | I915_WRITE(reg, temp); |
| 4206 | |
| 4207 | reg = FDI_RX_CTL(pipe); |
| 4208 | temp = I915_READ(reg); |
| 4209 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4210 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4211 | temp &= ~FDI_RX_ENABLE; |
| 4212 | I915_WRITE(reg, temp); |
| 4213 | |
| 4214 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4215 | reg = FDI_TX_CTL(pipe); |
| 4216 | temp = I915_READ(reg); |
| 4217 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4218 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4219 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4220 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4221 | temp |= snb_b_fdi_train_param[j/2]; |
| 4222 | temp |= FDI_COMPOSITE_SYNC; |
| 4223 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4224 | |
| 4225 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4226 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4227 | |
| 4228 | reg = FDI_RX_CTL(pipe); |
| 4229 | temp = I915_READ(reg); |
| 4230 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4231 | temp |= FDI_COMPOSITE_SYNC; |
| 4232 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4233 | |
| 4234 | POSTING_READ(reg); |
| 4235 | udelay(1); /* should be 0.5us */ |
| 4236 | |
| 4237 | for (i = 0; i < 4; i++) { |
| 4238 | reg = FDI_RX_IIR(pipe); |
| 4239 | temp = I915_READ(reg); |
| 4240 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4241 | |
| 4242 | if (temp & FDI_RX_BIT_LOCK || |
| 4243 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4244 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4245 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4246 | i); |
| 4247 | break; |
| 4248 | } |
| 4249 | udelay(1); /* should be 0.5us */ |
| 4250 | } |
| 4251 | if (i == 4) { |
| 4252 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4253 | continue; |
| 4254 | } |
| 4255 | |
| 4256 | /* Train 2 */ |
| 4257 | reg = FDI_TX_CTL(pipe); |
| 4258 | temp = I915_READ(reg); |
| 4259 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4260 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4261 | I915_WRITE(reg, temp); |
| 4262 | |
| 4263 | reg = FDI_RX_CTL(pipe); |
| 4264 | temp = I915_READ(reg); |
| 4265 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4266 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4267 | I915_WRITE(reg, temp); |
| 4268 | |
| 4269 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4270 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4271 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4272 | for (i = 0; i < 4; i++) { |
| 4273 | reg = FDI_RX_IIR(pipe); |
| 4274 | temp = I915_READ(reg); |
| 4275 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4276 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4277 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4278 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4279 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4280 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4281 | i); |
| 4282 | goto train_done; |
| 4283 | } |
| 4284 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4285 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4286 | if (i == 4) |
| 4287 | 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] | 4288 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4289 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4290 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4291 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4292 | } |
| 4293 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4294 | 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] | 4295 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4296 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4297 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4298 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4299 | i915_reg_t reg; |
| 4300 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4301 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4302 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4303 | reg = FDI_RX_CTL(pipe); |
| 4304 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4305 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4306 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4307 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4308 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4309 | |
| 4310 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4311 | udelay(200); |
| 4312 | |
| 4313 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4314 | temp = I915_READ(reg); |
| 4315 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4316 | |
| 4317 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4318 | udelay(200); |
| 4319 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4320 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4321 | reg = FDI_TX_CTL(pipe); |
| 4322 | temp = I915_READ(reg); |
| 4323 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4324 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4325 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4326 | POSTING_READ(reg); |
| 4327 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4328 | } |
| 4329 | } |
| 4330 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4331 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4332 | { |
| 4333 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4334 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4335 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4336 | i915_reg_t reg; |
| 4337 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4338 | |
| 4339 | /* Switch from PCDclk to Rawclk */ |
| 4340 | reg = FDI_RX_CTL(pipe); |
| 4341 | temp = I915_READ(reg); |
| 4342 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4343 | |
| 4344 | /* Disable CPU FDI TX PLL */ |
| 4345 | reg = FDI_TX_CTL(pipe); |
| 4346 | temp = I915_READ(reg); |
| 4347 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4348 | |
| 4349 | POSTING_READ(reg); |
| 4350 | udelay(100); |
| 4351 | |
| 4352 | reg = FDI_RX_CTL(pipe); |
| 4353 | temp = I915_READ(reg); |
| 4354 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4355 | |
| 4356 | /* Wait for the clocks to turn off. */ |
| 4357 | POSTING_READ(reg); |
| 4358 | udelay(100); |
| 4359 | } |
| 4360 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4361 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4362 | { |
| 4363 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4364 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4365 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4366 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4367 | i915_reg_t reg; |
| 4368 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4369 | |
| 4370 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4371 | reg = FDI_TX_CTL(pipe); |
| 4372 | temp = I915_READ(reg); |
| 4373 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4374 | POSTING_READ(reg); |
| 4375 | |
| 4376 | reg = FDI_RX_CTL(pipe); |
| 4377 | temp = I915_READ(reg); |
| 4378 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4379 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4380 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4381 | |
| 4382 | POSTING_READ(reg); |
| 4383 | udelay(100); |
| 4384 | |
| 4385 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4386 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4387 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4388 | |
| 4389 | /* still set train pattern 1 */ |
| 4390 | reg = FDI_TX_CTL(pipe); |
| 4391 | temp = I915_READ(reg); |
| 4392 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4393 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4394 | I915_WRITE(reg, temp); |
| 4395 | |
| 4396 | reg = FDI_RX_CTL(pipe); |
| 4397 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4398 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4399 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4400 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4401 | } else { |
| 4402 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4403 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4404 | } |
| 4405 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4406 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4407 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4408 | I915_WRITE(reg, temp); |
| 4409 | |
| 4410 | POSTING_READ(reg); |
| 4411 | udelay(100); |
| 4412 | } |
| 4413 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4414 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4415 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4416 | struct drm_crtc *crtc; |
| 4417 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4418 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4419 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4420 | struct drm_crtc_commit *commit; |
| 4421 | spin_lock(&crtc->commit_lock); |
| 4422 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4423 | struct drm_crtc_commit, commit_entry); |
| 4424 | cleanup_done = commit ? |
| 4425 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4426 | spin_unlock(&crtc->commit_lock); |
| 4427 | |
| 4428 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4429 | continue; |
| 4430 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4431 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4432 | |
| 4433 | return true; |
| 4434 | } |
| 4435 | |
| 4436 | return false; |
| 4437 | } |
| 4438 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4439 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4440 | { |
| 4441 | u32 temp; |
| 4442 | |
| 4443 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4444 | |
| 4445 | mutex_lock(&dev_priv->sb_lock); |
| 4446 | |
| 4447 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4448 | temp |= SBI_SSCCTL_DISABLE; |
| 4449 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4450 | |
| 4451 | mutex_unlock(&dev_priv->sb_lock); |
| 4452 | } |
| 4453 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4454 | /* Program iCLKIP clock to the desired frequency */ |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4455 | static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4456 | { |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4457 | 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] | 4458 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4459 | int clock = crtc_state->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4460 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4461 | u32 temp; |
| 4462 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4463 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4464 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4465 | /* The iCLK virtual clock root frequency is in MHz, |
| 4466 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4467 | * divisors, it is necessary to divide one by another, so we |
| 4468 | * convert the virtual clock precision to KHz here for higher |
| 4469 | * precision. |
| 4470 | */ |
| 4471 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4472 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4473 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4474 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4475 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4476 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4477 | clock << auxdiv); |
| 4478 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4479 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4480 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4481 | /* |
| 4482 | * Near 20MHz is a corner case which is |
| 4483 | * out of range for the 7-bit divisor |
| 4484 | */ |
| 4485 | if (divsel <= 0x7f) |
| 4486 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | /* This should not happen with any sane values */ |
| 4490 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4491 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4492 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4493 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4494 | |
| 4495 | 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] | 4496 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4497 | auxdiv, |
| 4498 | divsel, |
| 4499 | phasedir, |
| 4500 | phaseinc); |
| 4501 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4502 | mutex_lock(&dev_priv->sb_lock); |
| 4503 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4504 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4505 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4506 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4507 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4508 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4509 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4510 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4511 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4512 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4513 | |
| 4514 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4515 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4516 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4517 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4518 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4519 | |
| 4520 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4521 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4522 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4523 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4524 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4525 | mutex_unlock(&dev_priv->sb_lock); |
| 4526 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4527 | /* Wait for initialization time */ |
| 4528 | udelay(24); |
| 4529 | |
| 4530 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4531 | } |
| 4532 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4533 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4534 | { |
| 4535 | u32 divsel, phaseinc, auxdiv; |
| 4536 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4537 | u32 iclk_pi_range = 64; |
| 4538 | u32 desired_divisor; |
| 4539 | u32 temp; |
| 4540 | |
| 4541 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4542 | return 0; |
| 4543 | |
| 4544 | mutex_lock(&dev_priv->sb_lock); |
| 4545 | |
| 4546 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4547 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4548 | mutex_unlock(&dev_priv->sb_lock); |
| 4549 | return 0; |
| 4550 | } |
| 4551 | |
| 4552 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4553 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4554 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4555 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4556 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4557 | |
| 4558 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4559 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4560 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4561 | |
| 4562 | mutex_unlock(&dev_priv->sb_lock); |
| 4563 | |
| 4564 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4565 | |
| 4566 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4567 | desired_divisor << auxdiv); |
| 4568 | } |
| 4569 | |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4570 | 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] | 4571 | enum pipe pch_transcoder) |
| 4572 | { |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4573 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4574 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4575 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4576 | |
| 4577 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4578 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4579 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4580 | I915_READ(HBLANK(cpu_transcoder))); |
| 4581 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4582 | I915_READ(HSYNC(cpu_transcoder))); |
| 4583 | |
| 4584 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4585 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4586 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4587 | I915_READ(VBLANK(cpu_transcoder))); |
| 4588 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4589 | I915_READ(VSYNC(cpu_transcoder))); |
| 4590 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4591 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4592 | } |
| 4593 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4594 | 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] | 4595 | { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4596 | uint32_t temp; |
| 4597 | |
| 4598 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4599 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4600 | return; |
| 4601 | |
| 4602 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4603 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4604 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4605 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4606 | if (enable) |
| 4607 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4608 | |
| 4609 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4610 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4611 | POSTING_READ(SOUTH_CHICKEN1); |
| 4612 | } |
| 4613 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4614 | 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] | 4615 | { |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4616 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4617 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4618 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4619 | switch (crtc->pipe) { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4620 | case PIPE_A: |
| 4621 | break; |
| 4622 | case PIPE_B: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4623 | if (crtc_state->fdi_lanes > 2) |
| 4624 | cpt_set_fdi_bc_bifurcation(dev_priv, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4625 | else |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4626 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4627 | |
| 4628 | break; |
| 4629 | case PIPE_C: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4630 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4631 | |
| 4632 | break; |
| 4633 | default: |
| 4634 | BUG(); |
| 4635 | } |
| 4636 | } |
| 4637 | |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4638 | /* |
| 4639 | * Finds the encoder associated with the given CRTC. This can only be |
| 4640 | * used when we know that the CRTC isn't feeding multiple encoders! |
| 4641 | */ |
| 4642 | static struct intel_encoder * |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4643 | intel_get_crtc_new_encoder(const struct intel_atomic_state *state, |
| 4644 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4645 | { |
| 4646 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4647 | const struct drm_connector_state *connector_state; |
| 4648 | const struct drm_connector *connector; |
| 4649 | struct intel_encoder *encoder = NULL; |
| 4650 | int num_encoders = 0; |
| 4651 | int i; |
| 4652 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4653 | 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] | 4654 | if (connector_state->crtc != &crtc->base) |
| 4655 | continue; |
| 4656 | |
| 4657 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 4658 | num_encoders++; |
| 4659 | } |
| 4660 | |
| 4661 | WARN(num_encoders != 1, "%d encoders for pipe %c\n", |
| 4662 | num_encoders, pipe_name(crtc->pipe)); |
| 4663 | |
| 4664 | return encoder; |
| 4665 | } |
| 4666 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4667 | /* |
| 4668 | * Enable PCH resources required for PCH ports: |
| 4669 | * - PCH PLLs |
| 4670 | * - FDI training & RX/TX |
| 4671 | * - update transcoder timings |
| 4672 | * - DP transcoding bits |
| 4673 | * - transcoder |
| 4674 | */ |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4675 | static void ironlake_pch_enable(const struct intel_atomic_state *state, |
| 4676 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4677 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4678 | 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] | 4679 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4680 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4681 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4682 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4683 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4684 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4685 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4686 | if (IS_IVYBRIDGE(dev_priv)) |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4687 | ivybridge_update_fdi_bc_bifurcation(crtc_state); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4688 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4689 | /* Write the TU size bits before fdi link training, so that error |
| 4690 | * detection works. */ |
| 4691 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4692 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4693 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4694 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4695 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4696 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4697 | /* We need to program the right clock selection before writing the pixel |
| 4698 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4699 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4700 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4701 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4702 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4703 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4704 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4705 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4706 | 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] | 4707 | temp |= sel; |
| 4708 | else |
| 4709 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4710 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4711 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4712 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4713 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4714 | * transcoder, and we actually should do this to not upset any PCH |
| 4715 | * transcoder that already use the clock when we share it. |
| 4716 | * |
| 4717 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4718 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4719 | * the right LVDS enable sequence. */ |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 4720 | intel_enable_shared_dpll(crtc_state); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4721 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4722 | /* set transcoder timing, panel must allow it */ |
| 4723 | assert_panel_unlocked(dev_priv, pipe); |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4724 | ironlake_pch_transcoder_set_timings(crtc_state, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4725 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4726 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4727 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4728 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4729 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4730 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4731 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4732 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4733 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4734 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4735 | enum port port; |
| 4736 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4737 | temp = I915_READ(reg); |
| 4738 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4739 | TRANS_DP_SYNC_MASK | |
| 4740 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4741 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4742 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4743 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4744 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4745 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4746 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4747 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4748 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4749 | port = intel_get_crtc_new_encoder(state, crtc_state)->port; |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4750 | WARN_ON(port < PORT_B || port > PORT_D); |
| 4751 | temp |= TRANS_DP_PORT_SEL(port); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4752 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4753 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4754 | } |
| 4755 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 4756 | ironlake_enable_pch_transcoder(crtc_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4757 | } |
| 4758 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4759 | static void lpt_pch_enable(const struct intel_atomic_state *state, |
| 4760 | const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4761 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4762 | 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] | 4763 | 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] | 4764 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4765 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4766 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4767 | |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4768 | lpt_program_iclkip(crtc_state); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4769 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4770 | /* Set transcoder timing. */ |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4771 | ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4772 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4773 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4776 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4777 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4778 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4779 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4780 | u32 temp; |
| 4781 | |
| 4782 | temp = I915_READ(dslreg); |
| 4783 | udelay(500); |
| 4784 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4785 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4786 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4790 | /* |
| 4791 | * The hardware phase 0.0 refers to the center of the pixel. |
| 4792 | * We want to start from the top/left edge which is phase |
| 4793 | * -0.5. That matches how the hardware calculates the scaling |
| 4794 | * factors (from top-left of the first pixel to bottom-right |
| 4795 | * of the last pixel, as opposed to the pixel centers). |
| 4796 | * |
| 4797 | * For 4:2:0 subsampled chroma planes we obviously have to |
| 4798 | * adjust that so that the chroma sample position lands in |
| 4799 | * the right spot. |
| 4800 | * |
| 4801 | * Note that for packed YCbCr 4:2:2 formats there is no way to |
| 4802 | * control chroma siting. The hardware simply replicates the |
| 4803 | * chroma samples for both of the luma samples, and thus we don't |
| 4804 | * actually get the expected MPEG2 chroma siting convention :( |
| 4805 | * The same behaviour is observed on pre-SKL platforms as well. |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4806 | * |
| 4807 | * Theory behind the formula (note that we ignore sub-pixel |
| 4808 | * source coordinates): |
| 4809 | * s = source sample position |
| 4810 | * d = destination sample position |
| 4811 | * |
| 4812 | * Downscaling 4:1: |
| 4813 | * -0.5 |
| 4814 | * | 0.0 |
| 4815 | * | | 1.5 (initial phase) |
| 4816 | * | | | |
| 4817 | * v v v |
| 4818 | * | s | s | s | s | |
| 4819 | * | d | |
| 4820 | * |
| 4821 | * Upscaling 1:4: |
| 4822 | * -0.5 |
| 4823 | * | -0.375 (initial phase) |
| 4824 | * | | 0.0 |
| 4825 | * | | | |
| 4826 | * v v v |
| 4827 | * | s | |
| 4828 | * | d | d | d | d | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4829 | */ |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4830 | 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] | 4831 | { |
| 4832 | int phase = -0x8000; |
| 4833 | u16 trip = 0; |
| 4834 | |
| 4835 | if (chroma_cosited) |
| 4836 | phase += (sub - 1) * 0x8000 / sub; |
| 4837 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4838 | phase += scale / (2 * sub); |
| 4839 | |
| 4840 | /* |
| 4841 | * Hardware initial phase limited to [-0.5:1.5]. |
| 4842 | * Since the max hardware scale factor is 3.0, we |
| 4843 | * should never actually excdeed 1.0 here. |
| 4844 | */ |
| 4845 | WARN_ON(phase < -0x8000 || phase > 0x18000); |
| 4846 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4847 | if (phase < 0) |
| 4848 | phase = 0x10000 + phase; |
| 4849 | else |
| 4850 | trip = PS_PHASE_TRIP; |
| 4851 | |
| 4852 | return ((phase >> 2) & PS_PHASE_MASK) | trip; |
| 4853 | } |
| 4854 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4855 | static int |
| 4856 | 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] | 4857 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4858 | int src_w, int src_h, int dst_w, int dst_h, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4859 | const struct drm_format_info *format, bool need_scaler) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4860 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4861 | struct intel_crtc_scaler_state *scaler_state = |
| 4862 | &crtc_state->scaler_state; |
| 4863 | struct intel_crtc *intel_crtc = |
| 4864 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4865 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4866 | const struct drm_display_mode *adjusted_mode = |
| 4867 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4868 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4869 | /* |
| 4870 | * Src coordinates are already rotated by 270 degrees for |
| 4871 | * the 90/270 degree plane rotation cases (to match the |
| 4872 | * GTT mapping), hence no need to account for rotation here. |
| 4873 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4874 | if (src_w != dst_w || src_h != dst_h) |
| 4875 | need_scaler = true; |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 4876 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4877 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4878 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 4879 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 4880 | * Once NV12 is enabled, handle it here while allocating scaler |
| 4881 | * for NV12. |
| 4882 | */ |
| 4883 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4884 | need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4885 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 4886 | return -EINVAL; |
| 4887 | } |
| 4888 | |
| 4889 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4890 | * if plane is being disabled or scaler is no more required or force detach |
| 4891 | * - free scaler binded to this plane/crtc |
| 4892 | * - in order to do this, update crtc->scaler_usage |
| 4893 | * |
| 4894 | * Here scaler state in crtc_state is set free so that |
| 4895 | * scaler can be assigned to other user. Actual register |
| 4896 | * update to free the scaler is done in plane/panel-fit programming. |
| 4897 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4898 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4899 | if (force_detach || !need_scaler) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4900 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4901 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4902 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4903 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4904 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4905 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4906 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4907 | scaler_state->scaler_users); |
| 4908 | *scaler_id = -1; |
| 4909 | } |
| 4910 | return 0; |
| 4911 | } |
| 4912 | |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4913 | if (format && format->format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 4914 | (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] | 4915 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 4916 | return -EINVAL; |
| 4917 | } |
| 4918 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4919 | /* range checks */ |
| 4920 | 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] | 4921 | 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] | 4922 | (IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 4923 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 4924 | 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] | 4925 | (!IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 4926 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4927 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4928 | 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] | 4929 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4930 | 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] | 4931 | return -EINVAL; |
| 4932 | } |
| 4933 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4934 | /* mark this plane as a scaler user in crtc_state */ |
| 4935 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4936 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4937 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4938 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4939 | scaler_state->scaler_users); |
| 4940 | |
| 4941 | return 0; |
| 4942 | } |
| 4943 | |
| 4944 | /** |
| 4945 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4946 | * |
| 4947 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4948 | * |
| 4949 | * Return |
| 4950 | * 0 - scaler_usage updated successfully |
| 4951 | * error - requested scaling cannot be supported or other error condition |
| 4952 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4953 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4954 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4955 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4956 | bool need_scaler = false; |
| 4957 | |
| 4958 | if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
| 4959 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4960 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4961 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4962 | &state->scaler_state.scaler_id, |
| 4963 | state->pipe_src_w, state->pipe_src_h, |
| 4964 | adjusted_mode->crtc_hdisplay, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4965 | adjusted_mode->crtc_vdisplay, NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | /** |
| 4969 | * 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] | 4970 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4971 | * @plane_state: atomic plane state to update |
| 4972 | * |
| 4973 | * Return |
| 4974 | * 0 - scaler_usage updated successfully |
| 4975 | * error - requested scaling cannot be supported or other error condition |
| 4976 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4977 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4978 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4979 | { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4980 | struct intel_plane *intel_plane = |
| 4981 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4982 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4983 | int ret; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4984 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4985 | bool need_scaler = false; |
| 4986 | |
| 4987 | /* Pre-gen11 and SDR planes always need a scaler for planar formats. */ |
| 4988 | if (!icl_is_hdr_plane(intel_plane) && |
| 4989 | fb && fb->format->format == DRM_FORMAT_NV12) |
| 4990 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4991 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4992 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4993 | drm_plane_index(&intel_plane->base), |
| 4994 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4995 | drm_rect_width(&plane_state->base.src) >> 16, |
| 4996 | drm_rect_height(&plane_state->base.src) >> 16, |
| 4997 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4998 | drm_rect_height(&plane_state->base.dst), |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4999 | fb ? fb->format : NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5000 | |
| 5001 | if (ret || plane_state->scaler_id < 0) |
| 5002 | return ret; |
| 5003 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5004 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 5005 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5006 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 5007 | intel_plane->base.base.id, |
| 5008 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5009 | return -EINVAL; |
| 5010 | } |
| 5011 | |
| 5012 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5013 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5014 | case DRM_FORMAT_RGB565: |
| 5015 | case DRM_FORMAT_XBGR8888: |
| 5016 | case DRM_FORMAT_XRGB8888: |
| 5017 | case DRM_FORMAT_ABGR8888: |
| 5018 | case DRM_FORMAT_ARGB8888: |
| 5019 | case DRM_FORMAT_XRGB2101010: |
| 5020 | case DRM_FORMAT_XBGR2101010: |
| 5021 | case DRM_FORMAT_YUYV: |
| 5022 | case DRM_FORMAT_YVYU: |
| 5023 | case DRM_FORMAT_UYVY: |
| 5024 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5025 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5026 | break; |
| 5027 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5028 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 5029 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5030 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5031 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5034 | return 0; |
| 5035 | } |
| 5036 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5037 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 5038 | { |
| 5039 | int i; |
| 5040 | |
| 5041 | for (i = 0; i < crtc->num_scalers; i++) |
| 5042 | skl_detach_scaler(crtc, i); |
| 5043 | } |
| 5044 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5045 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5046 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5047 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5048 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5049 | enum pipe pipe = crtc->pipe; |
| 5050 | const struct intel_crtc_scaler_state *scaler_state = |
| 5051 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5052 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5053 | if (crtc_state->pch_pfit.enabled) { |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5054 | u16 uv_rgb_hphase, uv_rgb_vphase; |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5055 | int pfit_w, pfit_h, hscale, vscale; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5056 | int id; |
| 5057 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5058 | if (WARN_ON(crtc_state->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5059 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5060 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5061 | pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF; |
| 5062 | pfit_h = crtc_state->pch_pfit.size & 0xFFFF; |
| 5063 | |
| 5064 | hscale = (crtc_state->pipe_src_w << 16) / pfit_w; |
| 5065 | vscale = (crtc_state->pipe_src_h << 16) / pfit_h; |
| 5066 | |
| 5067 | uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false); |
| 5068 | uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5069 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5070 | id = scaler_state->scaler_id; |
| 5071 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 5072 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5073 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, id), |
| 5074 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase)); |
| 5075 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, id), |
| 5076 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase)); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5077 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos); |
| 5078 | 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] | 5079 | } |
| 5080 | } |
| 5081 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5082 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5083 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5084 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5085 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5086 | int pipe = crtc->pipe; |
| 5087 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5088 | if (crtc_state->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5089 | /* Force use of hard-coded filter coefficients |
| 5090 | * as some pre-programmed values are broken, |
| 5091 | * e.g. x201. |
| 5092 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5093 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5094 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 5095 | PF_PIPE_SEL_IVB(pipe)); |
| 5096 | else |
| 5097 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5098 | I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos); |
| 5099 | I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 5100 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5101 | } |
| 5102 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5103 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5104 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5105 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 5106 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5107 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5108 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5109 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5110 | return; |
| 5111 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 5112 | /* |
| 5113 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 5114 | * This function is called from post_plane_update, which is run after |
| 5115 | * a vblank wait. |
| 5116 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5117 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 5118 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5119 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5120 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 5121 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 5122 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5123 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5124 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 5125 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5126 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 5127 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5128 | */ |
| 5129 | } else { |
| 5130 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 5131 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 5132 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5133 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5134 | * the HW state readout code will complain that the expected |
| 5135 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5136 | if (intel_wait_for_register(dev_priv, |
| 5137 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5138 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5139 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5140 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5141 | } |
| 5142 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5143 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5144 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5145 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5146 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5147 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5148 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5149 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5150 | return; |
| 5151 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5152 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5153 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5154 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5155 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5156 | /* |
| 5157 | * Wait for PCODE to finish disabling IPS. The BSpec specified |
| 5158 | * 42ms timeout value leads to occasional timeouts so use 100ms |
| 5159 | * instead. |
| 5160 | */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5161 | if (intel_wait_for_register(dev_priv, |
| 5162 | IPS_CTL, IPS_ENABLE, 0, |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5163 | 100)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5164 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5165 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5166 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5167 | POSTING_READ(IPS_CTL); |
| 5168 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5169 | |
| 5170 | /* 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] | 5171 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5172 | } |
| 5173 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5174 | 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] | 5175 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5176 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5177 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5178 | |
| 5179 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5180 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5181 | mutex_unlock(&dev->struct_mutex); |
| 5182 | } |
| 5183 | |
| 5184 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5185 | * has to recompute where to put it anyway. |
| 5186 | */ |
| 5187 | } |
| 5188 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5189 | /** |
| 5190 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5191 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5192 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5193 | * |
| 5194 | * Performs potentially sleeping operations that must be done after the primary |
| 5195 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5196 | * called due to an explicit primary plane update, or due to an implicit |
| 5197 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5198 | * completely hide the primary plane. |
| 5199 | */ |
| 5200 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5201 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5202 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5203 | { |
| 5204 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5205 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5206 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5207 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5208 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5209 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5210 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5211 | * So don't enable underrun reporting before at least some planes |
| 5212 | * are enabled. |
| 5213 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5214 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5215 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5216 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5217 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5218 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5219 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5220 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5221 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5222 | } |
| 5223 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5224 | /* FIXME get rid of this and use pre_plane_update */ |
| 5225 | static void |
| 5226 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5227 | { |
| 5228 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5229 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5230 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5231 | int pipe = intel_crtc->pipe; |
| 5232 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5233 | /* |
| 5234 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5235 | * So disable underrun reporting before all the planes get disabled. |
| 5236 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5237 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5238 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5239 | |
| 5240 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5241 | |
| 5242 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5243 | * Vblank time updates from the shadow to live plane control register |
| 5244 | * are blocked if the memory self-refresh mode is active at that |
| 5245 | * moment. So to make sure the plane gets truly disabled, disable |
| 5246 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5247 | * will be checked/applied by the HW only at the next frame start |
| 5248 | * event which is after the vblank start event, so we need to have a |
| 5249 | * wait-for-vblank between disabling the plane and the pipe. |
| 5250 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5251 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 5252 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5253 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5254 | } |
| 5255 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5256 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5257 | const struct intel_crtc_state *new_crtc_state) |
| 5258 | { |
| 5259 | if (!old_crtc_state->ips_enabled) |
| 5260 | return false; |
| 5261 | |
| 5262 | if (needs_modeset(&new_crtc_state->base)) |
| 5263 | return true; |
| 5264 | |
| 5265 | return !new_crtc_state->ips_enabled; |
| 5266 | } |
| 5267 | |
| 5268 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5269 | const struct intel_crtc_state *new_crtc_state) |
| 5270 | { |
| 5271 | if (!new_crtc_state->ips_enabled) |
| 5272 | return false; |
| 5273 | |
| 5274 | if (needs_modeset(&new_crtc_state->base)) |
| 5275 | return true; |
| 5276 | |
| 5277 | /* |
| 5278 | * We can't read out IPS on broadwell, assume the worst and |
| 5279 | * forcibly enable IPS on the first fastset. |
| 5280 | */ |
| 5281 | if (new_crtc_state->update_pipe && |
| 5282 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5283 | return true; |
| 5284 | |
| 5285 | return !old_crtc_state->ips_enabled; |
| 5286 | } |
| 5287 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5288 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5289 | const struct intel_crtc_state *crtc_state) |
| 5290 | { |
| 5291 | if (!crtc_state->nv12_planes) |
| 5292 | return false; |
| 5293 | |
Rodrigo Vivi | 1347d3c | 2018-10-31 09:28:45 -0700 | [diff] [blame] | 5294 | /* WA Display #0827: Gen9:all */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5295 | if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv)) |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5296 | return true; |
| 5297 | |
| 5298 | return false; |
| 5299 | } |
| 5300 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5301 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5302 | { |
| 5303 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5304 | struct drm_device *dev = crtc->base.dev; |
| 5305 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5306 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5307 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5308 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5309 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5310 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5311 | struct drm_plane_state *old_primary_state = |
| 5312 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5313 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5314 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5315 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5316 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5317 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5318 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5319 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5320 | hsw_enable_ips(pipe_config); |
| 5321 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5322 | if (old_primary_state) { |
| 5323 | struct drm_plane_state *new_primary_state = |
| 5324 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5325 | |
| 5326 | intel_fbc_post_update(crtc); |
| 5327 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5328 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5329 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5330 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5331 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5332 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5333 | |
| 5334 | /* Display WA 827 */ |
| 5335 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5336 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5337 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5338 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5339 | } |
| 5340 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5341 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5342 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5343 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5344 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5345 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5346 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5347 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5348 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5349 | struct drm_plane_state *old_primary_state = |
| 5350 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5351 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5352 | struct intel_atomic_state *old_intel_state = |
| 5353 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5354 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5355 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5356 | hsw_disable_ips(old_crtc_state); |
| 5357 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5358 | if (old_primary_state) { |
| 5359 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5360 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5361 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5362 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5363 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5364 | /* |
| 5365 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5366 | * So disable underrun reporting before all the planes get disabled. |
| 5367 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5368 | if (IS_GEN(dev_priv, 2) && old_primary_state->visible && |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5369 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5370 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5371 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5372 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5373 | /* Display WA 827 */ |
| 5374 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5375 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5376 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5377 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5378 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5379 | /* |
| 5380 | * Vblank time updates from the shadow to live plane control register |
| 5381 | * are blocked if the memory self-refresh mode is active at that |
| 5382 | * moment. So to make sure the plane gets truly disabled, disable |
| 5383 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5384 | * will be checked/applied by the HW only at the next frame start |
| 5385 | * event which is after the vblank start event, so we need to have a |
| 5386 | * wait-for-vblank between disabling the plane and the pipe. |
| 5387 | */ |
| 5388 | if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active && |
| 5389 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5390 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5391 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5392 | /* |
| 5393 | * IVB workaround: must disable low power watermarks for at least |
| 5394 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5395 | * when scaling is disabled. |
| 5396 | * |
| 5397 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5398 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 5399 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) && |
| 5400 | old_crtc_state->base.active) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5401 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5402 | |
| 5403 | /* |
| 5404 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5405 | * watermark programming here. |
| 5406 | */ |
| 5407 | if (needs_modeset(&pipe_config->base)) |
| 5408 | return; |
| 5409 | |
| 5410 | /* |
| 5411 | * For platforms that support atomic watermarks, program the |
| 5412 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5413 | * will be the intermediate values that are safe for both pre- and |
| 5414 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5415 | * to the final 'target' values and we'll do this again to get the |
| 5416 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5417 | * will be the final target values which will get automatically latched |
| 5418 | * at vblank time; no further programming will be necessary. |
| 5419 | * |
| 5420 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5421 | * we'll continue to update watermarks the old way, if flags tell |
| 5422 | * us to. |
| 5423 | */ |
| 5424 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5425 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5426 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5427 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5428 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5429 | } |
| 5430 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5431 | static void intel_crtc_disable_planes(struct intel_atomic_state *state, |
| 5432 | struct intel_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5433 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5434 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5435 | const struct intel_crtc_state *new_crtc_state = |
| 5436 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5437 | unsigned int update_mask = new_crtc_state->update_planes; |
| 5438 | const struct intel_plane_state *old_plane_state; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5439 | struct intel_plane *plane; |
| 5440 | unsigned fb_bits = 0; |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5441 | int i; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5442 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5443 | intel_crtc_dpms_overlay_disable(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5444 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5445 | for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { |
| 5446 | if (crtc->pipe != plane->pipe || |
| 5447 | !(update_mask & BIT(plane->id))) |
| 5448 | continue; |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5449 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5450 | plane->disable_plane(plane, new_crtc_state); |
| 5451 | |
| 5452 | if (old_plane_state->base.visible) |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5453 | fb_bits |= plane->frontbuffer_bit; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5454 | } |
| 5455 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5456 | intel_frontbuffer_flip(dev_priv, fb_bits); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5457 | } |
| 5458 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5459 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5460 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5461 | struct drm_atomic_state *old_state) |
| 5462 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5463 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5464 | struct drm_connector *conn; |
| 5465 | int i; |
| 5466 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5467 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5468 | struct intel_encoder *encoder = |
| 5469 | to_intel_encoder(conn_state->best_encoder); |
| 5470 | |
| 5471 | if (conn_state->crtc != crtc) |
| 5472 | continue; |
| 5473 | |
| 5474 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5475 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5476 | } |
| 5477 | } |
| 5478 | |
| 5479 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5480 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5481 | struct drm_atomic_state *old_state) |
| 5482 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5483 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5484 | struct drm_connector *conn; |
| 5485 | int i; |
| 5486 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5487 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5488 | struct intel_encoder *encoder = |
| 5489 | to_intel_encoder(conn_state->best_encoder); |
| 5490 | |
| 5491 | if (conn_state->crtc != crtc) |
| 5492 | continue; |
| 5493 | |
| 5494 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5495 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5496 | } |
| 5497 | } |
| 5498 | |
| 5499 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5500 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5501 | struct drm_atomic_state *old_state) |
| 5502 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5503 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5504 | struct drm_connector *conn; |
| 5505 | int i; |
| 5506 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5507 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5508 | struct intel_encoder *encoder = |
| 5509 | to_intel_encoder(conn_state->best_encoder); |
| 5510 | |
| 5511 | if (conn_state->crtc != crtc) |
| 5512 | continue; |
| 5513 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5514 | if (encoder->enable) |
| 5515 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5516 | intel_opregion_notify_encoder(encoder, true); |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5521 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5522 | struct drm_atomic_state *old_state) |
| 5523 | { |
| 5524 | struct drm_connector_state *old_conn_state; |
| 5525 | struct drm_connector *conn; |
| 5526 | int i; |
| 5527 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5528 | 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] | 5529 | struct intel_encoder *encoder = |
| 5530 | to_intel_encoder(old_conn_state->best_encoder); |
| 5531 | |
| 5532 | if (old_conn_state->crtc != crtc) |
| 5533 | continue; |
| 5534 | |
| 5535 | intel_opregion_notify_encoder(encoder, false); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5536 | if (encoder->disable) |
| 5537 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5542 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5543 | struct drm_atomic_state *old_state) |
| 5544 | { |
| 5545 | struct drm_connector_state *old_conn_state; |
| 5546 | struct drm_connector *conn; |
| 5547 | int i; |
| 5548 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5549 | 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] | 5550 | struct intel_encoder *encoder = |
| 5551 | to_intel_encoder(old_conn_state->best_encoder); |
| 5552 | |
| 5553 | if (old_conn_state->crtc != crtc) |
| 5554 | continue; |
| 5555 | |
| 5556 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5557 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5562 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5563 | struct drm_atomic_state *old_state) |
| 5564 | { |
| 5565 | struct drm_connector_state *old_conn_state; |
| 5566 | struct drm_connector *conn; |
| 5567 | int i; |
| 5568 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5569 | 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] | 5570 | struct intel_encoder *encoder = |
| 5571 | to_intel_encoder(old_conn_state->best_encoder); |
| 5572 | |
| 5573 | if (old_conn_state->crtc != crtc) |
| 5574 | continue; |
| 5575 | |
| 5576 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5577 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5578 | } |
| 5579 | } |
| 5580 | |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 5581 | static void intel_encoders_update_pipe(struct drm_crtc *crtc, |
| 5582 | struct intel_crtc_state *crtc_state, |
| 5583 | struct drm_atomic_state *old_state) |
| 5584 | { |
| 5585 | struct drm_connector_state *conn_state; |
| 5586 | struct drm_connector *conn; |
| 5587 | int i; |
| 5588 | |
| 5589 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
| 5590 | struct intel_encoder *encoder = |
| 5591 | to_intel_encoder(conn_state->best_encoder); |
| 5592 | |
| 5593 | if (conn_state->crtc != crtc) |
| 5594 | continue; |
| 5595 | |
| 5596 | if (encoder->update_pipe) |
| 5597 | encoder->update_pipe(encoder, crtc_state, conn_state); |
| 5598 | } |
| 5599 | } |
| 5600 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5601 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5602 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5603 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5604 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5605 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5606 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5607 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5608 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5609 | struct intel_atomic_state *old_intel_state = |
| 5610 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5611 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5612 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5613 | return; |
| 5614 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5615 | /* |
| 5616 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5617 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5618 | * |
| 5619 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5620 | * between eDP port A enable and vdd enable. Also PCH port |
| 5621 | * enable seems to result in the occasional CPU pipe underrun. |
| 5622 | * |
| 5623 | * Spurious PCH underruns also occur during PCH enabling. |
| 5624 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5625 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5626 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5627 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5628 | if (pipe_config->has_pch_encoder) |
| 5629 | intel_prepare_shared_dpll(pipe_config); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5630 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5631 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5632 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5633 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5634 | intel_set_pipe_timings(pipe_config); |
| 5635 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5636 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5637 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5638 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5639 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5640 | } |
| 5641 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5642 | ironlake_set_pipeconf(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5643 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5644 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5645 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5646 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5647 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5648 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5649 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5650 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5651 | * enabling. */ |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 5652 | ironlake_fdi_pll_enable(pipe_config); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5653 | } else { |
| 5654 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5655 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5656 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5657 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5658 | ironlake_pfit_enable(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5659 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5660 | /* |
| 5661 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5662 | * clocks enabled |
| 5663 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5664 | intel_color_load_luts(pipe_config); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5665 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5666 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5667 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5668 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5669 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5670 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5671 | ironlake_pch_enable(old_intel_state, pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5672 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5673 | assert_vblank_disabled(crtc); |
| 5674 | drm_crtc_vblank_on(crtc); |
| 5675 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5676 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5677 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5678 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5679 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5680 | |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5681 | /* |
| 5682 | * Must wait for vblank to avoid spurious PCH FIFO underruns. |
| 5683 | * And a second vblank wait is needed at least on ILK with |
| 5684 | * some interlaced HDMI modes. Let's do the double wait always |
| 5685 | * in case there are more corner cases we don't know about. |
| 5686 | */ |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5687 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5688 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5689 | intel_wait_for_vblank(dev_priv, pipe); |
| 5690 | } |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5691 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5692 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5693 | } |
| 5694 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5695 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5696 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5697 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5698 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5699 | } |
| 5700 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5701 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5702 | enum pipe pipe, bool apply) |
| 5703 | { |
| 5704 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5705 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5706 | |
| 5707 | if (apply) |
| 5708 | val |= mask; |
| 5709 | else |
| 5710 | val &= ~mask; |
| 5711 | |
| 5712 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5713 | } |
| 5714 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5715 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5716 | { |
| 5717 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5718 | enum pipe pipe = crtc->pipe; |
| 5719 | uint32_t val; |
| 5720 | |
Rodrigo Vivi | 443d5e3 | 2018-10-04 08:18:14 -0700 | [diff] [blame] | 5721 | val = MBUS_DBOX_A_CREDIT(2); |
| 5722 | val |= MBUS_DBOX_BW_CREDIT(1); |
| 5723 | val |= MBUS_DBOX_B_CREDIT(8); |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5724 | |
| 5725 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5726 | } |
| 5727 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5728 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5729 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5730 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5731 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5732 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5733 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5734 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5735 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5736 | struct intel_atomic_state *old_intel_state = |
| 5737 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5738 | bool psl_clkgate_wa; |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5739 | u32 pipe_chicken; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5740 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5741 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5742 | return; |
| 5743 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5744 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5745 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5746 | if (pipe_config->shared_dpll) |
| 5747 | intel_enable_shared_dpll(pipe_config); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5748 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame] | 5749 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5750 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5751 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5752 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5753 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5754 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5755 | intel_set_pipe_timings(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5756 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5757 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5758 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5759 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5760 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5761 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5762 | pipe_config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5763 | } |
| 5764 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5765 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5766 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5767 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5768 | } |
| 5769 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5770 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5771 | haswell_set_pipeconf(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5772 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5773 | haswell_set_pipemisc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5774 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5775 | intel_color_set_csc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5776 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5777 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5778 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5779 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5780 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5781 | pipe_config->pch_pfit.enabled; |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5782 | if (psl_clkgate_wa) |
| 5783 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5784 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5785 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5786 | skylake_pfit_enable(pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5787 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5788 | ironlake_pfit_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5789 | |
| 5790 | /* |
| 5791 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5792 | * clocks enabled |
| 5793 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5794 | intel_color_load_luts(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5795 | |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5796 | /* |
| 5797 | * Display WA #1153: enable hardware to bypass the alpha math |
| 5798 | * and rounding for per-pixel values 00 and 0xff |
| 5799 | */ |
| 5800 | if (INTEL_GEN(dev_priv) >= 11) { |
| 5801 | pipe_chicken = I915_READ(PIPE_CHICKEN(pipe)); |
| 5802 | if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN)) |
| 5803 | I915_WRITE_FW(PIPE_CHICKEN(pipe), |
| 5804 | pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN); |
| 5805 | } |
| 5806 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5807 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5808 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5809 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5810 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5811 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5812 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5813 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5814 | if (INTEL_GEN(dev_priv) >= 11) |
| 5815 | icl_pipe_mbus_enable(intel_crtc); |
| 5816 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5817 | /* 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] | 5818 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5819 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5820 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5821 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5822 | lpt_pch_enable(old_intel_state, pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5823 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5824 | 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] | 5825 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5826 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5827 | assert_vblank_disabled(crtc); |
| 5828 | drm_crtc_vblank_on(crtc); |
| 5829 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5830 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5831 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5832 | if (psl_clkgate_wa) { |
| 5833 | intel_wait_for_vblank(dev_priv, pipe); |
| 5834 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5835 | } |
| 5836 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5837 | /* If we change the relative order between pipe/planes enabling, we need |
| 5838 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5839 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5840 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5841 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5842 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5843 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5844 | } |
| 5845 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5846 | 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] | 5847 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5848 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5849 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5850 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5851 | |
| 5852 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5853 | * 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] | 5854 | if (old_crtc_state->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5855 | I915_WRITE(PF_CTL(pipe), 0); |
| 5856 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5857 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5858 | } |
| 5859 | } |
| 5860 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5861 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5862 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5863 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5864 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5865 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5866 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5867 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5868 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5869 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5870 | /* |
| 5871 | * Sometimes spurious CPU pipe underruns happen when the |
| 5872 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 5873 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 5874 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5875 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5876 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5877 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5878 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5879 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5880 | drm_crtc_vblank_off(crtc); |
| 5881 | assert_vblank_disabled(crtc); |
| 5882 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5883 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5884 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5885 | ironlake_pfit_disable(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5886 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5887 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 5888 | ironlake_fdi_disable(crtc); |
| 5889 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5890 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5891 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5892 | if (old_crtc_state->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5893 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5894 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5895 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5896 | i915_reg_t reg; |
| 5897 | u32 temp; |
| 5898 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5899 | /* disable TRANS_DP_CTL */ |
| 5900 | reg = TRANS_DP_CTL(pipe); |
| 5901 | temp = I915_READ(reg); |
| 5902 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5903 | TRANS_DP_PORT_SEL_MASK); |
| 5904 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5905 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5906 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5907 | /* disable DPLL_SEL */ |
| 5908 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5909 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5910 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5911 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5912 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5913 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5914 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5915 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5916 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5917 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5920 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5921 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5922 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5923 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5924 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5925 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5926 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5927 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5928 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5929 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5930 | drm_crtc_vblank_off(crtc); |
| 5931 | assert_vblank_disabled(crtc); |
| 5932 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5933 | /* 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] | 5934 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5935 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5936 | |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5937 | if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) |
| 5938 | intel_ddi_set_vc_payload_alloc(old_crtc_state, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5939 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5940 | if (!transcoder_is_dsi(cpu_transcoder)) |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 5941 | intel_ddi_disable_transcoder_func(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5942 | |
Manasi Navare | a600622 | 2018-11-28 12:26:23 -0800 | [diff] [blame] | 5943 | intel_dsc_disable(old_crtc_state); |
| 5944 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5945 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5946 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5947 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5948 | ironlake_pfit_disable(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5949 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5950 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5951 | |
Imre Deak | bdaa29b | 2018-11-01 16:04:24 +0200 | [diff] [blame] | 5952 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5953 | } |
| 5954 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5955 | static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5956 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5957 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5958 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5959 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5960 | if (!crtc_state->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5961 | return; |
| 5962 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5963 | /* |
| 5964 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5965 | * according to register description and PRM. |
| 5966 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5967 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5968 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5969 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5970 | I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios); |
| 5971 | I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5972 | |
| 5973 | /* Border color in case we don't scale up to the full screen. Black by |
| 5974 | * default, change to something else for debugging. */ |
| 5975 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5976 | } |
| 5977 | |
Mahesh Kumar | 176597a | 2018-10-04 14:20:43 +0530 | [diff] [blame] | 5978 | bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port) |
| 5979 | { |
| 5980 | if (port == PORT_NONE) |
| 5981 | return false; |
| 5982 | |
| 5983 | if (IS_ICELAKE(dev_priv)) |
| 5984 | return port <= PORT_B; |
| 5985 | |
| 5986 | return false; |
| 5987 | } |
| 5988 | |
Paulo Zanoni | ac213c1 | 2018-05-21 17:25:37 -0700 | [diff] [blame] | 5989 | bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5990 | { |
| 5991 | if (IS_ICELAKE(dev_priv)) |
| 5992 | return port >= PORT_C && port <= PORT_F; |
| 5993 | |
| 5994 | return false; |
| 5995 | } |
| 5996 | |
| 5997 | enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5998 | { |
| 5999 | if (!intel_port_is_tc(dev_priv, port)) |
| 6000 | return PORT_TC_NONE; |
| 6001 | |
| 6002 | return port - PORT_C; |
| 6003 | } |
| 6004 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6005 | 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] | 6006 | { |
| 6007 | switch (port) { |
| 6008 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6009 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6010 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6011 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6012 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6013 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6014 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6015 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 6016 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6017 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 6018 | case PORT_F: |
| 6019 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6020 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 6021 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6022 | return POWER_DOMAIN_PORT_OTHER; |
| 6023 | } |
| 6024 | } |
| 6025 | |
Imre Deak | 337837a | 2018-11-01 16:04:23 +0200 | [diff] [blame] | 6026 | enum intel_display_power_domain |
| 6027 | intel_aux_power_domain(struct intel_digital_port *dig_port) |
| 6028 | { |
| 6029 | switch (dig_port->aux_ch) { |
| 6030 | case AUX_CH_A: |
| 6031 | return POWER_DOMAIN_AUX_A; |
| 6032 | case AUX_CH_B: |
| 6033 | return POWER_DOMAIN_AUX_B; |
| 6034 | case AUX_CH_C: |
| 6035 | return POWER_DOMAIN_AUX_C; |
| 6036 | case AUX_CH_D: |
| 6037 | return POWER_DOMAIN_AUX_D; |
| 6038 | case AUX_CH_E: |
| 6039 | return POWER_DOMAIN_AUX_E; |
| 6040 | case AUX_CH_F: |
| 6041 | return POWER_DOMAIN_AUX_F; |
| 6042 | default: |
| 6043 | MISSING_CASE(dig_port->aux_ch); |
| 6044 | return POWER_DOMAIN_AUX_A; |
| 6045 | } |
| 6046 | } |
| 6047 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6048 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 6049 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6050 | { |
| 6051 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6052 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6053 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6054 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6055 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6056 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6057 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6058 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6059 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6060 | return 0; |
| 6061 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6062 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 6063 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6064 | if (crtc_state->pch_pfit.enabled || |
| 6065 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6066 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6067 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6068 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 6069 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 6070 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6071 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6072 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6073 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6074 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6075 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6076 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6077 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6078 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6079 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6080 | return mask; |
| 6081 | } |
| 6082 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6083 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6084 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 6085 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6086 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6087 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6088 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6089 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6090 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6091 | |
| 6092 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6093 | intel_crtc->enabled_power_domains = new_domains = |
| 6094 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6095 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6096 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6097 | |
| 6098 | for_each_power_domain(domain, domains) |
| 6099 | intel_display_power_get(dev_priv, domain); |
| 6100 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6101 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6102 | } |
| 6103 | |
| 6104 | 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] | 6105 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6106 | { |
| 6107 | enum intel_display_power_domain domain; |
| 6108 | |
| 6109 | for_each_power_domain(domain, domains) |
| 6110 | intel_display_power_put(dev_priv, domain); |
| 6111 | } |
| 6112 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6113 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6114 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6115 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6116 | struct intel_atomic_state *old_intel_state = |
| 6117 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6118 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6119 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6120 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6121 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6122 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6123 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6124 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6125 | return; |
| 6126 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6127 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6128 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6129 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6130 | intel_set_pipe_timings(pipe_config); |
| 6131 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6132 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6133 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6134 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6135 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6136 | } |
| 6137 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6138 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6139 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6140 | intel_color_set_csc(pipe_config); |
P Raviraj Sitaram | c59d2da | 2018-09-10 19:57:14 +0530 | [diff] [blame] | 6141 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6142 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6143 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6144 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6145 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6146 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6147 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6148 | if (IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6149 | chv_prepare_pll(intel_crtc, pipe_config); |
| 6150 | chv_enable_pll(intel_crtc, pipe_config); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6151 | } else { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6152 | vlv_prepare_pll(intel_crtc, pipe_config); |
| 6153 | vlv_enable_pll(intel_crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6154 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6155 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6156 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6157 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6158 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6159 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6160 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6161 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6162 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6163 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6164 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6165 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6166 | assert_vblank_disabled(crtc); |
| 6167 | drm_crtc_vblank_on(crtc); |
| 6168 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6169 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6172 | 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] | 6173 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6174 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6175 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6176 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6177 | I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0); |
| 6178 | I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6179 | } |
| 6180 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6181 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6182 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6183 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6184 | struct intel_atomic_state *old_intel_state = |
| 6185 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6186 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6187 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6188 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6189 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6190 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6191 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6192 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6193 | return; |
| 6194 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6195 | i9xx_set_pll_dividers(pipe_config); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6196 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6197 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6198 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6199 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6200 | intel_set_pipe_timings(pipe_config); |
| 6201 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6202 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6203 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6204 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6205 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6206 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6207 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6208 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6209 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6210 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6211 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 6212 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6213 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6214 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6215 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6216 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6217 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6218 | if (dev_priv->display.initial_watermarks != NULL) |
| 6219 | dev_priv->display.initial_watermarks(old_intel_state, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6220 | pipe_config); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6221 | else |
| 6222 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6223 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6224 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6225 | assert_vblank_disabled(crtc); |
| 6226 | drm_crtc_vblank_on(crtc); |
| 6227 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6228 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6229 | } |
| 6230 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6231 | 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] | 6232 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6233 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 6234 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6235 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6236 | if (!old_crtc_state->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6237 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6238 | |
| 6239 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6240 | |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 6241 | DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n", |
| 6242 | I915_READ(PFIT_CONTROL)); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6243 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6244 | } |
| 6245 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6246 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6247 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6248 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6249 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6250 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6251 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6252 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6253 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6254 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6255 | /* |
| 6256 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6257 | * wait for planes to fully turn off before disabling the pipe. |
| 6258 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6259 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6260 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6261 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6262 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6263 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6264 | drm_crtc_vblank_off(crtc); |
| 6265 | assert_vblank_disabled(crtc); |
| 6266 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6267 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6268 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6269 | i9xx_pfit_disable(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6270 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6271 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6272 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6273 | if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6274 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6275 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6276 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6277 | vlv_disable_pll(dev_priv, pipe); |
| 6278 | else |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6279 | i9xx_disable_pll(old_crtc_state); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6280 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6281 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6282 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6283 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6284 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6285 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6286 | |
| 6287 | if (!dev_priv->display.initial_watermarks) |
| 6288 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6289 | |
| 6290 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6291 | if (IS_I830(dev_priv)) |
| 6292 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6295 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6296 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6297 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6298 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6299 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6300 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6301 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6302 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6303 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6304 | struct drm_atomic_state *state; |
| 6305 | struct intel_crtc_state *crtc_state; |
| 6306 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6307 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6308 | if (!intel_crtc->active) |
| 6309 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6310 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6311 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6312 | const struct intel_plane_state *plane_state = |
| 6313 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6314 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6315 | if (plane_state->base.visible) |
| 6316 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6317 | } |
| 6318 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6319 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6320 | if (!state) { |
| 6321 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6322 | crtc->base.id, crtc->name); |
| 6323 | return; |
| 6324 | } |
| 6325 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6326 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6327 | |
| 6328 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6329 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6330 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6331 | |
| 6332 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6333 | |
| 6334 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6335 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6336 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6337 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6338 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6339 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6340 | |
| 6341 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6342 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6343 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6344 | crtc->enabled = false; |
| 6345 | crtc->state->connector_mask = 0; |
| 6346 | crtc->state->encoder_mask = 0; |
| 6347 | |
| 6348 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6349 | encoder->base.crtc = NULL; |
| 6350 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6351 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6352 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 6353 | intel_disable_shared_dpll(to_intel_crtc_state(crtc->state)); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6354 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6355 | domains = intel_crtc->enabled_power_domains; |
| 6356 | for_each_power_domain(domain, domains) |
| 6357 | intel_display_power_put(dev_priv, domain); |
| 6358 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6359 | |
| 6360 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6361 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6362 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6363 | } |
| 6364 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6365 | /* |
| 6366 | * turn all crtc's off, but do not adjust state |
| 6367 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6368 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6369 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6370 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6371 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6372 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6373 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6374 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6375 | state = drm_atomic_helper_suspend(dev); |
| 6376 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6377 | if (ret) |
| 6378 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6379 | else |
| 6380 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6381 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6382 | } |
| 6383 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6384 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6385 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6386 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6387 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6388 | drm_encoder_cleanup(encoder); |
| 6389 | kfree(intel_encoder); |
| 6390 | } |
| 6391 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6392 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6393 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6394 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6395 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6396 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6397 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6398 | |
| 6399 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6400 | connector->base.base.id, |
| 6401 | connector->base.name); |
| 6402 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6403 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6404 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6405 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6406 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6407 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6408 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6409 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6410 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6411 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6412 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6413 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6414 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6415 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6416 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6417 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6418 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6419 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6420 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6421 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6422 | "attached encoder crtc differs from connector crtc\n"); |
| 6423 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6424 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6425 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6426 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6427 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6428 | } |
| 6429 | } |
| 6430 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6431 | 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] | 6432 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6433 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6434 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6435 | |
| 6436 | return 0; |
| 6437 | } |
| 6438 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6439 | 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] | 6440 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6441 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6442 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6443 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6444 | struct intel_crtc *other_crtc; |
| 6445 | struct intel_crtc_state *other_crtc_state; |
| 6446 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6447 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6448 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6449 | if (pipe_config->fdi_lanes > 4) { |
| 6450 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6451 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6452 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6453 | } |
| 6454 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6455 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6456 | if (pipe_config->fdi_lanes > 2) { |
| 6457 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6458 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6459 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6460 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6461 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6462 | } |
| 6463 | } |
| 6464 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6465 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6466 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6467 | |
| 6468 | /* Ivybridge 3 pipe is really complicated */ |
| 6469 | switch (pipe) { |
| 6470 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6471 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6472 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6473 | if (pipe_config->fdi_lanes <= 2) |
| 6474 | return 0; |
| 6475 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6476 | 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] | 6477 | other_crtc_state = |
| 6478 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6479 | if (IS_ERR(other_crtc_state)) |
| 6480 | return PTR_ERR(other_crtc_state); |
| 6481 | |
| 6482 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6483 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6484 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6485 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6486 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6487 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6488 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6489 | if (pipe_config->fdi_lanes > 2) { |
| 6490 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6491 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6492 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6493 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6494 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6495 | 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] | 6496 | other_crtc_state = |
| 6497 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6498 | if (IS_ERR(other_crtc_state)) |
| 6499 | return PTR_ERR(other_crtc_state); |
| 6500 | |
| 6501 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6502 | 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] | 6503 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6504 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6505 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6506 | default: |
| 6507 | BUG(); |
| 6508 | } |
| 6509 | } |
| 6510 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6511 | #define RETRY 1 |
| 6512 | 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] | 6513 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6514 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6515 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6516 | 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] | 6517 | int lane, link_bw, fdi_dotclock, ret; |
| 6518 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6519 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6520 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6521 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6522 | * each output octet as 10 bits. The actual frequency |
| 6523 | * is stored as a divider into a 100MHz clock, and the |
| 6524 | * mode pixel clock is stored in units of 1KHz. |
| 6525 | * Hence the bw of each lane in terms of the mode signal |
| 6526 | * is: |
| 6527 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6528 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6529 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6530 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6531 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6532 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6533 | pipe_config->pipe_bpp); |
| 6534 | |
| 6535 | pipe_config->fdi_lanes = lane; |
| 6536 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6537 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6538 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6539 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6540 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 6541 | if (ret == -EDEADLK) |
| 6542 | return ret; |
| 6543 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6544 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6545 | pipe_config->pipe_bpp -= 2*3; |
| 6546 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6547 | pipe_config->pipe_bpp); |
| 6548 | needs_recompute = true; |
| 6549 | pipe_config->bw_constrained = true; |
| 6550 | |
| 6551 | goto retry; |
| 6552 | } |
| 6553 | |
| 6554 | if (needs_recompute) |
| 6555 | return RETRY; |
| 6556 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6557 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6558 | } |
| 6559 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6560 | 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] | 6561 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6562 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6563 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6564 | |
| 6565 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6566 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6567 | return false; |
| 6568 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6569 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6570 | return false; |
| 6571 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6572 | if (crtc_state->pipe_bpp > 24) |
| 6573 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6574 | |
| 6575 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6576 | * We compare against max which means we must take |
| 6577 | * the increased cdclk requirement into account when |
| 6578 | * calculating the new cdclk. |
| 6579 | * |
| 6580 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6581 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6582 | if (IS_BROADWELL(dev_priv) && |
| 6583 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6584 | return false; |
| 6585 | |
| 6586 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6587 | } |
| 6588 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6589 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6590 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6591 | struct drm_i915_private *dev_priv = |
| 6592 | to_i915(crtc_state->base.crtc->dev); |
| 6593 | struct intel_atomic_state *intel_state = |
| 6594 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6595 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6596 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6597 | return false; |
| 6598 | |
| 6599 | if (crtc_state->ips_force_disable) |
| 6600 | return false; |
| 6601 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6602 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6603 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6604 | return false; |
| 6605 | |
| 6606 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6607 | if (IS_BROADWELL(dev_priv) && |
| 6608 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6609 | return false; |
| 6610 | |
| 6611 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6612 | } |
| 6613 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6614 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6615 | { |
| 6616 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6617 | |
| 6618 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6619 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6620 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6621 | } |
| 6622 | |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6623 | static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
| 6624 | { |
| 6625 | uint32_t pixel_rate; |
| 6626 | |
| 6627 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6628 | |
| 6629 | /* |
| 6630 | * We only use IF-ID interlacing. If we ever use |
| 6631 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6632 | */ |
| 6633 | |
| 6634 | if (pipe_config->pch_pfit.enabled) { |
| 6635 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
| 6636 | uint32_t pfit_size = pipe_config->pch_pfit.size; |
| 6637 | |
| 6638 | pipe_w = pipe_config->pipe_src_w; |
| 6639 | pipe_h = pipe_config->pipe_src_h; |
| 6640 | |
| 6641 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6642 | pfit_h = pfit_size & 0xFFFF; |
| 6643 | if (pipe_w < pfit_w) |
| 6644 | pipe_w = pfit_w; |
| 6645 | if (pipe_h < pfit_h) |
| 6646 | pipe_h = pfit_h; |
| 6647 | |
| 6648 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6649 | return pixel_rate; |
| 6650 | |
| 6651 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 6652 | pfit_w * pfit_h); |
| 6653 | } |
| 6654 | |
| 6655 | return pixel_rate; |
| 6656 | } |
| 6657 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6658 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6659 | { |
| 6660 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6661 | |
| 6662 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 6663 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6664 | crtc_state->pixel_rate = |
| 6665 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6666 | else |
| 6667 | crtc_state->pixel_rate = |
| 6668 | ilk_pipe_pixel_rate(crtc_state); |
| 6669 | } |
| 6670 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6671 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6672 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6673 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6674 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6675 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6676 | 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] | 6677 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6678 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6679 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6680 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6681 | |
| 6682 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6683 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6684 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6685 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6686 | if (intel_crtc_supports_double_wide(crtc) && |
| 6687 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6688 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6689 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6690 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6691 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6692 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6693 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6694 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6695 | adjusted_mode->crtc_clock, clock_limit, |
| 6696 | yesno(pipe_config->double_wide)); |
| 6697 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6698 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6699 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 6700 | if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 6701 | pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) && |
| 6702 | pipe_config->base.ctm) { |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6703 | /* |
| 6704 | * There is only one pipe CSC unit per pipe, and we need that |
| 6705 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6706 | * applied we can't support YCBCR420 output. |
| 6707 | */ |
| 6708 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6709 | return -EINVAL; |
| 6710 | } |
| 6711 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6712 | /* |
| 6713 | * Pipe horizontal size must be even in: |
| 6714 | * - DVO ganged mode |
| 6715 | * - LVDS dual channel mode |
| 6716 | * - Double wide pipe |
| 6717 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6718 | if (pipe_config->pipe_src_w & 1) { |
| 6719 | if (pipe_config->double_wide) { |
| 6720 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6721 | return -EINVAL; |
| 6722 | } |
| 6723 | |
| 6724 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6725 | intel_is_dual_link_lvds(dev)) { |
| 6726 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6727 | return -EINVAL; |
| 6728 | } |
| 6729 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6730 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6731 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6732 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6733 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6734 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6735 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6736 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6737 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6738 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6739 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6740 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6741 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6742 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6743 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6744 | } |
| 6745 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6746 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6747 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6748 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6749 | while (*num > DATA_LINK_M_N_MASK || |
| 6750 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6751 | *num >>= 1; |
| 6752 | *den >>= 1; |
| 6753 | } |
| 6754 | } |
| 6755 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6756 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6757 | uint32_t *ret_m, uint32_t *ret_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6758 | bool constant_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6759 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6760 | /* |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6761 | * Several DP dongles in particular seem to be fussy about |
| 6762 | * too large link M/N values. Give N value as 0x8000 that |
| 6763 | * should be acceptable by specific devices. 0x8000 is the |
| 6764 | * specified fixed N value for asynchronous clock mode, |
| 6765 | * which the devices expect also in synchronous clock mode. |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6766 | */ |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6767 | if (constant_n) |
| 6768 | *ret_n = 0x8000; |
| 6769 | else |
| 6770 | *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] | 6771 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6772 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6773 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6774 | } |
| 6775 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6776 | void |
Manasi Navare | a4a1577 | 2018-11-28 13:36:21 -0800 | [diff] [blame] | 6777 | intel_link_compute_m_n(u16 bits_per_pixel, int nlanes, |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6778 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6779 | struct intel_link_m_n *m_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6780 | bool constant_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6781 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6782 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6783 | |
| 6784 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6785 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6786 | &m_n->gmch_m, &m_n->gmch_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6787 | constant_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6788 | |
| 6789 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6790 | &m_n->link_m, &m_n->link_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6791 | constant_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6792 | } |
| 6793 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6794 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6795 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6796 | if (i915_modparams.panel_use_ssc >= 0) |
| 6797 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6798 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6799 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6800 | } |
| 6801 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6802 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6803 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6804 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6805 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6806 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6807 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6808 | { |
| 6809 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6812 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6813 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6814 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6815 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6816 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6817 | u32 fp, fp2 = 0; |
| 6818 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6819 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6820 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6821 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6822 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6823 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6824 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6825 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6826 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6827 | } |
| 6828 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6829 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6830 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6831 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6832 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6833 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6834 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6835 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6836 | } |
| 6837 | } |
| 6838 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6839 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6840 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6841 | { |
| 6842 | u32 reg_val; |
| 6843 | |
| 6844 | /* |
| 6845 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6846 | * and set it to a reasonable value instead. |
| 6847 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6848 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6849 | reg_val &= 0xffffff00; |
| 6850 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6851 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6852 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6853 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 6854 | reg_val &= 0x00ffffff; |
| 6855 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6856 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6857 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6858 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6859 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6860 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6861 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6862 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6863 | reg_val &= 0x00ffffff; |
| 6864 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6865 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6866 | } |
| 6867 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6868 | static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 6869 | const struct intel_link_m_n *m_n) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6870 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6871 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6872 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6873 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6874 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6875 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6876 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6877 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6878 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6879 | } |
| 6880 | |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6881 | static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv, |
| 6882 | enum transcoder transcoder) |
| 6883 | { |
| 6884 | if (IS_HASWELL(dev_priv)) |
| 6885 | return transcoder == TRANSCODER_EDP; |
| 6886 | |
| 6887 | /* |
| 6888 | * Strictly speaking some registers are available before |
| 6889 | * gen7, but we only support DRRS on gen7+ |
| 6890 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6891 | return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6892 | } |
| 6893 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6894 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 6895 | const struct intel_link_m_n *m_n, |
| 6896 | const struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6897 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6898 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6899 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6900 | enum pipe pipe = crtc->pipe; |
| 6901 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6902 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6903 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6904 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6905 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6906 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6907 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6908 | /* |
| 6909 | * M2_N2 registers are set only if DRRS is supported |
| 6910 | * (to make sure the registers are not unnecessarily accessed). |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6911 | */ |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6912 | if (m2_n2 && crtc_state->has_drrs && |
| 6913 | transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6914 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6915 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6916 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6917 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6918 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6919 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6920 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6921 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6922 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6923 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6924 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6925 | } |
| 6926 | } |
| 6927 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6928 | 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] | 6929 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6930 | 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] | 6931 | |
| 6932 | if (m_n == M1_N1) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6933 | dp_m_n = &crtc_state->dp_m_n; |
| 6934 | dp_m2_n2 = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6935 | } else if (m_n == M2_N2) { |
| 6936 | |
| 6937 | /* |
| 6938 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6939 | * needs to be programmed into M1_N1. |
| 6940 | */ |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6941 | dp_m_n = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6942 | } else { |
| 6943 | DRM_ERROR("Unsupported divider value\n"); |
| 6944 | return; |
| 6945 | } |
| 6946 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6947 | if (crtc_state->has_pch_encoder) |
| 6948 | 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] | 6949 | else |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6950 | 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] | 6951 | } |
| 6952 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 6953 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 6954 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6955 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6956 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6957 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6958 | if (crtc->pipe != PIPE_A) |
| 6959 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6960 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6961 | /* 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] | 6962 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6963 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 6964 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 6965 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6966 | pipe_config->dpll_hw_state.dpll_md = |
| 6967 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 6968 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6969 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6970 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 6971 | struct intel_crtc_state *pipe_config) |
| 6972 | { |
| 6973 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6974 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6975 | if (crtc->pipe != PIPE_A) |
| 6976 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6977 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6978 | /* 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] | 6979 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6980 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 6981 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6982 | pipe_config->dpll_hw_state.dpll_md = |
| 6983 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6984 | } |
| 6985 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6986 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6987 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6988 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6989 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6990 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6991 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6992 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6993 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6994 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6995 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6996 | /* Enable Refclk */ |
| 6997 | I915_WRITE(DPLL(pipe), |
| 6998 | pipe_config->dpll_hw_state.dpll & |
| 6999 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 7000 | |
| 7001 | /* No need to actually set up the DPLL with DSI */ |
| 7002 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7003 | return; |
| 7004 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7005 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7006 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7007 | bestn = pipe_config->dpll.n; |
| 7008 | bestm1 = pipe_config->dpll.m1; |
| 7009 | bestm2 = pipe_config->dpll.m2; |
| 7010 | bestp1 = pipe_config->dpll.p1; |
| 7011 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7012 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7013 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7014 | |
| 7015 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7016 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7017 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7018 | |
| 7019 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7020 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7021 | |
| 7022 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7023 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7024 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7025 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7026 | |
| 7027 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7028 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7029 | |
| 7030 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7031 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7032 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7033 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7034 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7035 | |
| 7036 | /* |
| 7037 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7038 | * but we don't support that). |
| 7039 | * Note: don't use the DAC post divider as it seems unstable. |
| 7040 | */ |
| 7041 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7042 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7043 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7044 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7045 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7046 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7047 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7048 | if (pipe_config->port_clock == 162000 || |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7049 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) || |
| 7050 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7051 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7052 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7053 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7054 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7055 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7056 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7057 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7058 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7059 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7060 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7061 | 0x0df40000); |
| 7062 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7063 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7064 | 0x0df70000); |
| 7065 | } else { /* HDMI or VGA */ |
| 7066 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7067 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7068 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7069 | 0x0df70000); |
| 7070 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7071 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7072 | 0x0df40000); |
| 7073 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7074 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7075 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7076 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7077 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7078 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7079 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7080 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7081 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7082 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7083 | } |
| 7084 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7085 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7086 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7087 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7088 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7089 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7090 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7091 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7092 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7093 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7094 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7095 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7096 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7097 | /* Enable Refclk and SSC */ |
| 7098 | I915_WRITE(DPLL(pipe), |
| 7099 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7100 | |
| 7101 | /* No need to actually set up the DPLL with DSI */ |
| 7102 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7103 | return; |
| 7104 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7105 | bestn = pipe_config->dpll.n; |
| 7106 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7107 | bestm1 = pipe_config->dpll.m1; |
| 7108 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7109 | bestp1 = pipe_config->dpll.p1; |
| 7110 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7111 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7112 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7113 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7114 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7115 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7116 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7117 | /* p1 and p2 divider */ |
| 7118 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7119 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7120 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7121 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7122 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7123 | |
| 7124 | /* Feedback post-divider - m2 */ |
| 7125 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7126 | |
| 7127 | /* Feedback refclk divider - n and m1 */ |
| 7128 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7129 | DPIO_CHV_M1_DIV_BY_2 | |
| 7130 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7131 | |
| 7132 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7133 | 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] | 7134 | |
| 7135 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7136 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7137 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7138 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7139 | if (bestm2_frac) |
| 7140 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7141 | 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] | 7142 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7143 | /* Program digital lock detect threshold */ |
| 7144 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7145 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7146 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7147 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7148 | if (!bestm2_frac) |
| 7149 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7150 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7151 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7152 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7153 | if (vco == 5400000) { |
| 7154 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7155 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7156 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7157 | tribuf_calcntr = 0x9; |
| 7158 | } else if (vco <= 6200000) { |
| 7159 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7160 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7161 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7162 | tribuf_calcntr = 0x9; |
| 7163 | } else if (vco <= 6480000) { |
| 7164 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7165 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7166 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7167 | tribuf_calcntr = 0x8; |
| 7168 | } else { |
| 7169 | /* Not supported. Apply the same limits as in the max case */ |
| 7170 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7171 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7172 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7173 | tribuf_calcntr = 0; |
| 7174 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7175 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7176 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7177 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7178 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7179 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7180 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7181 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7182 | /* AFC Recal */ |
| 7183 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7184 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7185 | DPIO_AFC_RECAL); |
| 7186 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7187 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7188 | } |
| 7189 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7190 | /** |
| 7191 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7192 | * @dev_priv: i915 private structure |
| 7193 | * @pipe: pipe PLL to enable |
| 7194 | * @dpll: PLL configuration |
| 7195 | * |
| 7196 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7197 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7198 | * be enabled. |
| 7199 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7200 | 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] | 7201 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7202 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7203 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7204 | struct intel_crtc_state *pipe_config; |
| 7205 | |
| 7206 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7207 | if (!pipe_config) |
| 7208 | return -ENOMEM; |
| 7209 | |
| 7210 | pipe_config->base.crtc = &crtc->base; |
| 7211 | pipe_config->pixel_multiplier = 1; |
| 7212 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7213 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7214 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7215 | chv_compute_dpll(crtc, pipe_config); |
| 7216 | chv_prepare_pll(crtc, pipe_config); |
| 7217 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7218 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7219 | vlv_compute_dpll(crtc, pipe_config); |
| 7220 | vlv_prepare_pll(crtc, pipe_config); |
| 7221 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7222 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7223 | |
| 7224 | kfree(pipe_config); |
| 7225 | |
| 7226 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7227 | } |
| 7228 | |
| 7229 | /** |
| 7230 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7231 | * @dev_priv: i915 private structure |
| 7232 | * @pipe: pipe PLL to disable |
| 7233 | * |
| 7234 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7235 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7236 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7237 | 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] | 7238 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7239 | if (IS_CHERRYVIEW(dev_priv)) |
| 7240 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7241 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7242 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7243 | } |
| 7244 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7245 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7246 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7247 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7248 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7249 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7250 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7251 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7252 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7253 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7254 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7255 | dpll = DPLL_VGA_MODE_DIS; |
| 7256 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7257 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7258 | dpll |= DPLLB_MODE_LVDS; |
| 7259 | else |
| 7260 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7261 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7262 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7263 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7264 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7265 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7266 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7267 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7268 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7269 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7270 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7271 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7272 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7273 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7274 | |
| 7275 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7276 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7277 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7278 | else { |
| 7279 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7280 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7281 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7282 | } |
| 7283 | switch (clock->p2) { |
| 7284 | case 5: |
| 7285 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7286 | break; |
| 7287 | case 7: |
| 7288 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7289 | break; |
| 7290 | case 10: |
| 7291 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7292 | break; |
| 7293 | case 14: |
| 7294 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7295 | break; |
| 7296 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7297 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7298 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7299 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7300 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7301 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7302 | 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] | 7303 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7304 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7305 | else |
| 7306 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7307 | |
| 7308 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7309 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7310 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7311 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7312 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7313 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7314 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7315 | } |
| 7316 | } |
| 7317 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7318 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7319 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7320 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7321 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7322 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7323 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7324 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7325 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7326 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7327 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7328 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7329 | dpll = DPLL_VGA_MODE_DIS; |
| 7330 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7331 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7332 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7333 | } else { |
| 7334 | if (clock->p1 == 2) |
| 7335 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7336 | else |
| 7337 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7338 | if (clock->p2 == 4) |
| 7339 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7340 | } |
| 7341 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7342 | if (!IS_I830(dev_priv) && |
| 7343 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7344 | dpll |= DPLL_DVO_2X_MODE; |
| 7345 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7346 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7347 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7348 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7349 | else |
| 7350 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7351 | |
| 7352 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7353 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7354 | } |
| 7355 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7356 | 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] | 7357 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7358 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7359 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7360 | enum pipe pipe = crtc->pipe; |
| 7361 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 7362 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7363 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7364 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7365 | |
| 7366 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7367 | * the hw state checker will get angry at the mismatch. */ |
| 7368 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7369 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7370 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7371 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7372 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7373 | crtc_vtotal -= 1; |
| 7374 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7375 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7376 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7377 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7378 | else |
| 7379 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7380 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7381 | if (vsyncshift < 0) |
| 7382 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7383 | } |
| 7384 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7385 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7386 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7387 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7388 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7389 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7390 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7391 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7392 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7393 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7394 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7395 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7396 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7397 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7398 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7399 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7400 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7401 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7402 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7403 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7404 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7405 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7406 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7407 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7408 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7409 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7410 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7411 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7412 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7413 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7414 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7415 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7416 | } |
| 7417 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7418 | 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] | 7419 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7420 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7421 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7422 | enum pipe pipe = crtc->pipe; |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7423 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7424 | /* pipesrc controls the size that is scaled from, which should |
| 7425 | * always be the user's requested size. |
| 7426 | */ |
| 7427 | I915_WRITE(PIPESRC(pipe), |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7428 | ((crtc_state->pipe_src_w - 1) << 16) | |
| 7429 | (crtc_state->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7430 | } |
| 7431 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7432 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7433 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7434 | { |
| 7435 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7436 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7437 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7438 | uint32_t tmp; |
| 7439 | |
| 7440 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7441 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7442 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7443 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7444 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7445 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7446 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7447 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7448 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7449 | |
| 7450 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7451 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7452 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7453 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7454 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7455 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7456 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7457 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7458 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7459 | |
| 7460 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7461 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7462 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7463 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7464 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7468 | struct intel_crtc_state *pipe_config) |
| 7469 | { |
| 7470 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7471 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7472 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7473 | |
| 7474 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7475 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7476 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7477 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7478 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7479 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7480 | } |
| 7481 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7482 | 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] | 7483 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7484 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7485 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7486 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7487 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7488 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7489 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7490 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7491 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7492 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7493 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7494 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7495 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7496 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7497 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7498 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7499 | |
| 7500 | mode->hsync = drm_mode_hsync(mode); |
| 7501 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7502 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7503 | } |
| 7504 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7505 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7506 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7507 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7508 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7509 | uint32_t pipeconf; |
| 7510 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7511 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7512 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7513 | /* we keep both pipes enabled on 830 */ |
| 7514 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7515 | pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7516 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7517 | if (crtc_state->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7518 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7519 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7520 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7521 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7522 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7523 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7524 | if (crtc_state->dither && crtc_state->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7525 | pipeconf |= PIPECONF_DITHER_EN | |
| 7526 | PIPECONF_DITHER_TYPE_SP; |
| 7527 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7528 | switch (crtc_state->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7529 | case 18: |
| 7530 | pipeconf |= PIPECONF_6BPC; |
| 7531 | break; |
| 7532 | case 24: |
| 7533 | pipeconf |= PIPECONF_8BPC; |
| 7534 | break; |
| 7535 | case 30: |
| 7536 | pipeconf |= PIPECONF_10BPC; |
| 7537 | break; |
| 7538 | default: |
| 7539 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7540 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7541 | } |
| 7542 | } |
| 7543 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7544 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7545 | if (INTEL_GEN(dev_priv) < 4 || |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7546 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7547 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7548 | else |
| 7549 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7550 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7551 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7552 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7553 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7554 | crtc_state->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7555 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7556 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7557 | I915_WRITE(PIPECONF(crtc->pipe), pipeconf); |
| 7558 | POSTING_READ(PIPECONF(crtc->pipe)); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7559 | } |
| 7560 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7561 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7562 | struct intel_crtc_state *crtc_state) |
| 7563 | { |
| 7564 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7565 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7566 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7567 | int refclk = 48000; |
| 7568 | |
| 7569 | memset(&crtc_state->dpll_hw_state, 0, |
| 7570 | sizeof(crtc_state->dpll_hw_state)); |
| 7571 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7572 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7573 | if (intel_panel_use_ssc(dev_priv)) { |
| 7574 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7575 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7576 | } |
| 7577 | |
| 7578 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7579 | } 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] | 7580 | limit = &intel_limits_i8xx_dvo; |
| 7581 | } else { |
| 7582 | limit = &intel_limits_i8xx_dac; |
| 7583 | } |
| 7584 | |
| 7585 | if (!crtc_state->clock_set && |
| 7586 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7587 | refclk, NULL, &crtc_state->dpll)) { |
| 7588 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7589 | return -EINVAL; |
| 7590 | } |
| 7591 | |
| 7592 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7593 | |
| 7594 | return 0; |
| 7595 | } |
| 7596 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7597 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7598 | struct intel_crtc_state *crtc_state) |
| 7599 | { |
| 7600 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7601 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7602 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7603 | int refclk = 96000; |
| 7604 | |
| 7605 | memset(&crtc_state->dpll_hw_state, 0, |
| 7606 | sizeof(crtc_state->dpll_hw_state)); |
| 7607 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7608 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7609 | if (intel_panel_use_ssc(dev_priv)) { |
| 7610 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7611 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7612 | } |
| 7613 | |
| 7614 | if (intel_is_dual_link_lvds(dev)) |
| 7615 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7616 | else |
| 7617 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7618 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7619 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7620 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7621 | } 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] | 7622 | limit = &intel_limits_g4x_sdvo; |
| 7623 | } else { |
| 7624 | /* The option is for other outputs */ |
| 7625 | limit = &intel_limits_i9xx_sdvo; |
| 7626 | } |
| 7627 | |
| 7628 | if (!crtc_state->clock_set && |
| 7629 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7630 | refclk, NULL, &crtc_state->dpll)) { |
| 7631 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7632 | return -EINVAL; |
| 7633 | } |
| 7634 | |
| 7635 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7636 | |
| 7637 | return 0; |
| 7638 | } |
| 7639 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7640 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7641 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7642 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7643 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7644 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7645 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7646 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7647 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7648 | memset(&crtc_state->dpll_hw_state, 0, |
| 7649 | sizeof(crtc_state->dpll_hw_state)); |
| 7650 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7651 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7652 | if (intel_panel_use_ssc(dev_priv)) { |
| 7653 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7654 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7655 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7656 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7657 | limit = &intel_limits_pineview_lvds; |
| 7658 | } else { |
| 7659 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7660 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7661 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7662 | if (!crtc_state->clock_set && |
| 7663 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7664 | refclk, NULL, &crtc_state->dpll)) { |
| 7665 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7666 | return -EINVAL; |
| 7667 | } |
| 7668 | |
| 7669 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7670 | |
| 7671 | return 0; |
| 7672 | } |
| 7673 | |
| 7674 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7675 | struct intel_crtc_state *crtc_state) |
| 7676 | { |
| 7677 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7678 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7679 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7680 | int refclk = 96000; |
| 7681 | |
| 7682 | memset(&crtc_state->dpll_hw_state, 0, |
| 7683 | sizeof(crtc_state->dpll_hw_state)); |
| 7684 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7685 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7686 | if (intel_panel_use_ssc(dev_priv)) { |
| 7687 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7688 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7689 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7690 | |
| 7691 | limit = &intel_limits_i9xx_lvds; |
| 7692 | } else { |
| 7693 | limit = &intel_limits_i9xx_sdvo; |
| 7694 | } |
| 7695 | |
| 7696 | if (!crtc_state->clock_set && |
| 7697 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7698 | refclk, NULL, &crtc_state->dpll)) { |
| 7699 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7700 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7701 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7702 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7703 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7704 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7705 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7706 | } |
| 7707 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7708 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7709 | struct intel_crtc_state *crtc_state) |
| 7710 | { |
| 7711 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7712 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7713 | |
| 7714 | memset(&crtc_state->dpll_hw_state, 0, |
| 7715 | sizeof(crtc_state->dpll_hw_state)); |
| 7716 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7717 | if (!crtc_state->clock_set && |
| 7718 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7719 | refclk, NULL, &crtc_state->dpll)) { |
| 7720 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7721 | return -EINVAL; |
| 7722 | } |
| 7723 | |
| 7724 | chv_compute_dpll(crtc, crtc_state); |
| 7725 | |
| 7726 | return 0; |
| 7727 | } |
| 7728 | |
| 7729 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7730 | struct intel_crtc_state *crtc_state) |
| 7731 | { |
| 7732 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7733 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7734 | |
| 7735 | memset(&crtc_state->dpll_hw_state, 0, |
| 7736 | sizeof(crtc_state->dpll_hw_state)); |
| 7737 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7738 | if (!crtc_state->clock_set && |
| 7739 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7740 | refclk, NULL, &crtc_state->dpll)) { |
| 7741 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7742 | return -EINVAL; |
| 7743 | } |
| 7744 | |
| 7745 | vlv_compute_dpll(crtc, crtc_state); |
| 7746 | |
| 7747 | return 0; |
| 7748 | } |
| 7749 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7750 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7751 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7752 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7753 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7754 | uint32_t tmp; |
| 7755 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7756 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7757 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7758 | return; |
| 7759 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7760 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7761 | if (!(tmp & PFIT_ENABLE)) |
| 7762 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7763 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7764 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7765 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7766 | if (crtc->pipe != PIPE_B) |
| 7767 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7768 | } else { |
| 7769 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7770 | return; |
| 7771 | } |
| 7772 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7773 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7774 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7775 | } |
| 7776 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7777 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7778 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7779 | { |
| 7780 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7781 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7782 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7783 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7784 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7785 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7786 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7787 | /* In case of DSI, DPLL will not be used */ |
| 7788 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7789 | return; |
| 7790 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7791 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7792 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7793 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7794 | |
| 7795 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7796 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7797 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7798 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7799 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7800 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7801 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7802 | } |
| 7803 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7804 | static void |
| 7805 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7806 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7807 | { |
| 7808 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7809 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7810 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7811 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7812 | enum pipe pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7813 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7814 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7815 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7816 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7817 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7818 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7819 | if (!plane->get_hw_state(plane, &pipe)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7820 | return; |
| 7821 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7822 | WARN_ON(pipe != crtc->pipe); |
| 7823 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7824 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7825 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7826 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7827 | return; |
| 7828 | } |
| 7829 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7830 | fb = &intel_fb->base; |
| 7831 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7832 | fb->dev = dev; |
| 7833 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7834 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7835 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7836 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7837 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7838 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7839 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7840 | } |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7841 | |
| 7842 | if (val & DISPPLANE_ROTATE_180) |
| 7843 | plane_config->rotation = DRM_MODE_ROTATE_180; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7844 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7845 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7846 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B && |
| 7847 | val & DISPPLANE_MIRROR) |
| 7848 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 7849 | |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7850 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7851 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 7852 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7853 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 7854 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 7855 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 7856 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 7857 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7858 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7859 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7860 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7861 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 7862 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7863 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7864 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7865 | } |
| 7866 | plane_config->base = base; |
| 7867 | |
| 7868 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7869 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7870 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7871 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7872 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7873 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7874 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 7875 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7876 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7877 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7878 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7879 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7880 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 7881 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7882 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7883 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7884 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7885 | } |
| 7886 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7887 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7888 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7889 | { |
| 7890 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7891 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7892 | int pipe = pipe_config->cpu_transcoder; |
| 7893 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7894 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7895 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7896 | int refclk = 100000; |
| 7897 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7898 | /* In case of DSI, DPLL will not be used */ |
| 7899 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7900 | return; |
| 7901 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7902 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7903 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7904 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7905 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7906 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7907 | 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] | 7908 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7909 | |
| 7910 | 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] | 7911 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 7912 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 7913 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7914 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7915 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7916 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7917 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7918 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7919 | } |
| 7920 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7921 | static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc, |
| 7922 | struct intel_crtc_state *pipe_config) |
| 7923 | { |
| 7924 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7925 | enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB; |
| 7926 | |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 7927 | pipe_config->lspcon_downsampling = false; |
| 7928 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7929 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
| 7930 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 7931 | |
| 7932 | if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) { |
| 7933 | bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE; |
| 7934 | bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 7935 | |
| 7936 | if (ycbcr420_enabled) { |
| 7937 | /* We support 4:2:0 in full blend mode only */ |
| 7938 | if (!blend) |
| 7939 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 7940 | else if (!(IS_GEMINILAKE(dev_priv) || |
| 7941 | INTEL_GEN(dev_priv) >= 10)) |
| 7942 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 7943 | else |
| 7944 | output = INTEL_OUTPUT_FORMAT_YCBCR420; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 7945 | } else { |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 7946 | /* |
| 7947 | * Currently there is no interface defined to |
| 7948 | * check user preference between RGB/YCBCR444 |
| 7949 | * or YCBCR420. So the only possible case for |
| 7950 | * YCBCR444 usage is driving YCBCR420 output |
| 7951 | * with LSPCON, when pipe is configured for |
| 7952 | * YCBCR444 output and LSPCON takes care of |
| 7953 | * downsampling it. |
| 7954 | */ |
| 7955 | pipe_config->lspcon_downsampling = true; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 7956 | output = INTEL_OUTPUT_FORMAT_YCBCR444; |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7957 | } |
| 7958 | } |
| 7959 | } |
| 7960 | |
| 7961 | pipe_config->output_format = output; |
| 7962 | } |
| 7963 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7964 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7965 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7966 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7967 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7968 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7969 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7970 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7971 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7972 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 7973 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7974 | return false; |
| 7975 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 7976 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7977 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 7978 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7979 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7980 | ret = false; |
| 7981 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7982 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7983 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7984 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7985 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7986 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7987 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7988 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7989 | case PIPECONF_6BPC: |
| 7990 | pipe_config->pipe_bpp = 18; |
| 7991 | break; |
| 7992 | case PIPECONF_8BPC: |
| 7993 | pipe_config->pipe_bpp = 24; |
| 7994 | break; |
| 7995 | case PIPECONF_10BPC: |
| 7996 | pipe_config->pipe_bpp = 30; |
| 7997 | break; |
| 7998 | default: |
| 7999 | break; |
| 8000 | } |
| 8001 | } |
| 8002 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8003 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8004 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8005 | pipe_config->limited_color_range = true; |
| 8006 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8007 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8008 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8009 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8010 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8011 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8012 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8013 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8014 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8015 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8016 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8017 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8018 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8019 | else |
| 8020 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8021 | pipe_config->pixel_multiplier = |
| 8022 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8023 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8024 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8025 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 8026 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8027 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8028 | pipe_config->pixel_multiplier = |
| 8029 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8030 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8031 | } else { |
| 8032 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8033 | * port and will be fixed up in the encoder->get_config |
| 8034 | * function. */ |
| 8035 | pipe_config->pixel_multiplier = 1; |
| 8036 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8037 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8038 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8039 | /* |
| 8040 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8041 | * on 830. Filter it out here so that we don't |
| 8042 | * report errors due to that. |
| 8043 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8044 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8045 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8046 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8047 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8048 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8049 | } else { |
| 8050 | /* Mask out read-only status bits. */ |
| 8051 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8052 | DPLL_PORTC_READY_MASK | |
| 8053 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8054 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8055 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8056 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8057 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 8058 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8059 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8060 | else |
| 8061 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8062 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8063 | /* |
| 8064 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8065 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8066 | * default. |
| 8067 | */ |
| 8068 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8069 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8070 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8071 | ret = true; |
| 8072 | |
| 8073 | out: |
| 8074 | intel_display_power_put(dev_priv, power_domain); |
| 8075 | |
| 8076 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8077 | } |
| 8078 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8079 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8080 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8081 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8082 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8083 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8084 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8085 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8086 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8087 | bool has_ck505 = false; |
| 8088 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8089 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8090 | |
| 8091 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8092 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8093 | switch (encoder->type) { |
| 8094 | case INTEL_OUTPUT_LVDS: |
| 8095 | has_panel = true; |
| 8096 | has_lvds = true; |
| 8097 | break; |
| 8098 | case INTEL_OUTPUT_EDP: |
| 8099 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 8100 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8101 | has_cpu_edp = true; |
| 8102 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8103 | default: |
| 8104 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8105 | } |
| 8106 | } |
| 8107 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8108 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8109 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8110 | can_ssc = has_ck505; |
| 8111 | } else { |
| 8112 | has_ck505 = false; |
| 8113 | can_ssc = true; |
| 8114 | } |
| 8115 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8116 | /* Check if any DPLLs are using the SSC source */ |
| 8117 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8118 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8119 | |
| 8120 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8121 | continue; |
| 8122 | |
| 8123 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8124 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8125 | using_ssc_source = true; |
| 8126 | break; |
| 8127 | } |
| 8128 | } |
| 8129 | |
| 8130 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8131 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8132 | |
| 8133 | /* Ironlake: try to setup display ref clock before DPLL |
| 8134 | * enabling. This is only under driver's control after |
| 8135 | * PCH B stepping, previous chipset stepping should be |
| 8136 | * ignoring this setting. |
| 8137 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8138 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8139 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8140 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8141 | * compute the final state we want first and check if we need to |
| 8142 | * make any changes at all. |
| 8143 | */ |
| 8144 | final = val; |
| 8145 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8146 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8147 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8148 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8149 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8150 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8151 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8152 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8153 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8154 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8155 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8156 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8157 | |
| 8158 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8159 | final |= DREF_SSC1_ENABLE; |
| 8160 | |
| 8161 | if (has_cpu_edp) { |
| 8162 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8163 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8164 | else |
| 8165 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8166 | } else |
| 8167 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8168 | } else if (using_ssc_source) { |
| 8169 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8170 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8171 | } |
| 8172 | |
| 8173 | if (final == val) |
| 8174 | return; |
| 8175 | |
| 8176 | /* Always enable nonspread source */ |
| 8177 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8178 | |
| 8179 | if (has_ck505) |
| 8180 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8181 | else |
| 8182 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8183 | |
| 8184 | if (has_panel) { |
| 8185 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8186 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8187 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8188 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8189 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8190 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8191 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8192 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8193 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8194 | |
| 8195 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8196 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8197 | POSTING_READ(PCH_DREF_CONTROL); |
| 8198 | udelay(200); |
| 8199 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8200 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8201 | |
| 8202 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8203 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8204 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8205 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8206 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8207 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8208 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8209 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8210 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8211 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8212 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8213 | POSTING_READ(PCH_DREF_CONTROL); |
| 8214 | udelay(200); |
| 8215 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8216 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8217 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8218 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8219 | |
| 8220 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8221 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8222 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8223 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8224 | POSTING_READ(PCH_DREF_CONTROL); |
| 8225 | udelay(200); |
| 8226 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8227 | if (!using_ssc_source) { |
| 8228 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8229 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8230 | /* Turn off the SSC source */ |
| 8231 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8232 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8233 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8234 | /* Turn off SSC1 */ |
| 8235 | val &= ~DREF_SSC1_ENABLE; |
| 8236 | |
| 8237 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8238 | POSTING_READ(PCH_DREF_CONTROL); |
| 8239 | udelay(200); |
| 8240 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8241 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8242 | |
| 8243 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8244 | } |
| 8245 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8246 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8247 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8248 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8249 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8250 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8251 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8252 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8253 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8254 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8255 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8256 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8257 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8258 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8259 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8260 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8261 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8262 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8263 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8264 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8265 | } |
| 8266 | |
| 8267 | /* WaMPhyProgramming:hsw */ |
| 8268 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8269 | { |
| 8270 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8271 | |
| 8272 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8273 | tmp &= ~(0xFF << 24); |
| 8274 | tmp |= (0x12 << 24); |
| 8275 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8276 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8277 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8278 | tmp |= (1 << 11); |
| 8279 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8280 | |
| 8281 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8282 | tmp |= (1 << 11); |
| 8283 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8284 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8285 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8286 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8287 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8288 | |
| 8289 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8290 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8291 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8292 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8293 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8294 | tmp &= ~(7 << 13); |
| 8295 | tmp |= (5 << 13); |
| 8296 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8297 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8298 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8299 | tmp &= ~(7 << 13); |
| 8300 | tmp |= (5 << 13); |
| 8301 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8302 | |
| 8303 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8304 | tmp &= ~0xFF; |
| 8305 | tmp |= 0x1C; |
| 8306 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8307 | |
| 8308 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8309 | tmp &= ~0xFF; |
| 8310 | tmp |= 0x1C; |
| 8311 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8312 | |
| 8313 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8314 | tmp &= ~(0xFF << 16); |
| 8315 | tmp |= (0x1C << 16); |
| 8316 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8317 | |
| 8318 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8319 | tmp &= ~(0xFF << 16); |
| 8320 | tmp |= (0x1C << 16); |
| 8321 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8322 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8323 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8324 | tmp |= (1 << 27); |
| 8325 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8326 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8327 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8328 | tmp |= (1 << 27); |
| 8329 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8330 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8331 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8332 | tmp &= ~(0xF << 28); |
| 8333 | tmp |= (4 << 28); |
| 8334 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8335 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8336 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8337 | tmp &= ~(0xF << 28); |
| 8338 | tmp |= (4 << 28); |
| 8339 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8340 | } |
| 8341 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8342 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8343 | * Programming" based on the parameters passed: |
| 8344 | * - Sequence to enable CLKOUT_DP |
| 8345 | * - Sequence to enable CLKOUT_DP without spread |
| 8346 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8347 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8348 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8349 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8350 | { |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8351 | uint32_t reg, tmp; |
| 8352 | |
| 8353 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8354 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8355 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8356 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8357 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8358 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8359 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8360 | |
| 8361 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8362 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8363 | tmp |= SBI_SSCCTL_PATHALT; |
| 8364 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8365 | |
| 8366 | udelay(24); |
| 8367 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8368 | if (with_spread) { |
| 8369 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8370 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8371 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8372 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8373 | if (with_fdi) { |
| 8374 | lpt_reset_fdi_mphy(dev_priv); |
| 8375 | lpt_program_fdi_mphy(dev_priv); |
| 8376 | } |
| 8377 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8378 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8379 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8380 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8381 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8382 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8383 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8384 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8385 | } |
| 8386 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8387 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8388 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8389 | { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8390 | uint32_t reg, tmp; |
| 8391 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8392 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8393 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8394 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8395 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8396 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8397 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8398 | |
| 8399 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8400 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8401 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8402 | tmp |= SBI_SSCCTL_PATHALT; |
| 8403 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8404 | udelay(32); |
| 8405 | } |
| 8406 | tmp |= SBI_SSCCTL_DISABLE; |
| 8407 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8408 | } |
| 8409 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8410 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8411 | } |
| 8412 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8413 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8414 | |
| 8415 | static const uint16_t sscdivintphase[] = { |
| 8416 | [BEND_IDX( 50)] = 0x3B23, |
| 8417 | [BEND_IDX( 45)] = 0x3B23, |
| 8418 | [BEND_IDX( 40)] = 0x3C23, |
| 8419 | [BEND_IDX( 35)] = 0x3C23, |
| 8420 | [BEND_IDX( 30)] = 0x3D23, |
| 8421 | [BEND_IDX( 25)] = 0x3D23, |
| 8422 | [BEND_IDX( 20)] = 0x3E23, |
| 8423 | [BEND_IDX( 15)] = 0x3E23, |
| 8424 | [BEND_IDX( 10)] = 0x3F23, |
| 8425 | [BEND_IDX( 5)] = 0x3F23, |
| 8426 | [BEND_IDX( 0)] = 0x0025, |
| 8427 | [BEND_IDX( -5)] = 0x0025, |
| 8428 | [BEND_IDX(-10)] = 0x0125, |
| 8429 | [BEND_IDX(-15)] = 0x0125, |
| 8430 | [BEND_IDX(-20)] = 0x0225, |
| 8431 | [BEND_IDX(-25)] = 0x0225, |
| 8432 | [BEND_IDX(-30)] = 0x0325, |
| 8433 | [BEND_IDX(-35)] = 0x0325, |
| 8434 | [BEND_IDX(-40)] = 0x0425, |
| 8435 | [BEND_IDX(-45)] = 0x0425, |
| 8436 | [BEND_IDX(-50)] = 0x0525, |
| 8437 | }; |
| 8438 | |
| 8439 | /* |
| 8440 | * Bend CLKOUT_DP |
| 8441 | * steps -50 to 50 inclusive, in steps of 5 |
| 8442 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8443 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8444 | */ |
| 8445 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8446 | { |
| 8447 | uint32_t tmp; |
| 8448 | int idx = BEND_IDX(steps); |
| 8449 | |
| 8450 | if (WARN_ON(steps % 5 != 0)) |
| 8451 | return; |
| 8452 | |
| 8453 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8454 | return; |
| 8455 | |
| 8456 | mutex_lock(&dev_priv->sb_lock); |
| 8457 | |
| 8458 | if (steps % 10 != 0) |
| 8459 | tmp = 0xAAAAAAAB; |
| 8460 | else |
| 8461 | tmp = 0x00000000; |
| 8462 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8463 | |
| 8464 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8465 | tmp &= 0xffff0000; |
| 8466 | tmp |= sscdivintphase[idx]; |
| 8467 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8468 | |
| 8469 | mutex_unlock(&dev_priv->sb_lock); |
| 8470 | } |
| 8471 | |
| 8472 | #undef BEND_IDX |
| 8473 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8474 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8475 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8476 | struct intel_encoder *encoder; |
| 8477 | bool has_vga = false; |
| 8478 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8479 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8480 | switch (encoder->type) { |
| 8481 | case INTEL_OUTPUT_ANALOG: |
| 8482 | has_vga = true; |
| 8483 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8484 | default: |
| 8485 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8486 | } |
| 8487 | } |
| 8488 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8489 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8490 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8491 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8492 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8493 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8494 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8495 | } |
| 8496 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8497 | /* |
| 8498 | * Initialize reference clocks when the driver loads |
| 8499 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8500 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8501 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8502 | 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] | 8503 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8504 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8505 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8506 | } |
| 8507 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8508 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8509 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8510 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8511 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8512 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8513 | uint32_t val; |
| 8514 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8515 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8516 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8517 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8518 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8519 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8520 | break; |
| 8521 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8522 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8523 | break; |
| 8524 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8525 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8526 | break; |
| 8527 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8528 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8529 | break; |
| 8530 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8531 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8532 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8533 | } |
| 8534 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8535 | if (crtc_state->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8536 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8537 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8538 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8539 | val |= PIPECONF_INTERLACED_ILK; |
| 8540 | else |
| 8541 | val |= PIPECONF_PROGRESSIVE; |
| 8542 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8543 | if (crtc_state->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8544 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8545 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8546 | I915_WRITE(PIPECONF(pipe), val); |
| 8547 | POSTING_READ(PIPECONF(pipe)); |
| 8548 | } |
| 8549 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8550 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8551 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8552 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8553 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8554 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8555 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8556 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8557 | if (IS_HASWELL(dev_priv) && crtc_state->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8558 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8559 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8560 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8561 | val |= PIPECONF_INTERLACED_ILK; |
| 8562 | else |
| 8563 | val |= PIPECONF_PROGRESSIVE; |
| 8564 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8565 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8566 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8567 | } |
| 8568 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8569 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state) |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8570 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8571 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8572 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8573 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8574 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8575 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8576 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8577 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8578 | case 18: |
| 8579 | val |= PIPEMISC_DITHER_6_BPC; |
| 8580 | break; |
| 8581 | case 24: |
| 8582 | val |= PIPEMISC_DITHER_8_BPC; |
| 8583 | break; |
| 8584 | case 30: |
| 8585 | val |= PIPEMISC_DITHER_10_BPC; |
| 8586 | break; |
| 8587 | case 36: |
| 8588 | val |= PIPEMISC_DITHER_12_BPC; |
| 8589 | break; |
| 8590 | default: |
| 8591 | /* Case prevented by pipe_config_set_bpp. */ |
| 8592 | BUG(); |
| 8593 | } |
| 8594 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8595 | if (crtc_state->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8596 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8597 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8598 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 8599 | crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8600 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8601 | |
| 8602 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8603 | val |= PIPEMISC_YUV420_ENABLE | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8604 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8605 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8606 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8607 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8608 | } |
| 8609 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8610 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8611 | { |
| 8612 | /* |
| 8613 | * Account for spread spectrum to avoid |
| 8614 | * oversubscribing the link. Max center spread |
| 8615 | * is 2.5%; use 5% for safety's sake. |
| 8616 | */ |
| 8617 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8618 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8619 | } |
| 8620 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8621 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8622 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8623 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8624 | } |
| 8625 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8626 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8627 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8628 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8629 | { |
| 8630 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8631 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8632 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8633 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8634 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8635 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8636 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8637 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8638 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8639 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8640 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8641 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8642 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8643 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8644 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8645 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8646 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8647 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8648 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8649 | fp |= FP_CB_TUNE; |
| 8650 | |
| 8651 | if (reduced_clock) { |
| 8652 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8653 | |
| 8654 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8655 | fp2 |= FP_CB_TUNE; |
| 8656 | } else { |
| 8657 | fp2 = fp; |
| 8658 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8659 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8660 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8661 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8662 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8663 | dpll |= DPLLB_MODE_LVDS; |
| 8664 | else |
| 8665 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8666 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8667 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8668 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8669 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8670 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8671 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8672 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8673 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8674 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8675 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8676 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8677 | /* |
| 8678 | * The high speed IO clock is only really required for |
| 8679 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8680 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8681 | * the clock needlessly does no real harm, except use up a |
| 8682 | * bit of power potentially. |
| 8683 | * |
| 8684 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8685 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8686 | * driving PCH ports at the same time. On SNB we could do this, |
| 8687 | * and potentially avoid enabling the second DPLL, but it's not |
| 8688 | * clear if it''s a win or loss power wise. No point in doing |
| 8689 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8690 | */ |
| 8691 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8692 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8693 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8694 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8695 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8696 | 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] | 8697 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8698 | 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] | 8699 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8700 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8701 | case 5: |
| 8702 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8703 | break; |
| 8704 | case 7: |
| 8705 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8706 | break; |
| 8707 | case 10: |
| 8708 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8709 | break; |
| 8710 | case 14: |
| 8711 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8712 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8713 | } |
| 8714 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8715 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8716 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8717 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8718 | else |
| 8719 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8720 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8721 | dpll |= DPLL_VCO_ENABLE; |
| 8722 | |
| 8723 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8724 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8725 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8726 | } |
| 8727 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8728 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8729 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8730 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8731 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8732 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8733 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8734 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8735 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8736 | memset(&crtc_state->dpll_hw_state, 0, |
| 8737 | sizeof(crtc_state->dpll_hw_state)); |
| 8738 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8739 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8740 | if (!crtc_state->has_pch_encoder) |
| 8741 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8742 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8743 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8744 | if (intel_panel_use_ssc(dev_priv)) { |
| 8745 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8746 | dev_priv->vbt.lvds_ssc_freq); |
| 8747 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8748 | } |
| 8749 | |
| 8750 | if (intel_is_dual_link_lvds(dev)) { |
| 8751 | if (refclk == 100000) |
| 8752 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8753 | else |
| 8754 | limit = &intel_limits_ironlake_dual_lvds; |
| 8755 | } else { |
| 8756 | if (refclk == 100000) |
| 8757 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8758 | else |
| 8759 | limit = &intel_limits_ironlake_single_lvds; |
| 8760 | } |
| 8761 | } else { |
| 8762 | limit = &intel_limits_ironlake_dac; |
| 8763 | } |
| 8764 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8765 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8766 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8767 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8768 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8769 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8770 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8771 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8772 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8773 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8774 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 8775 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 8776 | pipe_name(crtc->pipe)); |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8777 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8778 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8779 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8780 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8781 | } |
| 8782 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8783 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8784 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8785 | { |
| 8786 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8787 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8788 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8789 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8790 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8791 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8792 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8793 | & ~TU_SIZE_MASK; |
| 8794 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8795 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8796 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8797 | } |
| 8798 | |
| 8799 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8800 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8801 | struct intel_link_m_n *m_n, |
| 8802 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8803 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8804 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8805 | enum pipe pipe = crtc->pipe; |
| 8806 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8807 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8808 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8809 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8810 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8811 | & ~TU_SIZE_MASK; |
| 8812 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8813 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8814 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 8815 | |
| 8816 | if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8817 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8818 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8819 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8820 | & ~TU_SIZE_MASK; |
| 8821 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8822 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8823 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8824 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8825 | } else { |
| 8826 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8827 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8828 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8829 | & ~TU_SIZE_MASK; |
| 8830 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8831 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8832 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8833 | } |
| 8834 | } |
| 8835 | |
| 8836 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8837 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8838 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8839 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8840 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8841 | else |
| 8842 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8843 | &pipe_config->dp_m_n, |
| 8844 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8845 | } |
| 8846 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8847 | 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] | 8848 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8849 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8850 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8851 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8852 | } |
| 8853 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8854 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8855 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8856 | { |
| 8857 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8858 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8859 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8860 | uint32_t ps_ctrl = 0; |
| 8861 | int id = -1; |
| 8862 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8863 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8864 | /* find scaler attached to this pipe */ |
| 8865 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8866 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8867 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8868 | id = i; |
| 8869 | pipe_config->pch_pfit.enabled = true; |
| 8870 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8871 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8872 | break; |
| 8873 | } |
| 8874 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8875 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8876 | scaler_state->scaler_id = id; |
| 8877 | if (id >= 0) { |
| 8878 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8879 | } else { |
| 8880 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8881 | } |
| 8882 | } |
| 8883 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8884 | static void |
| 8885 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8886 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8887 | { |
| 8888 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8889 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8890 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 8891 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8892 | enum pipe pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8893 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8894 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8895 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8896 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8897 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8898 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8899 | if (!plane->get_hw_state(plane, &pipe)) |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 8900 | return; |
| 8901 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8902 | WARN_ON(pipe != crtc->pipe); |
| 8903 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8904 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8905 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8906 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8907 | return; |
| 8908 | } |
| 8909 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8910 | fb = &intel_fb->base; |
| 8911 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 8912 | fb->dev = dev; |
| 8913 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8914 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8915 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 8916 | if (INTEL_GEN(dev_priv) >= 11) |
| 8917 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 8918 | else |
| 8919 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8920 | |
| 8921 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8922 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8923 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 8924 | } else { |
| 8925 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 8926 | } |
| 8927 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8928 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8929 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 8930 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8931 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8932 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8933 | switch (tiling) { |
| 8934 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 8935 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8936 | break; |
| 8937 | case PLANE_CTL_TILED_X: |
| 8938 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8939 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8940 | break; |
| 8941 | case PLANE_CTL_TILED_Y: |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 8942 | plane_config->tiling = I915_TILING_Y; |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8943 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8944 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 8945 | else |
| 8946 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8947 | break; |
| 8948 | case PLANE_CTL_TILED_YF: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8949 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8950 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 8951 | else |
| 8952 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8953 | break; |
| 8954 | default: |
| 8955 | MISSING_CASE(tiling); |
| 8956 | goto error; |
| 8957 | } |
| 8958 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 8959 | /* |
| 8960 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 8961 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 8962 | */ |
| 8963 | switch (val & PLANE_CTL_ROTATE_MASK) { |
| 8964 | case PLANE_CTL_ROTATE_0: |
| 8965 | plane_config->rotation = DRM_MODE_ROTATE_0; |
| 8966 | break; |
| 8967 | case PLANE_CTL_ROTATE_90: |
| 8968 | plane_config->rotation = DRM_MODE_ROTATE_270; |
| 8969 | break; |
| 8970 | case PLANE_CTL_ROTATE_180: |
| 8971 | plane_config->rotation = DRM_MODE_ROTATE_180; |
| 8972 | break; |
| 8973 | case PLANE_CTL_ROTATE_270: |
| 8974 | plane_config->rotation = DRM_MODE_ROTATE_90; |
| 8975 | break; |
| 8976 | } |
| 8977 | |
| 8978 | if (INTEL_GEN(dev_priv) >= 10 && |
| 8979 | val & PLANE_CTL_FLIP_HORIZONTAL) |
| 8980 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 8981 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8982 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8983 | plane_config->base = base; |
| 8984 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8985 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8986 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8987 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8988 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8989 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8990 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8991 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 8992 | stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8993 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8994 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8995 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8996 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8997 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8998 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8999 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9000 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 9001 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9002 | plane_config->size); |
| 9003 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9004 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9005 | return; |
| 9006 | |
| 9007 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 9008 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9009 | } |
| 9010 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9011 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9012 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9013 | { |
| 9014 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9015 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9016 | uint32_t tmp; |
| 9017 | |
| 9018 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9019 | |
| 9020 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9021 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9022 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9023 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9024 | |
| 9025 | /* We currently do not free assignements of panel fitters on |
| 9026 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9027 | * differentiates them) so just WARN about this case for now. */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9028 | if (IS_GEN(dev_priv, 7)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9029 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9030 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9031 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9032 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9033 | } |
| 9034 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9035 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9036 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [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); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9040 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9041 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9042 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9043 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9044 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9045 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9046 | return false; |
| 9047 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 9048 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9049 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9050 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9051 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9052 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9053 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9054 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9055 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9056 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9057 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9058 | case PIPECONF_6BPC: |
| 9059 | pipe_config->pipe_bpp = 18; |
| 9060 | break; |
| 9061 | case PIPECONF_8BPC: |
| 9062 | pipe_config->pipe_bpp = 24; |
| 9063 | break; |
| 9064 | case PIPECONF_10BPC: |
| 9065 | pipe_config->pipe_bpp = 30; |
| 9066 | break; |
| 9067 | case PIPECONF_12BPC: |
| 9068 | pipe_config->pipe_bpp = 36; |
| 9069 | break; |
| 9070 | default: |
| 9071 | break; |
| 9072 | } |
| 9073 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9074 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9075 | pipe_config->limited_color_range = true; |
| 9076 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9077 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9078 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9079 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9080 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9081 | pipe_config->has_pch_encoder = true; |
| 9082 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9083 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9084 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9085 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9086 | |
| 9087 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9088 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9089 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9090 | /* |
| 9091 | * The pipe->pch transcoder and pch transcoder->pll |
| 9092 | * mapping is fixed. |
| 9093 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9094 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9095 | } else { |
| 9096 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9097 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9098 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9099 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9100 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9101 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9102 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9103 | pipe_config->shared_dpll = |
| 9104 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9105 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9106 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9107 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9108 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9109 | |
| 9110 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9111 | pipe_config->pixel_multiplier = |
| 9112 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9113 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9114 | |
| 9115 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9116 | } else { |
| 9117 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9118 | } |
| 9119 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9120 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9121 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9122 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9123 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9124 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9125 | ret = true; |
| 9126 | |
| 9127 | out: |
| 9128 | intel_display_power_put(dev_priv, power_domain); |
| 9129 | |
| 9130 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9131 | } |
| 9132 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9133 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9134 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 9135 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9136 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9137 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9138 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9139 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9140 | pipe_name(crtc->pipe)); |
| 9141 | |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 9142 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2), |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 9143 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9144 | 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] | 9145 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9146 | 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] | 9147 | 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] | 9148 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9149 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9150 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9151 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9152 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9153 | 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] | 9154 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9155 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9156 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9157 | 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] | 9158 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9159 | /* |
| 9160 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9161 | * interrupts remain enabled. We used to check for that, but since it's |
| 9162 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9163 | * the interrupts, the check below should be enough. |
| 9164 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9165 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9166 | } |
| 9167 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9168 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9169 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9170 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9171 | return I915_READ(D_COMP_HSW); |
| 9172 | else |
| 9173 | return I915_READ(D_COMP_BDW); |
| 9174 | } |
| 9175 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9176 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9177 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9178 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9179 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9180 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9181 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 9182 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9183 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9184 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9185 | I915_WRITE(D_COMP_BDW, val); |
| 9186 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9187 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9188 | } |
| 9189 | |
| 9190 | /* |
| 9191 | * This function implements pieces of two sequences from BSpec: |
| 9192 | * - Sequence for display software to disable LCPLL |
| 9193 | * - Sequence for display software to allow package C8+ |
| 9194 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9195 | * register. Callers should take care of disabling all the display engine |
| 9196 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9197 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9198 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9199 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9200 | { |
| 9201 | uint32_t val; |
| 9202 | |
| 9203 | assert_can_disable_lcpll(dev_priv); |
| 9204 | |
| 9205 | val = I915_READ(LCPLL_CTL); |
| 9206 | |
| 9207 | if (switch_to_fclk) { |
| 9208 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9209 | I915_WRITE(LCPLL_CTL, val); |
| 9210 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9211 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9212 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9213 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9214 | |
| 9215 | val = I915_READ(LCPLL_CTL); |
| 9216 | } |
| 9217 | |
| 9218 | val |= LCPLL_PLL_DISABLE; |
| 9219 | I915_WRITE(LCPLL_CTL, val); |
| 9220 | POSTING_READ(LCPLL_CTL); |
| 9221 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 9222 | 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] | 9223 | DRM_ERROR("LCPLL still locked\n"); |
| 9224 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9225 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9226 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9227 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9228 | ndelay(100); |
| 9229 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9230 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9231 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9232 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9233 | |
| 9234 | if (allow_power_down) { |
| 9235 | val = I915_READ(LCPLL_CTL); |
| 9236 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9237 | I915_WRITE(LCPLL_CTL, val); |
| 9238 | POSTING_READ(LCPLL_CTL); |
| 9239 | } |
| 9240 | } |
| 9241 | |
| 9242 | /* |
| 9243 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9244 | * source. |
| 9245 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9246 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9247 | { |
| 9248 | uint32_t val; |
| 9249 | |
| 9250 | val = I915_READ(LCPLL_CTL); |
| 9251 | |
| 9252 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9253 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9254 | return; |
| 9255 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9256 | /* |
| 9257 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9258 | * 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] | 9259 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9260 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9261 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9262 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9263 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9264 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9265 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9266 | } |
| 9267 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9268 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9269 | val |= D_COMP_COMP_FORCE; |
| 9270 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9271 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9272 | |
| 9273 | val = I915_READ(LCPLL_CTL); |
| 9274 | val &= ~LCPLL_PLL_DISABLE; |
| 9275 | I915_WRITE(LCPLL_CTL, val); |
| 9276 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9277 | if (intel_wait_for_register(dev_priv, |
| 9278 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9279 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9280 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9281 | |
| 9282 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9283 | val = I915_READ(LCPLL_CTL); |
| 9284 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9285 | I915_WRITE(LCPLL_CTL, val); |
| 9286 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9287 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9288 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9289 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9290 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9291 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9292 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9293 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9294 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9295 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9296 | } |
| 9297 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9298 | /* |
| 9299 | * Package states C8 and deeper are really deep PC states that can only be |
| 9300 | * reached when all the devices on the system allow it, so even if the graphics |
| 9301 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9302 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9303 | * |
| 9304 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9305 | * well is disabled and most interrupts are disabled, and these are also |
| 9306 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9307 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9308 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9309 | * hang the machine. |
| 9310 | * |
| 9311 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9312 | * the state of some registers, so when we come back from PC8+ we need to |
| 9313 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9314 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9315 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9316 | * because of the runtime PM support). |
| 9317 | * |
| 9318 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9319 | * documentation. |
| 9320 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9321 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9322 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9323 | uint32_t val; |
| 9324 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9325 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9326 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9327 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9328 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9329 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9330 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9331 | } |
| 9332 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9333 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9334 | hsw_disable_lcpll(dev_priv, true, true); |
| 9335 | } |
| 9336 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9337 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9338 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9339 | uint32_t val; |
| 9340 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9341 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9342 | |
| 9343 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9344 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9345 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9346 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9347 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9348 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9349 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9350 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9351 | } |
| 9352 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9353 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9354 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9355 | { |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9356 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9357 | struct intel_atomic_state *state = |
| 9358 | to_intel_atomic_state(crtc_state->base.state); |
| 9359 | |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9360 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) || |
| 9361 | IS_ICELAKE(dev_priv)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9362 | struct intel_encoder *encoder = |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9363 | intel_get_crtc_new_encoder(state, crtc_state); |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9364 | |
| 9365 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 9366 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 9367 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9368 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9369 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9370 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9371 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9372 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9373 | } |
| 9374 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9375 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9376 | enum port port, |
| 9377 | struct intel_crtc_state *pipe_config) |
| 9378 | { |
| 9379 | enum intel_dpll_id id; |
| 9380 | u32 temp; |
| 9381 | |
| 9382 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9383 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9384 | |
| 9385 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9386 | return; |
| 9387 | |
| 9388 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9389 | } |
| 9390 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9391 | static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9392 | enum port port, |
| 9393 | struct intel_crtc_state *pipe_config) |
| 9394 | { |
| 9395 | enum intel_dpll_id id; |
| 9396 | u32 temp; |
| 9397 | |
| 9398 | /* TODO: TBT pll not implemented. */ |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9399 | if (intel_port_is_combophy(dev_priv, port)) { |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9400 | temp = I915_READ(DPCLKA_CFGCR0_ICL) & |
| 9401 | DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
| 9402 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
| 9403 | |
Vandita Kulkarni | a54270d | 2018-10-03 12:52:00 +0530 | [diff] [blame] | 9404 | if (WARN_ON(!intel_dpll_is_combophy(id))) |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9405 | return; |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9406 | } else if (intel_port_is_tc(dev_priv, port)) { |
Vandita Kulkarni | cb6caf7 | 2018-10-03 12:51:58 +0530 | [diff] [blame] | 9407 | id = icl_port_to_mg_pll_id(port); |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9408 | } else { |
| 9409 | WARN(1, "Invalid port %x\n", port); |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9410 | return; |
| 9411 | } |
| 9412 | |
| 9413 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9414 | } |
| 9415 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9416 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9417 | enum port port, |
| 9418 | struct intel_crtc_state *pipe_config) |
| 9419 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9420 | enum intel_dpll_id id; |
| 9421 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9422 | switch (port) { |
| 9423 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9424 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9425 | break; |
| 9426 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9427 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9428 | break; |
| 9429 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9430 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9431 | break; |
| 9432 | default: |
| 9433 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9434 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9435 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9436 | |
| 9437 | 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] | 9438 | } |
| 9439 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9440 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9441 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9442 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9443 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9444 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9445 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9446 | |
| 9447 | 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] | 9448 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9449 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9450 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9451 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9452 | |
| 9453 | 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] | 9454 | } |
| 9455 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9456 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9457 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9458 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9459 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9460 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9461 | uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9462 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9463 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9464 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9465 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9466 | break; |
| 9467 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9468 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9469 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9470 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9471 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9472 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9473 | case PORT_CLK_SEL_LCPLL_810: |
| 9474 | id = DPLL_ID_LCPLL_810; |
| 9475 | break; |
| 9476 | case PORT_CLK_SEL_LCPLL_1350: |
| 9477 | id = DPLL_ID_LCPLL_1350; |
| 9478 | break; |
| 9479 | case PORT_CLK_SEL_LCPLL_2700: |
| 9480 | id = DPLL_ID_LCPLL_2700; |
| 9481 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9482 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9483 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9484 | /* fall through */ |
| 9485 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9486 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9487 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9488 | |
| 9489 | 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] | 9490 | } |
| 9491 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9492 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9493 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9494 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9495 | { |
| 9496 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9497 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9498 | enum intel_display_power_domain power_domain; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9499 | unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP); |
| 9500 | unsigned long enabled_panel_transcoders = 0; |
| 9501 | enum transcoder panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9502 | u32 tmp; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9503 | |
| 9504 | if (IS_ICELAKE(dev_priv)) |
| 9505 | panel_transcoder_mask |= |
| 9506 | BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9507 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9508 | /* |
| 9509 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9510 | * and DSI transcoders handled below. |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9511 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9512 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9513 | |
| 9514 | /* |
| 9515 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9516 | * consistency and less surprising code; it's in always on power). |
| 9517 | */ |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9518 | for_each_set_bit(panel_transcoder, &panel_transcoder_mask, 32) { |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9519 | enum pipe trans_pipe; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9520 | |
| 9521 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder)); |
| 9522 | if (!(tmp & TRANS_DDI_FUNC_ENABLE)) |
| 9523 | continue; |
| 9524 | |
| 9525 | /* |
| 9526 | * Log all enabled ones, only use the first one. |
| 9527 | * |
| 9528 | * FIXME: This won't work for two separate DSI displays. |
| 9529 | */ |
| 9530 | enabled_panel_transcoders |= BIT(panel_transcoder); |
| 9531 | if (enabled_panel_transcoders != BIT(panel_transcoder)) |
| 9532 | continue; |
| 9533 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9534 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9535 | default: |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9536 | WARN(1, "unknown pipe linked to transcoder %s\n", |
| 9537 | transcoder_name(panel_transcoder)); |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 9538 | /* fall through */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9539 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9540 | case TRANS_DDI_EDP_INPUT_A_ON: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9541 | trans_pipe = PIPE_A; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9542 | break; |
| 9543 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9544 | trans_pipe = PIPE_B; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9545 | break; |
| 9546 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9547 | trans_pipe = PIPE_C; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9548 | break; |
| 9549 | } |
| 9550 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9551 | if (trans_pipe == crtc->pipe) |
| 9552 | pipe_config->cpu_transcoder = panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9553 | } |
| 9554 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9555 | /* |
| 9556 | * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1 |
| 9557 | */ |
| 9558 | WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) && |
| 9559 | enabled_panel_transcoders != BIT(TRANSCODER_EDP)); |
| 9560 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9561 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9562 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9563 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9564 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9565 | |
| 9566 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9567 | |
| 9568 | return tmp & PIPECONF_ENABLE; |
| 9569 | } |
| 9570 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9571 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9572 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9573 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9574 | { |
| 9575 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9576 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9577 | enum intel_display_power_domain power_domain; |
| 9578 | enum port port; |
| 9579 | enum transcoder cpu_transcoder; |
| 9580 | u32 tmp; |
| 9581 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9582 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9583 | if (port == PORT_A) |
| 9584 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9585 | else |
| 9586 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9587 | |
| 9588 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9589 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9590 | continue; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9591 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9592 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9593 | /* |
| 9594 | * The PLL needs to be enabled with a valid divider |
| 9595 | * configuration, otherwise accessing DSI registers will hang |
| 9596 | * the machine. See BSpec North Display Engine |
| 9597 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9598 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9599 | */ |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 9600 | if (!bxt_dsi_pll_is_enabled(dev_priv)) |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9601 | break; |
| 9602 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9603 | /* XXX: this works for video mode only */ |
| 9604 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9605 | if (!(tmp & DPI_ENABLE)) |
| 9606 | continue; |
| 9607 | |
| 9608 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9609 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9610 | continue; |
| 9611 | |
| 9612 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9613 | break; |
| 9614 | } |
| 9615 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9616 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9617 | } |
| 9618 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9619 | 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] | 9620 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9621 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9622 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9623 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9624 | enum port port; |
| 9625 | uint32_t tmp; |
| 9626 | |
| 9627 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9628 | |
| 9629 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9630 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9631 | if (IS_ICELAKE(dev_priv)) |
| 9632 | icelake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9633 | else if (IS_CANNONLAKE(dev_priv)) |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9634 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9635 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9636 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9637 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9638 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9639 | else |
| 9640 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9641 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9642 | pll = pipe_config->shared_dpll; |
| 9643 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9644 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9645 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9646 | } |
| 9647 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9648 | /* |
| 9649 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9650 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9651 | * the PCH transcoder is on. |
| 9652 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9653 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9654 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9655 | pipe_config->has_pch_encoder = true; |
| 9656 | |
| 9657 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9658 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9659 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9660 | |
| 9661 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9662 | } |
| 9663 | } |
| 9664 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9665 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9666 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9667 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9668 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9669 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9670 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9671 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9672 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9673 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9674 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9675 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9676 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9677 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9678 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9679 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9680 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9681 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9682 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9683 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9684 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9685 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9686 | WARN_ON(active); |
| 9687 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9688 | } |
| 9689 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9690 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9691 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9692 | |
Madhav Chauhan | 2eae5d6 | 2018-11-29 16:12:28 +0200 | [diff] [blame] | 9693 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || |
| 9694 | IS_ICELAKE(dev_priv)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9695 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9696 | intel_get_pipe_timings(crtc, pipe_config); |
| 9697 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9698 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9699 | intel_get_pipe_src_size(crtc, pipe_config); |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 9700 | intel_get_crtc_ycbcr_config(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9701 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9702 | pipe_config->gamma_mode = |
| 9703 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9704 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9705 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9706 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9707 | power_domain_mask |= BIT_ULL(power_domain); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9708 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9709 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9710 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9711 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9712 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9713 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9714 | if (hsw_crtc_supports_ips(crtc)) { |
| 9715 | if (IS_HASWELL(dev_priv)) |
| 9716 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9717 | else { |
| 9718 | /* |
| 9719 | * We cannot readout IPS state on broadwell, set to |
| 9720 | * true so we can set it to a defined state on first |
| 9721 | * commit. |
| 9722 | */ |
| 9723 | pipe_config->ips_enabled = true; |
| 9724 | } |
| 9725 | } |
| 9726 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9727 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9728 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9729 | pipe_config->pixel_multiplier = |
| 9730 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9731 | } else { |
| 9732 | pipe_config->pixel_multiplier = 1; |
| 9733 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9734 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9735 | out: |
| 9736 | for_each_power_domain(power_domain, power_domain_mask) |
| 9737 | intel_display_power_put(dev_priv, power_domain); |
| 9738 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9739 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9740 | } |
| 9741 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9742 | 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] | 9743 | { |
| 9744 | struct drm_i915_private *dev_priv = |
| 9745 | to_i915(plane_state->base.plane->dev); |
| 9746 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9747 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9748 | u32 base; |
| 9749 | |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 9750 | if (INTEL_INFO(dev_priv)->display.cursor_needs_physical) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9751 | base = obj->phys_handle->busaddr; |
| 9752 | else |
| 9753 | base = intel_plane_ggtt_offset(plane_state); |
| 9754 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 9755 | base += plane_state->color_plane[0].offset; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9756 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9757 | /* ILK+ do this automagically */ |
| 9758 | if (HAS_GMCH_DISPLAY(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9759 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9760 | base += (plane_state->base.crtc_h * |
| 9761 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9762 | |
| 9763 | return base; |
| 9764 | } |
| 9765 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9766 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9767 | { |
| 9768 | int x = plane_state->base.crtc_x; |
| 9769 | int y = plane_state->base.crtc_y; |
| 9770 | u32 pos = 0; |
| 9771 | |
| 9772 | if (x < 0) { |
| 9773 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9774 | x = -x; |
| 9775 | } |
| 9776 | pos |= x << CURSOR_X_SHIFT; |
| 9777 | |
| 9778 | if (y < 0) { |
| 9779 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9780 | y = -y; |
| 9781 | } |
| 9782 | pos |= y << CURSOR_Y_SHIFT; |
| 9783 | |
| 9784 | return pos; |
| 9785 | } |
| 9786 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9787 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9788 | { |
| 9789 | const struct drm_mode_config *config = |
| 9790 | &plane_state->base.plane->dev->mode_config; |
| 9791 | int width = plane_state->base.crtc_w; |
| 9792 | int height = plane_state->base.crtc_h; |
| 9793 | |
| 9794 | return width > 0 && width <= config->cursor_width && |
| 9795 | height > 0 && height <= config->cursor_height; |
| 9796 | } |
| 9797 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9798 | 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] | 9799 | { |
| 9800 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9801 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9802 | int src_x, src_y; |
| 9803 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9804 | int ret; |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9805 | |
| 9806 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
| 9807 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 9808 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9809 | ret = intel_plane_check_stride(plane_state); |
| 9810 | if (ret) |
| 9811 | return ret; |
| 9812 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9813 | src_x = plane_state->base.src_x >> 16; |
| 9814 | src_y = plane_state->base.src_y >> 16; |
| 9815 | |
| 9816 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 9817 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 9818 | plane_state, 0); |
| 9819 | |
| 9820 | if (src_x != 0 || src_y != 0) { |
| 9821 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 9822 | return -EINVAL; |
| 9823 | } |
| 9824 | |
| 9825 | plane_state->color_plane[0].offset = offset; |
| 9826 | |
| 9827 | return 0; |
| 9828 | } |
| 9829 | |
| 9830 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 9831 | struct intel_plane_state *plane_state) |
| 9832 | { |
| 9833 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9834 | int ret; |
| 9835 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9836 | if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 9837 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 9838 | return -EINVAL; |
| 9839 | } |
| 9840 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9841 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 9842 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9843 | DRM_PLANE_HELPER_NO_SCALING, |
| 9844 | DRM_PLANE_HELPER_NO_SCALING, |
| 9845 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9846 | if (ret) |
| 9847 | return ret; |
| 9848 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9849 | if (!plane_state->base.visible) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9850 | return 0; |
| 9851 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9852 | ret = intel_plane_check_src_coordinates(plane_state); |
| 9853 | if (ret) |
| 9854 | return ret; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9855 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9856 | ret = intel_cursor_check_surface(plane_state); |
| 9857 | if (ret) |
| 9858 | return ret; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9859 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9860 | return 0; |
| 9861 | } |
| 9862 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 9863 | static unsigned int |
| 9864 | i845_cursor_max_stride(struct intel_plane *plane, |
| 9865 | u32 pixel_format, u64 modifier, |
| 9866 | unsigned int rotation) |
| 9867 | { |
| 9868 | return 2048; |
| 9869 | } |
| 9870 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9871 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9872 | const struct intel_plane_state *plane_state) |
| 9873 | { |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9874 | return CURSOR_ENABLE | |
| 9875 | CURSOR_GAMMA_ENABLE | |
| 9876 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9877 | CURSOR_STRIDE(plane_state->color_plane[0].stride); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9878 | } |
| 9879 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9880 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9881 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9882 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9883 | |
| 9884 | /* |
| 9885 | * 845g/865g are only limited by the width of their cursors, |
| 9886 | * the height is arbitrary up to the precision of the register. |
| 9887 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9888 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9889 | } |
| 9890 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9891 | static int i845_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9892 | struct intel_plane_state *plane_state) |
| 9893 | { |
| 9894 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9895 | int ret; |
| 9896 | |
| 9897 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9898 | if (ret) |
| 9899 | return ret; |
| 9900 | |
| 9901 | /* 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] | 9902 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9903 | return 0; |
| 9904 | |
| 9905 | /* Check for which cursor types we support */ |
| 9906 | if (!i845_cursor_size_ok(plane_state)) { |
| 9907 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9908 | plane_state->base.crtc_w, |
| 9909 | plane_state->base.crtc_h); |
| 9910 | return -EINVAL; |
| 9911 | } |
| 9912 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9913 | WARN_ON(plane_state->base.visible && |
| 9914 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 9915 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9916 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9917 | case 256: |
| 9918 | case 512: |
| 9919 | case 1024: |
| 9920 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9921 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9922 | default: |
| 9923 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 9924 | fb->pitches[0]); |
| 9925 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9926 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9927 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9928 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 9929 | |
| 9930 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9931 | } |
| 9932 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9933 | static void i845_update_cursor(struct intel_plane *plane, |
| 9934 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9935 | const struct intel_plane_state *plane_state) |
| 9936 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9937 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9938 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 9939 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9940 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 9941 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9942 | unsigned int width = plane_state->base.crtc_w; |
| 9943 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9944 | |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 9945 | cntl = plane_state->ctl; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9946 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9947 | |
| 9948 | base = intel_cursor_base(plane_state); |
| 9949 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9950 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9951 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9952 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 9953 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9954 | /* On these chipsets we can only modify the base/size/stride |
| 9955 | * whilst the cursor is disabled. |
| 9956 | */ |
| 9957 | if (plane->cursor.base != base || |
| 9958 | plane->cursor.size != size || |
| 9959 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9960 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9961 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9962 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9963 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9964 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9965 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9966 | plane->cursor.base = base; |
| 9967 | plane->cursor.size = size; |
| 9968 | plane->cursor.cntl = cntl; |
| 9969 | } else { |
| 9970 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9971 | } |
| 9972 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9973 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 9974 | } |
| 9975 | |
| 9976 | static void i845_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 9977 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9978 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 9979 | i845_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9980 | } |
| 9981 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9982 | static bool i845_cursor_get_hw_state(struct intel_plane *plane, |
| 9983 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9984 | { |
| 9985 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9986 | enum intel_display_power_domain power_domain; |
| 9987 | bool ret; |
| 9988 | |
| 9989 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
| 9990 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9991 | return false; |
| 9992 | |
| 9993 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 9994 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9995 | *pipe = PIPE_A; |
| 9996 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9997 | intel_display_power_put(dev_priv, power_domain); |
| 9998 | |
| 9999 | return ret; |
| 10000 | } |
| 10001 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 10002 | static unsigned int |
| 10003 | i9xx_cursor_max_stride(struct intel_plane *plane, |
| 10004 | u32 pixel_format, u64 modifier, |
| 10005 | unsigned int rotation) |
| 10006 | { |
| 10007 | return plane->base.dev->mode_config.cursor_width * 4; |
| 10008 | } |
| 10009 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10010 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 10011 | const struct intel_plane_state *plane_state) |
| 10012 | { |
| 10013 | struct drm_i915_private *dev_priv = |
| 10014 | to_i915(plane_state->base.plane->dev); |
| 10015 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10016 | u32 cntl = 0; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10017 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10018 | if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | e876b78 | 2018-01-30 22:38:05 +0200 | [diff] [blame] | 10019 | cntl |= MCURSOR_TRICKLE_FEED_DISABLE; |
| 10020 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10021 | if (INTEL_GEN(dev_priv) <= 10) { |
| 10022 | cntl |= MCURSOR_GAMMA_ENABLE; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10023 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10024 | if (HAS_DDI(dev_priv)) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10025 | cntl |= MCURSOR_PIPE_CSC_ENABLE; |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10026 | } |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10027 | |
Ville Syrjälä | 32ea06b | 2018-01-30 22:38:01 +0200 | [diff] [blame] | 10028 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 10029 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10030 | |
| 10031 | switch (plane_state->base.crtc_w) { |
| 10032 | case 64: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10033 | cntl |= MCURSOR_MODE_64_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10034 | break; |
| 10035 | case 128: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10036 | cntl |= MCURSOR_MODE_128_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10037 | break; |
| 10038 | case 256: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10039 | cntl |= MCURSOR_MODE_256_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10040 | break; |
| 10041 | default: |
| 10042 | MISSING_CASE(plane_state->base.crtc_w); |
| 10043 | return 0; |
| 10044 | } |
| 10045 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 10046 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10047 | cntl |= MCURSOR_ROTATE_180; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10048 | |
| 10049 | return cntl; |
| 10050 | } |
| 10051 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10052 | 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] | 10053 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10054 | struct drm_i915_private *dev_priv = |
| 10055 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10056 | int width = plane_state->base.crtc_w; |
| 10057 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10058 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 10059 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10060 | return false; |
| 10061 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10062 | /* Cursor width is limited to a few power-of-two sizes */ |
| 10063 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10064 | case 256: |
| 10065 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10066 | case 64: |
| 10067 | break; |
| 10068 | default: |
| 10069 | return false; |
| 10070 | } |
| 10071 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10072 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10073 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 10074 | * height from 8 lines up to the cursor width, when the |
| 10075 | * cursor is not rotated. Everything else requires square |
| 10076 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10077 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10078 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 10079 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10080 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10081 | return false; |
| 10082 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10083 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10084 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10085 | } |
| 10086 | |
| 10087 | return true; |
| 10088 | } |
| 10089 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10090 | static int i9xx_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10091 | struct intel_plane_state *plane_state) |
| 10092 | { |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10093 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10094 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10095 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10096 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10097 | int ret; |
| 10098 | |
| 10099 | ret = intel_check_cursor(crtc_state, plane_state); |
| 10100 | if (ret) |
| 10101 | return ret; |
| 10102 | |
| 10103 | /* 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] | 10104 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10105 | return 0; |
| 10106 | |
| 10107 | /* Check for which cursor types we support */ |
| 10108 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 10109 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 10110 | plane_state->base.crtc_w, |
| 10111 | plane_state->base.crtc_h); |
| 10112 | return -EINVAL; |
| 10113 | } |
| 10114 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10115 | WARN_ON(plane_state->base.visible && |
| 10116 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 10117 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10118 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 10119 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 10120 | fb->pitches[0], plane_state->base.crtc_w); |
| 10121 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10122 | } |
| 10123 | |
| 10124 | /* |
| 10125 | * There's something wrong with the cursor on CHV pipe C. |
| 10126 | * If it straddles the left edge of the screen then |
| 10127 | * moving it away from the edge or disabling it often |
| 10128 | * results in a pipe underrun, and often that can lead to |
| 10129 | * dead pipe (constant underrun reported, and it scans |
| 10130 | * out just a solid color). To recover from that, the |
| 10131 | * display power well must be turned off and on again. |
| 10132 | * Refuse the put the cursor into that compromised position. |
| 10133 | */ |
| 10134 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 10135 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 10136 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 10137 | return -EINVAL; |
| 10138 | } |
| 10139 | |
| 10140 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 10141 | |
| 10142 | return 0; |
| 10143 | } |
| 10144 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10145 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 10146 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10147 | const struct intel_plane_state *plane_state) |
| 10148 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10149 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10150 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10151 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10152 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10153 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10154 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 10155 | cntl = plane_state->ctl; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10156 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10157 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 10158 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 10159 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10160 | base = intel_cursor_base(plane_state); |
| 10161 | pos = intel_cursor_position(plane_state); |
| 10162 | } |
| 10163 | |
| 10164 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10165 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10166 | /* |
| 10167 | * On some platforms writing CURCNTR first will also |
| 10168 | * cause CURPOS to be armed by the CURBASE write. |
| 10169 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10170 | * arm itself. Thus we always update CURCNTR before |
| 10171 | * CURPOS. |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10172 | * |
| 10173 | * On other platforms CURPOS always requires the |
| 10174 | * CURBASE write to arm the update. Additonally |
| 10175 | * a write to any of the cursor register will cancel |
| 10176 | * an already armed cursor update. Thus leaving out |
| 10177 | * the CURBASE write after CURPOS could lead to a |
| 10178 | * cursor that doesn't appear to move, or even change |
| 10179 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10180 | * |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10181 | * The other registers are armed by by the CURBASE write |
| 10182 | * except when the plane is getting enabled at which time |
| 10183 | * the CURCNTR write arms the update. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10184 | */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 10185 | |
| 10186 | if (INTEL_GEN(dev_priv) >= 9) |
| 10187 | skl_write_cursor_wm(plane, crtc_state); |
| 10188 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10189 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10190 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10191 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10192 | if (HAS_CUR_FBC(dev_priv)) |
| 10193 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10194 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10195 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10196 | I915_WRITE_FW(CURBASE(pipe), base); |
| 10197 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10198 | plane->cursor.base = base; |
| 10199 | plane->cursor.size = fbc_ctl; |
| 10200 | plane->cursor.cntl = cntl; |
| 10201 | } else { |
| 10202 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10203 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10204 | } |
| 10205 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10206 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10207 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10208 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10209 | static void i9xx_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10210 | const struct intel_crtc_state *crtc_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10211 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10212 | i9xx_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10213 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 10214 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10215 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane, |
| 10216 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10217 | { |
| 10218 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10219 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10220 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10221 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10222 | |
| 10223 | /* |
| 10224 | * Not 100% correct for planes that can move between pipes, |
| 10225 | * but that's only the case for gen2-3 which don't have any |
| 10226 | * display power wells. |
| 10227 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10228 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10229 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10230 | return false; |
| 10231 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10232 | val = I915_READ(CURCNTR(plane->pipe)); |
| 10233 | |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10234 | ret = val & MCURSOR_MODE; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10235 | |
| 10236 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 10237 | *pipe = plane->pipe; |
| 10238 | else |
| 10239 | *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >> |
| 10240 | MCURSOR_PIPE_SELECT_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10241 | |
| 10242 | intel_display_power_put(dev_priv, power_domain); |
| 10243 | |
| 10244 | return ret; |
| 10245 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10246 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10247 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10248 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10249 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10250 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10251 | }; |
| 10252 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10253 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10254 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 10255 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10256 | { |
| 10257 | struct intel_framebuffer *intel_fb; |
| 10258 | int ret; |
| 10259 | |
| 10260 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10261 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10262 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10263 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10264 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10265 | if (ret) |
| 10266 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10267 | |
| 10268 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10269 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10270 | err: |
| 10271 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10272 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10273 | } |
| 10274 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10275 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 10276 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10277 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10278 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10279 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10280 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10281 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10282 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10283 | if (ret) |
| 10284 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10285 | |
| 10286 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 10287 | if (plane_state->crtc != crtc) |
| 10288 | continue; |
| 10289 | |
| 10290 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 10291 | if (ret) |
| 10292 | return ret; |
| 10293 | |
| 10294 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 10295 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10296 | |
| 10297 | return 0; |
| 10298 | } |
| 10299 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10300 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10301 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10302 | struct intel_load_detect_pipe *old, |
| 10303 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10304 | { |
| 10305 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10306 | struct intel_encoder *intel_encoder = |
| 10307 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10308 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10309 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10310 | struct drm_crtc *crtc = NULL; |
| 10311 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10312 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10313 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10314 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10315 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10316 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10317 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10318 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10319 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10320 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10321 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10322 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10323 | old->restore_state = NULL; |
| 10324 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10325 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10326 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10327 | /* |
| 10328 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10329 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10330 | * - if the connector already has an assigned crtc, use it (but make |
| 10331 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10332 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10333 | * - try to find the first unused crtc that can drive this connector, |
| 10334 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10335 | */ |
| 10336 | |
| 10337 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10338 | if (connector->state->crtc) { |
| 10339 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10340 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10341 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10342 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10343 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10344 | |
| 10345 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10346 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10347 | } |
| 10348 | |
| 10349 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10350 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10351 | i++; |
| 10352 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10353 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10354 | |
| 10355 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10356 | if (ret) |
| 10357 | goto fail; |
| 10358 | |
| 10359 | if (possible_crtc->state->enable) { |
| 10360 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10361 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10362 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10363 | |
| 10364 | crtc = possible_crtc; |
| 10365 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10366 | } |
| 10367 | |
| 10368 | /* |
| 10369 | * If we didn't find an unused CRTC, don't use any. |
| 10370 | */ |
| 10371 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10372 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10373 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10374 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10375 | } |
| 10376 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10377 | found: |
| 10378 | intel_crtc = to_intel_crtc(crtc); |
| 10379 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10380 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10381 | restore_state = drm_atomic_state_alloc(dev); |
| 10382 | if (!state || !restore_state) { |
| 10383 | ret = -ENOMEM; |
| 10384 | goto fail; |
| 10385 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10386 | |
| 10387 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10388 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10389 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10390 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10391 | if (IS_ERR(connector_state)) { |
| 10392 | ret = PTR_ERR(connector_state); |
| 10393 | goto fail; |
| 10394 | } |
| 10395 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10396 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10397 | if (ret) |
| 10398 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10399 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10400 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10401 | if (IS_ERR(crtc_state)) { |
| 10402 | ret = PTR_ERR(crtc_state); |
| 10403 | goto fail; |
| 10404 | } |
| 10405 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10406 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10407 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10408 | if (!mode) |
| 10409 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10410 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10411 | 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] | 10412 | if (ret) |
| 10413 | goto fail; |
| 10414 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10415 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10416 | if (ret) |
| 10417 | goto fail; |
| 10418 | |
| 10419 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10420 | if (!ret) |
| 10421 | 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] | 10422 | if (!ret) |
| 10423 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10424 | if (ret) { |
| 10425 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10426 | goto fail; |
| 10427 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10428 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10429 | ret = drm_atomic_commit(state); |
| 10430 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10431 | 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] | 10432 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10433 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10434 | |
| 10435 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10436 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10437 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10438 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10439 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10440 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10441 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10442 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10443 | if (state) { |
| 10444 | drm_atomic_state_put(state); |
| 10445 | state = NULL; |
| 10446 | } |
| 10447 | if (restore_state) { |
| 10448 | drm_atomic_state_put(restore_state); |
| 10449 | restore_state = NULL; |
| 10450 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10451 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10452 | if (ret == -EDEADLK) |
| 10453 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10454 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10455 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10456 | } |
| 10457 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10458 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10459 | struct intel_load_detect_pipe *old, |
| 10460 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10461 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10462 | struct intel_encoder *intel_encoder = |
| 10463 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10464 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10465 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10466 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10467 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10468 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10469 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10470 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10471 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10472 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10473 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10474 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10475 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10476 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10477 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10478 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10479 | } |
| 10480 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10481 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10482 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10483 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10484 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10485 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10486 | |
| 10487 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10488 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10489 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10490 | return 120000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10491 | else if (!IS_GEN(dev_priv, 2)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10492 | return 96000; |
| 10493 | else |
| 10494 | return 48000; |
| 10495 | } |
| 10496 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10497 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10498 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10499 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10500 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10501 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10502 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10503 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10504 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10505 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10506 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10507 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10508 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10509 | |
| 10510 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10511 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10512 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10513 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10514 | |
| 10515 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10516 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10517 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10518 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10519 | } else { |
| 10520 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10521 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10522 | } |
| 10523 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10524 | if (!IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10525 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10526 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10527 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10528 | else |
| 10529 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10530 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10531 | |
| 10532 | switch (dpll & DPLL_MODE_MASK) { |
| 10533 | case DPLLB_MODE_DAC_SERIAL: |
| 10534 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10535 | 5 : 10; |
| 10536 | break; |
| 10537 | case DPLLB_MODE_LVDS: |
| 10538 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10539 | 7 : 14; |
| 10540 | break; |
| 10541 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10542 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10543 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10544 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10545 | } |
| 10546 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10547 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10548 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10549 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10550 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10551 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10552 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10553 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10554 | |
| 10555 | if (is_lvds) { |
| 10556 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10557 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10558 | |
| 10559 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10560 | clock.p2 = 7; |
| 10561 | else |
| 10562 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10563 | } else { |
| 10564 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10565 | clock.p1 = 2; |
| 10566 | else { |
| 10567 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10568 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10569 | } |
| 10570 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10571 | clock.p2 = 4; |
| 10572 | else |
| 10573 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10574 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10575 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10576 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10577 | } |
| 10578 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10579 | /* |
| 10580 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10581 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10582 | * encoder's get_config() function. |
| 10583 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10584 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10585 | } |
| 10586 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10587 | int intel_dotclock_calculate(int link_freq, |
| 10588 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10589 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10590 | /* |
| 10591 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10592 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10593 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10594 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10595 | * |
| 10596 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10597 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10598 | */ |
| 10599 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10600 | if (!m_n->link_n) |
| 10601 | return 0; |
| 10602 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10603 | 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] | 10604 | } |
| 10605 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10606 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10607 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10608 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10609 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10610 | |
| 10611 | /* read out port_clock from the DPLL */ |
| 10612 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10613 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10614 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10615 | * In case there is an active pipe without active ports, |
| 10616 | * we may need some idea for the dotclock anyway. |
| 10617 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10618 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10619 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10620 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10621 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10622 | } |
| 10623 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10624 | /* Returns the currently programmed mode of the given encoder. */ |
| 10625 | struct drm_display_mode * |
| 10626 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10627 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10628 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10629 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10630 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10631 | struct intel_crtc *crtc; |
| 10632 | enum pipe pipe; |
| 10633 | |
| 10634 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10635 | return NULL; |
| 10636 | |
| 10637 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10638 | |
| 10639 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10640 | if (!mode) |
| 10641 | return NULL; |
| 10642 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10643 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10644 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10645 | kfree(mode); |
| 10646 | return NULL; |
| 10647 | } |
| 10648 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10649 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10650 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10651 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10652 | kfree(crtc_state); |
| 10653 | kfree(mode); |
| 10654 | return NULL; |
| 10655 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10656 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10657 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10658 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10659 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10660 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10661 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10662 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10663 | return mode; |
| 10664 | } |
| 10665 | |
| 10666 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10667 | { |
| 10668 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10669 | |
| 10670 | drm_crtc_cleanup(crtc); |
| 10671 | kfree(intel_crtc); |
| 10672 | } |
| 10673 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10674 | /** |
| 10675 | * intel_wm_need_update - Check whether watermarks need updating |
Chris Wilson | 6bf1981 | 2018-12-31 14:35:05 +0000 | [diff] [blame] | 10676 | * @cur: current plane state |
| 10677 | * @new: new plane state |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10678 | * |
| 10679 | * Check current plane state versus the new one to determine whether |
| 10680 | * watermarks need to be recalculated. |
| 10681 | * |
| 10682 | * Returns true or false. |
| 10683 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10684 | static bool intel_wm_need_update(struct intel_plane_state *cur, |
| 10685 | struct intel_plane_state *new) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10686 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10687 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10688 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10689 | return true; |
| 10690 | |
| 10691 | if (!cur->base.fb || !new->base.fb) |
| 10692 | return false; |
| 10693 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10694 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10695 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10696 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10697 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10698 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10699 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10700 | return true; |
| 10701 | |
| 10702 | return false; |
| 10703 | } |
| 10704 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10705 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10706 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10707 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10708 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10709 | int dst_w = drm_rect_width(&state->base.dst); |
| 10710 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10711 | |
| 10712 | return (src_w != dst_w || src_h != dst_h); |
| 10713 | } |
| 10714 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10715 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10716 | struct drm_crtc_state *crtc_state, |
| 10717 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10718 | struct drm_plane_state *plane_state) |
| 10719 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10720 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10721 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10722 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10723 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10724 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10725 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10726 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10727 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10728 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10729 | bool turn_off, turn_on, visible, was_visible; |
| 10730 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10731 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10732 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10733 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10734 | ret = skl_update_scaler_plane( |
| 10735 | to_intel_crtc_state(crtc_state), |
| 10736 | to_intel_plane_state(plane_state)); |
| 10737 | if (ret) |
| 10738 | return ret; |
| 10739 | } |
| 10740 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10741 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10742 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10743 | |
| 10744 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10745 | was_visible = false; |
| 10746 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10747 | /* |
| 10748 | * Visibility is calculated as if the crtc was on, but |
| 10749 | * after scaler setup everything depends on it being off |
| 10750 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10751 | * |
| 10752 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10753 | * be computed as if the pipe would be active. Perhaps move |
| 10754 | * per-plane wm computation to the .check_plane() hook, and |
| 10755 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10756 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10757 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10758 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10759 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10760 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10761 | |
| 10762 | if (!was_visible && !visible) |
| 10763 | return 0; |
| 10764 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10765 | if (fb != old_plane_state->base.fb) |
| 10766 | pipe_config->fb_changed = true; |
| 10767 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10768 | turn_off = was_visible && (!visible || mode_changed); |
| 10769 | turn_on = visible && (!was_visible || mode_changed); |
| 10770 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10771 | 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] | 10772 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 10773 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10774 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10775 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10776 | 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] | 10777 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10778 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10779 | turn_off, turn_on, mode_changed); |
| 10780 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10781 | if (turn_on) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10782 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10783 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10784 | |
| 10785 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10786 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10787 | pipe_config->disable_cxsr = true; |
| 10788 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10789 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10790 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10791 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10792 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10793 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10794 | pipe_config->disable_cxsr = true; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10795 | } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state), |
| 10796 | to_intel_plane_state(plane_state))) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10797 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10798 | /* FIXME bollocks */ |
| 10799 | pipe_config->update_wm_pre = true; |
| 10800 | pipe_config->update_wm_post = true; |
| 10801 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10802 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10803 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 10804 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10805 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10806 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10807 | /* |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10808 | * ILK/SNB DVSACNTR/Sprite Enable |
| 10809 | * IVB SPR_CTL/Sprite Enable |
| 10810 | * "When in Self Refresh Big FIFO mode, a write to enable the |
| 10811 | * plane will be internally buffered and delayed while Big FIFO |
| 10812 | * mode is exiting." |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10813 | * |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10814 | * Which means that enabling the sprite can take an extra frame |
| 10815 | * when we start in big FIFO mode (LP1+). Thus we need to drop |
| 10816 | * down to LP0 and wait for vblank in order to make sure the |
| 10817 | * sprite gets enabled on the next vblank after the register write. |
| 10818 | * Doing otherwise would risk enabling the sprite one frame after |
| 10819 | * we've already signalled flip completion. We can resume LP1+ |
| 10820 | * once the sprite has been enabled. |
| 10821 | * |
| 10822 | * |
| 10823 | * WaCxSRDisabledForSpriteScaling:ivb |
| 10824 | * IVB SPR_SCALE/Scaling Enable |
| 10825 | * "Low Power watermarks must be disabled for at least one |
| 10826 | * frame before enabling sprite scaling, and kept disabled |
| 10827 | * until sprite scaling is disabled." |
| 10828 | * |
| 10829 | * ILK/SNB DVSASCALE/Scaling Enable |
| 10830 | * "When in Self Refresh Big FIFO mode, scaling enable will be |
| 10831 | * masked off while Big FIFO mode is exiting." |
| 10832 | * |
| 10833 | * Despite the w/a only being listed for IVB we assume that |
| 10834 | * the ILK/SNB note has similar ramifications, hence we apply |
| 10835 | * the w/a on all three platforms. |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10836 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10837 | if (plane->id == PLANE_SPRITE0 && |
Lucas De Marchi | f3ce44a | 2018-12-12 10:10:44 -0800 | [diff] [blame] | 10838 | (IS_GEN_RANGE(dev_priv, 5, 6) || |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10839 | IS_IVYBRIDGE(dev_priv)) && |
| 10840 | (turn_on || (!needs_scaling(old_plane_state) && |
| 10841 | needs_scaling(to_intel_plane_state(plane_state))))) |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10842 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10843 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10844 | return 0; |
| 10845 | } |
| 10846 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10847 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10848 | const struct intel_encoder *b) |
| 10849 | { |
| 10850 | /* masks could be asymmetric, so check both ways */ |
| 10851 | return a == b || (a->cloneable & (1 << b->type) && |
| 10852 | b->cloneable & (1 << a->type)); |
| 10853 | } |
| 10854 | |
| 10855 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 10856 | struct intel_crtc *crtc, |
| 10857 | struct intel_encoder *encoder) |
| 10858 | { |
| 10859 | struct intel_encoder *source_encoder; |
| 10860 | struct drm_connector *connector; |
| 10861 | struct drm_connector_state *connector_state; |
| 10862 | int i; |
| 10863 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10864 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10865 | if (connector_state->crtc != &crtc->base) |
| 10866 | continue; |
| 10867 | |
| 10868 | source_encoder = |
| 10869 | to_intel_encoder(connector_state->best_encoder); |
| 10870 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10871 | return false; |
| 10872 | } |
| 10873 | |
| 10874 | return true; |
| 10875 | } |
| 10876 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10877 | static int icl_add_linked_planes(struct intel_atomic_state *state) |
| 10878 | { |
| 10879 | struct intel_plane *plane, *linked; |
| 10880 | struct intel_plane_state *plane_state, *linked_plane_state; |
| 10881 | int i; |
| 10882 | |
| 10883 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10884 | linked = plane_state->linked_plane; |
| 10885 | |
| 10886 | if (!linked) |
| 10887 | continue; |
| 10888 | |
| 10889 | linked_plane_state = intel_atomic_get_plane_state(state, linked); |
| 10890 | if (IS_ERR(linked_plane_state)) |
| 10891 | return PTR_ERR(linked_plane_state); |
| 10892 | |
| 10893 | WARN_ON(linked_plane_state->linked_plane != plane); |
| 10894 | WARN_ON(linked_plane_state->slave == plane_state->slave); |
| 10895 | } |
| 10896 | |
| 10897 | return 0; |
| 10898 | } |
| 10899 | |
| 10900 | static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state) |
| 10901 | { |
| 10902 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 10903 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 10904 | struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state); |
| 10905 | struct intel_plane *plane, *linked; |
| 10906 | struct intel_plane_state *plane_state; |
| 10907 | int i; |
| 10908 | |
| 10909 | if (INTEL_GEN(dev_priv) < 11) |
| 10910 | return 0; |
| 10911 | |
| 10912 | /* |
| 10913 | * Destroy all old plane links and make the slave plane invisible |
| 10914 | * in the crtc_state->active_planes mask. |
| 10915 | */ |
| 10916 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10917 | if (plane->pipe != crtc->pipe || !plane_state->linked_plane) |
| 10918 | continue; |
| 10919 | |
| 10920 | plane_state->linked_plane = NULL; |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 10921 | if (plane_state->slave && !plane_state->base.visible) { |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10922 | crtc_state->active_planes &= ~BIT(plane->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 10923 | crtc_state->update_planes |= BIT(plane->id); |
| 10924 | } |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10925 | |
| 10926 | plane_state->slave = false; |
| 10927 | } |
| 10928 | |
| 10929 | if (!crtc_state->nv12_planes) |
| 10930 | return 0; |
| 10931 | |
| 10932 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10933 | struct intel_plane_state *linked_state = NULL; |
| 10934 | |
| 10935 | if (plane->pipe != crtc->pipe || |
| 10936 | !(crtc_state->nv12_planes & BIT(plane->id))) |
| 10937 | continue; |
| 10938 | |
| 10939 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) { |
| 10940 | if (!icl_is_nv12_y_plane(linked->id)) |
| 10941 | continue; |
| 10942 | |
| 10943 | if (crtc_state->active_planes & BIT(linked->id)) |
| 10944 | continue; |
| 10945 | |
| 10946 | linked_state = intel_atomic_get_plane_state(state, linked); |
| 10947 | if (IS_ERR(linked_state)) |
| 10948 | return PTR_ERR(linked_state); |
| 10949 | |
| 10950 | break; |
| 10951 | } |
| 10952 | |
| 10953 | if (!linked_state) { |
| 10954 | DRM_DEBUG_KMS("Need %d free Y planes for NV12\n", |
| 10955 | hweight8(crtc_state->nv12_planes)); |
| 10956 | |
| 10957 | return -EINVAL; |
| 10958 | } |
| 10959 | |
| 10960 | plane_state->linked_plane = linked; |
| 10961 | |
| 10962 | linked_state->slave = true; |
| 10963 | linked_state->linked_plane = plane; |
| 10964 | crtc_state->active_planes |= BIT(linked->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 10965 | crtc_state->update_planes |= BIT(linked->id); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10966 | DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name); |
| 10967 | } |
| 10968 | |
| 10969 | return 0; |
| 10970 | } |
| 10971 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10972 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 10973 | struct drm_crtc_state *crtc_state) |
| 10974 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10975 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10976 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10977 | struct intel_crtc_state *pipe_config = |
| 10978 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 10979 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10980 | bool mode_changed = needs_modeset(crtc_state); |
| 10981 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10982 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10983 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 10984 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10985 | if (mode_changed && crtc_state->enable && |
| 10986 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10987 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10988 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 10989 | pipe_config); |
| 10990 | if (ret) |
| 10991 | return ret; |
| 10992 | } |
| 10993 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10994 | if (crtc_state->color_mgmt_changed) { |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 10995 | ret = intel_color_check(pipe_config); |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10996 | if (ret) |
| 10997 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 10998 | |
| 10999 | /* |
| 11000 | * Changing color management on Intel hardware is |
| 11001 | * handled as part of planes update. |
| 11002 | */ |
| 11003 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11004 | } |
| 11005 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11006 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11007 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 11008 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11009 | if (ret) { |
| 11010 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11011 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11012 | } |
| 11013 | } |
| 11014 | |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 11015 | if (dev_priv->display.compute_intermediate_wm) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11016 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 11017 | return 0; |
| 11018 | |
| 11019 | /* |
| 11020 | * Calculate 'intermediate' watermarks that satisfy both the |
| 11021 | * old state and the new state. We can program these |
| 11022 | * immediately. |
| 11023 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11024 | ret = dev_priv->display.compute_intermediate_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11025 | if (ret) { |
| 11026 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 11027 | return ret; |
| 11028 | } |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11029 | } |
| 11030 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11031 | if (INTEL_GEN(dev_priv) >= 9) { |
Hans de Goede | 2c5c415 | 2018-12-17 15:19:03 +0100 | [diff] [blame] | 11032 | if (mode_changed || pipe_config->update_pipe) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11033 | ret = skl_update_scaler_crtc(pipe_config); |
| 11034 | |
| 11035 | if (!ret) |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11036 | ret = icl_check_nv12_planes(pipe_config); |
| 11037 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 11038 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 11039 | pipe_config); |
| 11040 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 11041 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11042 | pipe_config); |
| 11043 | } |
| 11044 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 11045 | if (HAS_IPS(dev_priv)) |
| 11046 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 11047 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11048 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11049 | } |
| 11050 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11051 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11052 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11053 | }; |
| 11054 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11055 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11056 | { |
| 11057 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11058 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11059 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11060 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11061 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11062 | if (connector->base.state->crtc) |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11063 | drm_connector_put(&connector->base); |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11064 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11065 | if (connector->base.encoder) { |
| 11066 | connector->base.state->best_encoder = |
| 11067 | connector->base.encoder; |
| 11068 | connector->base.state->crtc = |
| 11069 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11070 | |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11071 | drm_connector_get(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11072 | } else { |
| 11073 | connector->base.state->best_encoder = NULL; |
| 11074 | connector->base.state->crtc = NULL; |
| 11075 | } |
| 11076 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11077 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11078 | } |
| 11079 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11080 | static int |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11081 | compute_sink_pipe_bpp(const struct drm_connector_state *conn_state, |
| 11082 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11083 | { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11084 | struct drm_connector *connector = conn_state->connector; |
| 11085 | const struct drm_display_info *info = &connector->display_info; |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11086 | int bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11087 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11088 | switch (conn_state->max_bpc) { |
| 11089 | case 6 ... 7: |
| 11090 | bpp = 6 * 3; |
| 11091 | break; |
| 11092 | case 8 ... 9: |
| 11093 | bpp = 8 * 3; |
| 11094 | break; |
| 11095 | case 10 ... 11: |
| 11096 | bpp = 10 * 3; |
| 11097 | break; |
| 11098 | case 12: |
| 11099 | bpp = 12 * 3; |
| 11100 | break; |
| 11101 | default: |
| 11102 | return -EINVAL; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11103 | } |
| 11104 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11105 | if (bpp < pipe_config->pipe_bpp) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11106 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of " |
| 11107 | "EDID bpp %d, requested bpp %d, max platform bpp %d\n", |
| 11108 | connector->base.id, connector->name, |
| 11109 | bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc, |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11110 | pipe_config->pipe_bpp); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11111 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11112 | pipe_config->pipe_bpp = bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11113 | } |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11114 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11115 | return 0; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11116 | } |
| 11117 | |
| 11118 | static int |
| 11119 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11120 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11121 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11122 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11123 | struct drm_atomic_state *state = pipe_config->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11124 | struct drm_connector *connector; |
| 11125 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11126 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11127 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11128 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 11129 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11130 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11131 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11132 | bpp = 12*3; |
| 11133 | else |
| 11134 | bpp = 8*3; |
| 11135 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11136 | pipe_config->pipe_bpp = bpp; |
| 11137 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11138 | /* Clamp display bpp to connector max bpp */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11139 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11140 | int ret; |
| 11141 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11142 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11143 | continue; |
| 11144 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11145 | ret = compute_sink_pipe_bpp(connector_state, pipe_config); |
| 11146 | if (ret) |
| 11147 | return ret; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11148 | } |
| 11149 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11150 | return 0; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11151 | } |
| 11152 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11153 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11154 | { |
| 11155 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11156 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11157 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11158 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11159 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11160 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11161 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11162 | } |
| 11163 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11164 | static inline void |
| 11165 | 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] | 11166 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11167 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11168 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11169 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11170 | m_n->gmch_m, m_n->gmch_n, |
| 11171 | m_n->link_m, m_n->link_n, m_n->tu); |
| 11172 | } |
| 11173 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11174 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 11175 | |
| 11176 | static const char * const output_type_str[] = { |
| 11177 | OUTPUT_TYPE(UNUSED), |
| 11178 | OUTPUT_TYPE(ANALOG), |
| 11179 | OUTPUT_TYPE(DVO), |
| 11180 | OUTPUT_TYPE(SDVO), |
| 11181 | OUTPUT_TYPE(LVDS), |
| 11182 | OUTPUT_TYPE(TVOUT), |
| 11183 | OUTPUT_TYPE(HDMI), |
| 11184 | OUTPUT_TYPE(DP), |
| 11185 | OUTPUT_TYPE(EDP), |
| 11186 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11187 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11188 | OUTPUT_TYPE(DP_MST), |
| 11189 | }; |
| 11190 | |
| 11191 | #undef OUTPUT_TYPE |
| 11192 | |
| 11193 | static void snprintf_output_types(char *buf, size_t len, |
| 11194 | unsigned int output_types) |
| 11195 | { |
| 11196 | char *str = buf; |
| 11197 | int i; |
| 11198 | |
| 11199 | str[0] = '\0'; |
| 11200 | |
| 11201 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 11202 | int r; |
| 11203 | |
| 11204 | if ((output_types & BIT(i)) == 0) |
| 11205 | continue; |
| 11206 | |
| 11207 | r = snprintf(str, len, "%s%s", |
| 11208 | str != buf ? "," : "", output_type_str[i]); |
| 11209 | if (r >= len) |
| 11210 | break; |
| 11211 | str += r; |
| 11212 | len -= r; |
| 11213 | |
| 11214 | output_types &= ~BIT(i); |
| 11215 | } |
| 11216 | |
| 11217 | WARN_ON_ONCE(output_types != 0); |
| 11218 | } |
| 11219 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11220 | static const char * const output_format_str[] = { |
| 11221 | [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid", |
| 11222 | [INTEL_OUTPUT_FORMAT_RGB] = "RGB", |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11223 | [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0", |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 11224 | [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4", |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11225 | }; |
| 11226 | |
| 11227 | static const char *output_formats(enum intel_output_format format) |
| 11228 | { |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11229 | if (format >= ARRAY_SIZE(output_format_str)) |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11230 | format = INTEL_OUTPUT_FORMAT_INVALID; |
| 11231 | return output_format_str[format]; |
| 11232 | } |
| 11233 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11234 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11235 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11236 | const char *context) |
| 11237 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11238 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11239 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11240 | struct drm_plane *plane; |
| 11241 | struct intel_plane *intel_plane; |
| 11242 | struct intel_plane_state *state; |
| 11243 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11244 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11245 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 11246 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 11247 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11248 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11249 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 11250 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 11251 | buf, pipe_config->output_types); |
| 11252 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11253 | DRM_DEBUG_KMS("output format: %s\n", |
| 11254 | output_formats(pipe_config->output_format)); |
| 11255 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11256 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 11257 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11258 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11259 | |
| 11260 | if (pipe_config->has_pch_encoder) |
| 11261 | intel_dump_m_n_config(pipe_config, "fdi", |
| 11262 | pipe_config->fdi_lanes, |
| 11263 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11264 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11265 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11266 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 11267 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 11268 | if (pipe_config->has_drrs) |
| 11269 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 11270 | pipe_config->lane_count, |
| 11271 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11272 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11273 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11274 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11275 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11276 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11277 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11278 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11279 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11280 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11281 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11282 | 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] | 11283 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11284 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 11285 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11286 | |
| 11287 | if (INTEL_GEN(dev_priv) >= 9) |
| 11288 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11289 | crtc->num_scalers, |
| 11290 | pipe_config->scaler_state.scaler_users, |
| 11291 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11292 | |
| 11293 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 11294 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11295 | pipe_config->gmch_pfit.control, |
| 11296 | pipe_config->gmch_pfit.pgm_ratios, |
| 11297 | pipe_config->gmch_pfit.lvds_border_bits); |
| 11298 | else |
| 11299 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 11300 | pipe_config->pch_pfit.pos, |
| 11301 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 11302 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11303 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11304 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 11305 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11306 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 11307 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11308 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11309 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11310 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11311 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11312 | intel_plane = to_intel_plane(plane); |
| 11313 | if (intel_plane->pipe != crtc->pipe) |
| 11314 | continue; |
| 11315 | |
| 11316 | state = to_intel_plane_state(plane->state); |
| 11317 | fb = state->base.fb; |
| 11318 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 11319 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 11320 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11321 | continue; |
| 11322 | } |
| 11323 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11324 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 11325 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11326 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 11327 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11328 | if (INTEL_GEN(dev_priv) >= 9) |
| 11329 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 11330 | state->scaler_id, |
| 11331 | state->base.src.x1 >> 16, |
| 11332 | state->base.src.y1 >> 16, |
| 11333 | drm_rect_width(&state->base.src) >> 16, |
| 11334 | drm_rect_height(&state->base.src) >> 16, |
| 11335 | state->base.dst.x1, state->base.dst.y1, |
| 11336 | drm_rect_width(&state->base.dst), |
| 11337 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11338 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11339 | } |
| 11340 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11341 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11342 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11343 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11344 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11345 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11346 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11347 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11348 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11349 | |
| 11350 | /* |
| 11351 | * Walk the connector list instead of the encoder |
| 11352 | * list to detect the problem on ddi platforms |
| 11353 | * where there's just one encoder per digital port. |
| 11354 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11355 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11356 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11357 | struct drm_connector_state *connector_state; |
| 11358 | struct intel_encoder *encoder; |
| 11359 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 11360 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11361 | if (!connector_state) |
| 11362 | connector_state = connector->state; |
| 11363 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11364 | if (!connector_state->best_encoder) |
| 11365 | continue; |
| 11366 | |
| 11367 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11368 | |
| 11369 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11370 | |
| 11371 | switch (encoder->type) { |
| 11372 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11373 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11374 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11375 | break; |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 11376 | /* else: fall through */ |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 11377 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11378 | case INTEL_OUTPUT_HDMI: |
| 11379 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11380 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11381 | |
| 11382 | /* the same port mustn't appear more than once */ |
| 11383 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11384 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11385 | |
| 11386 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11387 | break; |
| 11388 | case INTEL_OUTPUT_DP_MST: |
| 11389 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11390 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11391 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11392 | default: |
| 11393 | break; |
| 11394 | } |
| 11395 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11396 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11397 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11398 | /* can't mix MST and SST/HDMI on the same port */ |
| 11399 | if (used_ports & used_mst_ports) |
| 11400 | return false; |
| 11401 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11402 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11403 | } |
| 11404 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11405 | static void |
| 11406 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11407 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11408 | struct drm_i915_private *dev_priv = |
| 11409 | to_i915(crtc_state->base.crtc->dev); |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11410 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11411 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11412 | struct intel_shared_dpll *shared_dpll; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11413 | struct intel_crtc_wm_state wm_state; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11414 | bool force_thru, ips_force_disable; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11415 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 11416 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 11417 | * kzalloc'd. Code that depends on any field being zero should be |
| 11418 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 11419 | * only fields that are know to not cause problems are preserved. */ |
| 11420 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11421 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11422 | shared_dpll = crtc_state->shared_dpll; |
| 11423 | dpll_hw_state = crtc_state->dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11424 | force_thru = crtc_state->pch_pfit.force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11425 | ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11426 | if (IS_G4X(dev_priv) || |
| 11427 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11428 | wm_state = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11429 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11430 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 11431 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
| 11432 | memset(&crtc_state->base + 1, 0, |
| 11433 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11434 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11435 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11436 | crtc_state->shared_dpll = shared_dpll; |
| 11437 | crtc_state->dpll_hw_state = dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11438 | crtc_state->pch_pfit.force_thru = force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11439 | crtc_state->ips_force_disable = ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11440 | if (IS_G4X(dev_priv) || |
| 11441 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11442 | crtc_state->wm = wm_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11443 | } |
| 11444 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11445 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11446 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11447 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11448 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11449 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11450 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11451 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11452 | struct drm_connector_state *connector_state; |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11453 | int base_bpp, ret; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11454 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11455 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11456 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11457 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11458 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11459 | pipe_config->cpu_transcoder = |
| 11460 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11461 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11462 | /* |
| 11463 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11464 | * positive or negative polarity is requested, treat this as meaning |
| 11465 | * negative polarity. |
| 11466 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11467 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11468 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11469 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11470 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11471 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11472 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11473 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11474 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11475 | ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11476 | pipe_config); |
| 11477 | if (ret) |
| 11478 | return ret; |
| 11479 | |
| 11480 | base_bpp = pipe_config->pipe_bpp; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11481 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11482 | /* |
| 11483 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11484 | * increase the actual pipe size due to the frame doubling and |
| 11485 | * insertion of additional space for blanks between the frame. This |
| 11486 | * is stored in the crtc timings. We use the requested mode to do this |
| 11487 | * computation to clearly distinguish it from the adjusted mode, which |
| 11488 | * can be changed by the connectors in the below retry loop. |
| 11489 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 11490 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11491 | &pipe_config->pipe_src_w, |
| 11492 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11493 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11494 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11495 | if (connector_state->crtc != crtc) |
| 11496 | continue; |
| 11497 | |
| 11498 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11499 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11500 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11501 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11502 | return -EINVAL; |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11503 | } |
| 11504 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11505 | /* |
| 11506 | * Determine output_types before calling the .compute_config() |
| 11507 | * hooks so that the hooks can use this information safely. |
| 11508 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11509 | if (encoder->compute_output_type) |
| 11510 | pipe_config->output_types |= |
| 11511 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11512 | connector_state)); |
| 11513 | else |
| 11514 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11515 | } |
| 11516 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11517 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11518 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11519 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11520 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11521 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11522 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11523 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11524 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11525 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11526 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11527 | * adjust it according to limitations or connector properties, and also |
| 11528 | * a chance to reject the mode entirely. |
| 11529 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11530 | 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] | 11531 | if (connector_state->crtc != crtc) |
| 11532 | continue; |
| 11533 | |
| 11534 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11535 | |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 11536 | if (!(encoder->compute_config(encoder, pipe_config, connector_state))) { |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 11537 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11538 | return -EINVAL; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11539 | } |
| 11540 | } |
| 11541 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11542 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11543 | * done afterwards in case the encoder adjusts the mode. */ |
| 11544 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11545 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11546 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11547 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11548 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 11549 | if (ret == -EDEADLK) |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11550 | return ret; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11551 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11552 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11553 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11554 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11555 | |
| 11556 | if (ret == RETRY) { |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11557 | if (WARN(!retry, "loop in pipe configuration computation\n")) |
| 11558 | return -EINVAL; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11559 | |
| 11560 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11561 | retry = false; |
| 11562 | goto encoder_retry; |
| 11563 | } |
| 11564 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11565 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11566 | * only enable it on 6bpc panels and when its not a compliance |
| 11567 | * test requesting 6bpc video pattern. |
| 11568 | */ |
| 11569 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11570 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11571 | 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] | 11572 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11573 | |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11574 | return 0; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11575 | } |
| 11576 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11577 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11578 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11579 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11580 | |
| 11581 | if (clock1 == clock2) |
| 11582 | return true; |
| 11583 | |
| 11584 | if (!clock1 || !clock2) |
| 11585 | return false; |
| 11586 | |
| 11587 | diff = abs(clock1 - clock2); |
| 11588 | |
| 11589 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11590 | return true; |
| 11591 | |
| 11592 | return false; |
| 11593 | } |
| 11594 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11595 | static bool |
| 11596 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11597 | unsigned int m2, unsigned int n2, |
| 11598 | bool exact) |
| 11599 | { |
| 11600 | if (m == m2 && n == n2) |
| 11601 | return true; |
| 11602 | |
| 11603 | if (exact || !m || !n || !m2 || !n2) |
| 11604 | return false; |
| 11605 | |
| 11606 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11607 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11608 | if (n > n2) { |
| 11609 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11610 | m2 <<= 1; |
| 11611 | n2 <<= 1; |
| 11612 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11613 | } else if (n < n2) { |
| 11614 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11615 | m <<= 1; |
| 11616 | n <<= 1; |
| 11617 | } |
| 11618 | } |
| 11619 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11620 | if (n != n2) |
| 11621 | return false; |
| 11622 | |
| 11623 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11624 | } |
| 11625 | |
| 11626 | static bool |
| 11627 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11628 | struct intel_link_m_n *m2_n2, |
| 11629 | bool adjust) |
| 11630 | { |
| 11631 | if (m_n->tu == m2_n2->tu && |
| 11632 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11633 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11634 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11635 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11636 | if (adjust) |
| 11637 | *m2_n2 = *m_n; |
| 11638 | |
| 11639 | return true; |
| 11640 | } |
| 11641 | |
| 11642 | return false; |
| 11643 | } |
| 11644 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11645 | static void __printf(3, 4) |
| 11646 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11647 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11648 | struct va_format vaf; |
| 11649 | va_list args; |
| 11650 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11651 | va_start(args, format); |
| 11652 | vaf.fmt = format; |
| 11653 | vaf.va = &args; |
| 11654 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11655 | if (adjust) |
| 11656 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11657 | else |
| 11658 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11659 | |
| 11660 | va_end(args); |
| 11661 | } |
| 11662 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11663 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11664 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11665 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11666 | struct intel_crtc_state *pipe_config, |
| 11667 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11668 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11669 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11670 | bool fixup_inherited = adjust && |
| 11671 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11672 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11673 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11674 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11675 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11676 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11677 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11678 | current_config->name, \ |
| 11679 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11680 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11681 | } \ |
| 11682 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11683 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11684 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11685 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11686 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11687 | "(expected %i, found %i)\n", \ |
| 11688 | current_config->name, \ |
| 11689 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11690 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11691 | } \ |
| 11692 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11693 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11694 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11695 | if (current_config->name != pipe_config->name) { \ |
| 11696 | pipe_config_err(adjust, __stringify(name), \ |
| 11697 | "(expected %s, found %s)\n", \ |
| 11698 | yesno(current_config->name), \ |
| 11699 | yesno(pipe_config->name)); \ |
| 11700 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11701 | } \ |
| 11702 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11703 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11704 | /* |
| 11705 | * Checks state where we only read out the enabling, but not the entire |
| 11706 | * state itself (like full infoframes or ELD for audio). These states |
| 11707 | * require a full modeset on bootup to fix up. |
| 11708 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11709 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11710 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11711 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11712 | } else { \ |
| 11713 | pipe_config_err(adjust, __stringify(name), \ |
| 11714 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11715 | yesno(current_config->name), \ |
| 11716 | yesno(pipe_config->name)); \ |
| 11717 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11718 | } \ |
| 11719 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11720 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11721 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11722 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11723 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11724 | "(expected %p, found %p)\n", \ |
| 11725 | current_config->name, \ |
| 11726 | pipe_config->name); \ |
| 11727 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11728 | } \ |
| 11729 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11730 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11731 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11732 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11733 | &pipe_config->name,\ |
| 11734 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11735 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11736 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11737 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11738 | current_config->name.tu, \ |
| 11739 | current_config->name.gmch_m, \ |
| 11740 | current_config->name.gmch_n, \ |
| 11741 | current_config->name.link_m, \ |
| 11742 | current_config->name.link_n, \ |
| 11743 | pipe_config->name.tu, \ |
| 11744 | pipe_config->name.gmch_m, \ |
| 11745 | pipe_config->name.gmch_n, \ |
| 11746 | pipe_config->name.link_m, \ |
| 11747 | pipe_config->name.link_n); \ |
| 11748 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11749 | } \ |
| 11750 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11751 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 11752 | /* This is required for BDW+ where there is only one set of registers for |
| 11753 | * switching between high and low RR. |
| 11754 | * This macro can be used whenever a comparison has to be made between one |
| 11755 | * hw state and multiple sw state variables. |
| 11756 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11757 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11758 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11759 | &pipe_config->name, adjust) && \ |
| 11760 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 11761 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11762 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11763 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11764 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 11765 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11766 | current_config->name.tu, \ |
| 11767 | current_config->name.gmch_m, \ |
| 11768 | current_config->name.gmch_n, \ |
| 11769 | current_config->name.link_m, \ |
| 11770 | current_config->name.link_n, \ |
| 11771 | current_config->alt_name.tu, \ |
| 11772 | current_config->alt_name.gmch_m, \ |
| 11773 | current_config->alt_name.gmch_n, \ |
| 11774 | current_config->alt_name.link_m, \ |
| 11775 | current_config->alt_name.link_n, \ |
| 11776 | pipe_config->name.tu, \ |
| 11777 | pipe_config->name.gmch_m, \ |
| 11778 | pipe_config->name.gmch_n, \ |
| 11779 | pipe_config->name.link_m, \ |
| 11780 | pipe_config->name.link_n); \ |
| 11781 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11782 | } \ |
| 11783 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11784 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11785 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11786 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11787 | pipe_config_err(adjust, __stringify(name), \ |
| 11788 | "(%x) (expected %i, found %i)\n", \ |
| 11789 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11790 | current_config->name & (mask), \ |
| 11791 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11792 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11793 | } \ |
| 11794 | } while (0) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11795 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11796 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11797 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11798 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11799 | "(expected %i, found %i)\n", \ |
| 11800 | current_config->name, \ |
| 11801 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11802 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11803 | } \ |
| 11804 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11805 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11806 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11807 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11808 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11809 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11810 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11811 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11812 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11813 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11814 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11815 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 11816 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11817 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11818 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11819 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11820 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11821 | if (current_config->has_drrs) |
| 11822 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 11823 | } else |
| 11824 | 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] | 11825 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11826 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 11827 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11828 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11829 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11830 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11831 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11832 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11833 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11834 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11835 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11836 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11837 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11838 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11839 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11840 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11841 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11842 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11843 | PIPE_CONF_CHECK_I(output_format); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11844 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 11845 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 11846 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11847 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 11848 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11849 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 11850 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11851 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11852 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11853 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11854 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11855 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11856 | DRM_MODE_FLAG_INTERLACE); |
| 11857 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11858 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11859 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11860 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11861 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11862 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11863 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11864 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11865 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11866 | DRM_MODE_FLAG_NVSYNC); |
| 11867 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11868 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11869 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 11870 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11871 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 11872 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11873 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11874 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11875 | if (!adjust) { |
| 11876 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11877 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 11878 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11879 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11880 | if (current_config->pch_pfit.enabled) { |
| 11881 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 11882 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 11883 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11884 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11885 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11886 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11887 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 11888 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11889 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11890 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11891 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11892 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11893 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11894 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11895 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11896 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 11897 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11898 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11899 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11900 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 11901 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 11902 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 11903 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 11904 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 11905 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 11906 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 11907 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 11908 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 11909 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 11910 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 11911 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 11912 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 11913 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 11914 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 11915 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 11916 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 11917 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 11918 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 11919 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 11920 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 11921 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 11922 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11923 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 11924 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 11925 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 11926 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11927 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11928 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11929 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11930 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11931 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11932 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 11933 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 11934 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11935 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11936 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11937 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11938 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11939 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11940 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11941 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11942 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11943 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11944 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11945 | } |
| 11946 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11947 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 11948 | const struct intel_crtc_state *pipe_config) |
| 11949 | { |
| 11950 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 11951 | 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] | 11952 | &pipe_config->fdi_m_n); |
| 11953 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 11954 | |
| 11955 | /* |
| 11956 | * FDI already provided one idea for the dotclock. |
| 11957 | * Yell if the encoder disagrees. |
| 11958 | */ |
| 11959 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 11960 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 11961 | fdi_dotclock, dotclock); |
| 11962 | } |
| 11963 | } |
| 11964 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11965 | static void verify_wm_state(struct drm_crtc *crtc, |
| 11966 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11967 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11968 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11969 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11970 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 11971 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 11972 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 11973 | struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES]; |
| 11974 | struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11975 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11976 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11977 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11978 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11979 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11980 | return; |
| 11981 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11982 | skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 11983 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11984 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 11985 | skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv); |
| 11986 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11987 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11988 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11989 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 11990 | if (INTEL_GEN(dev_priv) >= 11) |
| 11991 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 11992 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 11993 | sw_ddb->enabled_slices, |
| 11994 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11995 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 11996 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11997 | hw_plane_wm = &hw_wm.planes[plane]; |
| 11998 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11999 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12000 | /* Watermarks */ |
| 12001 | for (level = 0; level <= max_level; level++) { |
| 12002 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12003 | &sw_plane_wm->wm[level])) |
| 12004 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12005 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12006 | 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", |
| 12007 | pipe_name(pipe), plane + 1, level, |
| 12008 | sw_plane_wm->wm[level].plane_en, |
| 12009 | sw_plane_wm->wm[level].plane_res_b, |
| 12010 | sw_plane_wm->wm[level].plane_res_l, |
| 12011 | hw_plane_wm->wm[level].plane_en, |
| 12012 | hw_plane_wm->wm[level].plane_res_b, |
| 12013 | hw_plane_wm->wm[level].plane_res_l); |
| 12014 | } |
| 12015 | |
| 12016 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12017 | &sw_plane_wm->trans_wm)) { |
| 12018 | 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", |
| 12019 | pipe_name(pipe), plane + 1, |
| 12020 | sw_plane_wm->trans_wm.plane_en, |
| 12021 | sw_plane_wm->trans_wm.plane_res_b, |
| 12022 | sw_plane_wm->trans_wm.plane_res_l, |
| 12023 | hw_plane_wm->trans_wm.plane_en, |
| 12024 | hw_plane_wm->trans_wm.plane_res_b, |
| 12025 | hw_plane_wm->trans_wm.plane_res_l); |
| 12026 | } |
| 12027 | |
| 12028 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12029 | hw_ddb_entry = &hw_ddb_y[plane]; |
| 12030 | 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] | 12031 | |
| 12032 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12033 | 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] | 12034 | pipe_name(pipe), plane + 1, |
| 12035 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12036 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 12037 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12038 | } |
| 12039 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12040 | /* |
| 12041 | * cursor |
| 12042 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 12043 | * allocation. In that case since the ddb allocation will be updated |
| 12044 | * once the plane becomes visible, we can skip this check |
| 12045 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 12046 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12047 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 12048 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12049 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12050 | /* Watermarks */ |
| 12051 | for (level = 0; level <= max_level; level++) { |
| 12052 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12053 | &sw_plane_wm->wm[level])) |
| 12054 | continue; |
| 12055 | |
| 12056 | 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", |
| 12057 | pipe_name(pipe), level, |
| 12058 | sw_plane_wm->wm[level].plane_en, |
| 12059 | sw_plane_wm->wm[level].plane_res_b, |
| 12060 | sw_plane_wm->wm[level].plane_res_l, |
| 12061 | hw_plane_wm->wm[level].plane_en, |
| 12062 | hw_plane_wm->wm[level].plane_res_b, |
| 12063 | hw_plane_wm->wm[level].plane_res_l); |
| 12064 | } |
| 12065 | |
| 12066 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12067 | &sw_plane_wm->trans_wm)) { |
| 12068 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12069 | pipe_name(pipe), |
| 12070 | sw_plane_wm->trans_wm.plane_en, |
| 12071 | sw_plane_wm->trans_wm.plane_res_b, |
| 12072 | sw_plane_wm->trans_wm.plane_res_l, |
| 12073 | hw_plane_wm->trans_wm.plane_en, |
| 12074 | hw_plane_wm->trans_wm.plane_res_b, |
| 12075 | hw_plane_wm->trans_wm.plane_res_l); |
| 12076 | } |
| 12077 | |
| 12078 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12079 | hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR]; |
| 12080 | 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] | 12081 | |
| 12082 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12083 | 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] | 12084 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12085 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12086 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12087 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12088 | } |
| 12089 | } |
| 12090 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12091 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12092 | verify_connector_state(struct drm_device *dev, |
| 12093 | struct drm_atomic_state *state, |
| 12094 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12095 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12096 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12097 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12098 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12099 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12100 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12101 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12102 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12103 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12104 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12105 | continue; |
| 12106 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12107 | if (crtc) |
| 12108 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 12109 | |
| 12110 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12111 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12112 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12113 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12114 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12115 | } |
| 12116 | |
| 12117 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12118 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12119 | { |
| 12120 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12121 | struct drm_connector *connector; |
| 12122 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 12123 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12124 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12125 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12126 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12127 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12128 | |
| 12129 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12130 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12131 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12132 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12133 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 12134 | new_conn_state, i) { |
| 12135 | if (old_conn_state->best_encoder == &encoder->base) |
| 12136 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12137 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12138 | if (new_conn_state->best_encoder != &encoder->base) |
| 12139 | continue; |
| 12140 | found = enabled = true; |
| 12141 | |
| 12142 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12143 | encoder->base.crtc, |
| 12144 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12145 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12146 | |
| 12147 | if (!found) |
| 12148 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12149 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12150 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12151 | "encoder's enabled state mismatch " |
| 12152 | "(expected %i, found %i)\n", |
| 12153 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12154 | |
| 12155 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12156 | bool active; |
| 12157 | |
| 12158 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12159 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12160 | "encoder detached but still enabled on pipe %c.\n", |
| 12161 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12162 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12163 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12164 | } |
| 12165 | |
| 12166 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12167 | verify_crtc_state(struct drm_crtc *crtc, |
| 12168 | struct drm_crtc_state *old_crtc_state, |
| 12169 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12170 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12171 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12172 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12173 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12174 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12175 | struct intel_crtc_state *pipe_config, *sw_config; |
| 12176 | struct drm_atomic_state *old_state; |
| 12177 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12178 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12179 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 12180 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12181 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12182 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12183 | pipe_config->base.crtc = crtc; |
| 12184 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12185 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12186 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12187 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12188 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12189 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 12190 | /* we keep both pipes enabled on 830 */ |
| 12191 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12192 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12193 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12194 | I915_STATE_WARN(new_crtc_state->active != active, |
| 12195 | "crtc active state doesn't match with hw state " |
| 12196 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12197 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12198 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 12199 | "transitional active state does not match atomic hw state " |
| 12200 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12201 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12202 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12203 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12204 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12205 | active = encoder->get_hw_state(encoder, &pipe); |
| 12206 | I915_STATE_WARN(active != new_crtc_state->active, |
| 12207 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12208 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12209 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12210 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12211 | "Encoder connected to wrong pipe %c\n", |
| 12212 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12213 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 12214 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12215 | encoder->get_config(encoder, pipe_config); |
| 12216 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12217 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12218 | intel_crtc_compute_pixel_rate(pipe_config); |
| 12219 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12220 | if (!new_crtc_state->active) |
| 12221 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12222 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12223 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12224 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12225 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12226 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12227 | pipe_config, false)) { |
| 12228 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 12229 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 12230 | "[hw state]"); |
| 12231 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 12232 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12233 | } |
| 12234 | } |
| 12235 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12236 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12237 | intel_verify_planes(struct intel_atomic_state *state) |
| 12238 | { |
| 12239 | struct intel_plane *plane; |
| 12240 | const struct intel_plane_state *plane_state; |
| 12241 | int i; |
| 12242 | |
| 12243 | for_each_new_intel_plane_in_state(state, plane, |
| 12244 | plane_state, i) |
| 12245 | assert_plane(plane, plane_state->base.visible); |
| 12246 | } |
| 12247 | |
| 12248 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12249 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 12250 | struct intel_shared_dpll *pll, |
| 12251 | struct drm_crtc *crtc, |
| 12252 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12253 | { |
| 12254 | struct intel_dpll_hw_state dpll_hw_state; |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12255 | unsigned int crtc_mask; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12256 | bool active; |
| 12257 | |
| 12258 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12259 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 12260 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12261 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 12262 | 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] | 12263 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 12264 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12265 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12266 | "pll in active use but not on in sw tracking\n"); |
| 12267 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12268 | "pll is on but not used by any active crtc\n"); |
| 12269 | I915_STATE_WARN(pll->on != active, |
| 12270 | "pll on state mismatch (expected %i, found %i)\n", |
| 12271 | pll->on, active); |
| 12272 | } |
| 12273 | |
| 12274 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12275 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12276 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12277 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12278 | |
| 12279 | return; |
| 12280 | } |
| 12281 | |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12282 | crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12283 | |
| 12284 | if (new_state->active) |
| 12285 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 12286 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 12287 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12288 | else |
| 12289 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12290 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 12291 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12292 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12293 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12294 | "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] | 12295 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12296 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12297 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12298 | &dpll_hw_state, |
| 12299 | sizeof(dpll_hw_state)), |
| 12300 | "pll hw state mismatch\n"); |
| 12301 | } |
| 12302 | |
| 12303 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12304 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 12305 | struct drm_crtc_state *old_crtc_state, |
| 12306 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12307 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12308 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12309 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 12310 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 12311 | |
| 12312 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12313 | 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] | 12314 | |
| 12315 | if (old_state->shared_dpll && |
| 12316 | old_state->shared_dpll != new_state->shared_dpll) { |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12317 | unsigned int crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12318 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 12319 | |
| 12320 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12321 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 12322 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12323 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12324 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 12325 | pipe_name(drm_crtc_index(crtc))); |
| 12326 | } |
| 12327 | } |
| 12328 | |
| 12329 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12330 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12331 | struct drm_atomic_state *state, |
| 12332 | struct drm_crtc_state *old_state, |
| 12333 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12334 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12335 | if (!needs_modeset(new_state) && |
| 12336 | !to_intel_crtc_state(new_state)->update_pipe) |
| 12337 | return; |
| 12338 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12339 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12340 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12341 | verify_crtc_state(crtc, old_state, new_state); |
| 12342 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12343 | } |
| 12344 | |
| 12345 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12346 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12347 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12348 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12349 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12350 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12351 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12352 | 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] | 12353 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12354 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12355 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12356 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 12357 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12358 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12359 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12360 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12361 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12362 | } |
| 12363 | |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12364 | 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] | 12365 | { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12366 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12367 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12368 | |
| 12369 | /* |
| 12370 | * The scanline counter increments at the leading edge of hsync. |
| 12371 | * |
| 12372 | * On most platforms it starts counting from vtotal-1 on the |
| 12373 | * first active line. That means the scanline counter value is |
| 12374 | * always one less than what we would expect. Ie. just after |
| 12375 | * start of vblank, which also occurs at start of hsync (on the |
| 12376 | * last active line), the scanline counter will read vblank_start-1. |
| 12377 | * |
| 12378 | * On gen2 the scanline counter starts counting from 1 instead |
| 12379 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12380 | * to keep the value positive), instead of adding one. |
| 12381 | * |
| 12382 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12383 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12384 | * there's an extra 1 line difference. So we need to add two instead of |
| 12385 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 12386 | * |
| 12387 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 12388 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 12389 | * that means we can't tell whether we're in vblank or not while |
| 12390 | * we're on that particular line. We must still set scanline_offset |
| 12391 | * to 1 so that the vblank timestamps come out correct when we query |
| 12392 | * the scanline counter from within the vblank interrupt handler. |
| 12393 | * However if queried just before the start of vblank we'll get an |
| 12394 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12395 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 12396 | if (IS_GEN(dev_priv, 2)) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12397 | 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] | 12398 | int vtotal; |
| 12399 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12400 | vtotal = adjusted_mode->crtc_vtotal; |
| 12401 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12402 | vtotal /= 2; |
| 12403 | |
| 12404 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12405 | } else if (HAS_DDI(dev_priv) && |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12406 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12407 | crtc->scanline_offset = 2; |
| 12408 | } else |
| 12409 | crtc->scanline_offset = 1; |
| 12410 | } |
| 12411 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12412 | 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] | 12413 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12414 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12415 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12416 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12417 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12418 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12419 | |
| 12420 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12421 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12422 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12423 | 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] | 12424 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12425 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12426 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12427 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12428 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12429 | continue; |
| 12430 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12431 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12432 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12433 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12434 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12435 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 12436 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12437 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12438 | } |
| 12439 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12440 | /* |
| 12441 | * This implements the workaround described in the "notes" section of the mode |
| 12442 | * set sequence documentation. When going from no pipes or single pipe to |
| 12443 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12444 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12445 | */ |
| 12446 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12447 | { |
| 12448 | struct drm_crtc_state *crtc_state; |
| 12449 | struct intel_crtc *intel_crtc; |
| 12450 | struct drm_crtc *crtc; |
| 12451 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12452 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12453 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12454 | int i; |
| 12455 | |
| 12456 | /* 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] | 12457 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12458 | intel_crtc = to_intel_crtc(crtc); |
| 12459 | |
| 12460 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12461 | continue; |
| 12462 | |
| 12463 | if (first_crtc_state) { |
| 12464 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12465 | break; |
| 12466 | } else { |
| 12467 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12468 | first_pipe = intel_crtc->pipe; |
| 12469 | } |
| 12470 | } |
| 12471 | |
| 12472 | /* No workaround needed? */ |
| 12473 | if (!first_crtc_state) |
| 12474 | return 0; |
| 12475 | |
| 12476 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12477 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12478 | struct intel_crtc_state *pipe_config; |
| 12479 | |
| 12480 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12481 | if (IS_ERR(pipe_config)) |
| 12482 | return PTR_ERR(pipe_config); |
| 12483 | |
| 12484 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12485 | |
| 12486 | if (!pipe_config->base.active || |
| 12487 | needs_modeset(&pipe_config->base)) |
| 12488 | continue; |
| 12489 | |
| 12490 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12491 | if (enabled_pipe != INVALID_PIPE) |
| 12492 | return 0; |
| 12493 | |
| 12494 | enabled_pipe = intel_crtc->pipe; |
| 12495 | } |
| 12496 | |
| 12497 | if (enabled_pipe != INVALID_PIPE) |
| 12498 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12499 | else if (other_crtc_state) |
| 12500 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12501 | |
| 12502 | return 0; |
| 12503 | } |
| 12504 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12505 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12506 | { |
| 12507 | struct drm_crtc *crtc; |
| 12508 | |
| 12509 | /* Add all pipes to the state */ |
| 12510 | for_each_crtc(state->dev, crtc) { |
| 12511 | struct drm_crtc_state *crtc_state; |
| 12512 | |
| 12513 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12514 | if (IS_ERR(crtc_state)) |
| 12515 | return PTR_ERR(crtc_state); |
| 12516 | } |
| 12517 | |
| 12518 | return 0; |
| 12519 | } |
| 12520 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12521 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12522 | { |
| 12523 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12524 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12525 | /* |
| 12526 | * Add all pipes to the state, and force |
| 12527 | * a modeset on all the active ones. |
| 12528 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12529 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12530 | struct drm_crtc_state *crtc_state; |
| 12531 | int ret; |
| 12532 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12533 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12534 | if (IS_ERR(crtc_state)) |
| 12535 | return PTR_ERR(crtc_state); |
| 12536 | |
| 12537 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12538 | continue; |
| 12539 | |
| 12540 | crtc_state->mode_changed = true; |
| 12541 | |
| 12542 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12543 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12544 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12545 | |
| 12546 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12547 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12548 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12549 | } |
| 12550 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12551 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12552 | } |
| 12553 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12554 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12555 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12556 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12557 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12558 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12559 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12560 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12561 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12562 | if (!check_digital_port_conflicts(state)) { |
| 12563 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12564 | return -EINVAL; |
| 12565 | } |
| 12566 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12567 | intel_state->modeset = true; |
| 12568 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12569 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12570 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12571 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12572 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12573 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12574 | intel_state->active_crtcs |= 1 << i; |
| 12575 | else |
| 12576 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12577 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12578 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12579 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12580 | } |
| 12581 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12582 | /* |
| 12583 | * See if the config requires any additional preparation, e.g. |
| 12584 | * to adjust global state with pipes off. We need to do this |
| 12585 | * here so we can get the modeset_pipe updated config for the new |
| 12586 | * mode set on this crtc. For other crtcs we need to use the |
| 12587 | * adjusted_mode bits in the crtc directly. |
| 12588 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12589 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12590 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12591 | if (ret < 0) |
| 12592 | return ret; |
| 12593 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12594 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12595 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12596 | * holding all the crtc locks, even if we don't end up |
| 12597 | * touching the hardware |
| 12598 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12599 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12600 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12601 | ret = intel_lock_all_pipes(state); |
| 12602 | if (ret < 0) |
| 12603 | return ret; |
| 12604 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12605 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12606 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12607 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12608 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12609 | ret = intel_modeset_all_pipes(state); |
| 12610 | if (ret < 0) |
| 12611 | return ret; |
| 12612 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12613 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12614 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12615 | intel_state->cdclk.logical.cdclk, |
| 12616 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12617 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12618 | intel_state->cdclk.logical.voltage_level, |
| 12619 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12620 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12621 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12622 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12623 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12624 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12625 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12626 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12627 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12628 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12629 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12630 | } |
| 12631 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12632 | /* |
| 12633 | * Handle calculation of various watermark data at the end of the atomic check |
| 12634 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12635 | * handlers to ensure that all derived state has been updated. |
| 12636 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12637 | static int calc_watermark_data(struct intel_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12638 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12639 | struct drm_device *dev = state->base.dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12640 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12641 | |
| 12642 | /* Is there platform-specific watermark information to calculate? */ |
| 12643 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12644 | return dev_priv->display.compute_global_watermarks(state); |
| 12645 | |
| 12646 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12647 | } |
| 12648 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12649 | /** |
| 12650 | * intel_atomic_check - validate state object |
| 12651 | * @dev: drm device |
| 12652 | * @state: state to validate |
| 12653 | */ |
| 12654 | static int intel_atomic_check(struct drm_device *dev, |
| 12655 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12656 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12657 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12658 | 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] | 12659 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12660 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12661 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12662 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12663 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12664 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12665 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12666 | crtc_state, i) { |
| 12667 | if (crtc_state->mode.private_flags != |
| 12668 | old_crtc_state->mode.private_flags) |
| 12669 | crtc_state->mode_changed = true; |
| 12670 | } |
| 12671 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12672 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12673 | if (ret) |
| 12674 | return ret; |
| 12675 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12676 | 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] | 12677 | struct intel_crtc_state *pipe_config = |
| 12678 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12679 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12680 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12681 | continue; |
| 12682 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12683 | if (!crtc_state->enable) { |
| 12684 | any_ms = true; |
| 12685 | continue; |
| 12686 | } |
| 12687 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12688 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 12689 | if (ret == -EDEADLK) |
| 12690 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12691 | if (ret) { |
| 12692 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12693 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12694 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12695 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12696 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 12697 | if (i915_modparams.fastboot && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12698 | intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12699 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12700 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12701 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12702 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12703 | } |
| 12704 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12705 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12706 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12707 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12708 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12709 | needs_modeset(crtc_state) ? |
| 12710 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12711 | } |
| 12712 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12713 | if (any_ms) { |
| 12714 | ret = intel_modeset_checks(state); |
| 12715 | |
| 12716 | if (ret) |
| 12717 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12718 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12719 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12720 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12721 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 12722 | ret = icl_add_linked_planes(intel_state); |
| 12723 | if (ret) |
| 12724 | return ret; |
| 12725 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12726 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12727 | if (ret) |
| 12728 | return ret; |
| 12729 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12730 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12731 | return calc_watermark_data(intel_state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12732 | } |
| 12733 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12734 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12735 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12736 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12737 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12738 | } |
| 12739 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12740 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12741 | { |
| 12742 | struct drm_device *dev = crtc->base.dev; |
| 12743 | |
| 12744 | if (!dev->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 12745 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12746 | |
| 12747 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 12748 | } |
| 12749 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12750 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 12751 | struct drm_atomic_state *state, |
| 12752 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12753 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12754 | { |
| 12755 | struct drm_device *dev = crtc->dev; |
| 12756 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 12757 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12758 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 12759 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12760 | struct intel_plane_state *new_plane_state = |
| 12761 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 12762 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12763 | |
| 12764 | if (modeset) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12765 | update_scanline_offset(pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12766 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12767 | |
| 12768 | /* vblanks work again, re-enable pipe CRC. */ |
| 12769 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12770 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12771 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12772 | pipe_config); |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 12773 | |
| 12774 | if (pipe_config->update_pipe) |
| 12775 | intel_encoders_update_pipe(crtc, pipe_config, state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12776 | } |
| 12777 | |
Maarten Lankhorst | 50c42fc | 2018-12-20 16:17:19 +0100 | [diff] [blame] | 12778 | if (pipe_config->update_pipe && !pipe_config->enable_fbc) |
| 12779 | intel_fbc_disable(intel_crtc); |
| 12780 | else if (new_plane_state) |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12781 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12782 | |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12783 | intel_begin_crtc_commit(crtc, old_crtc_state); |
| 12784 | |
Ville Syrjälä | 5f2e511 | 2018-11-14 23:07:27 +0200 | [diff] [blame] | 12785 | if (INTEL_GEN(dev_priv) >= 9) |
| 12786 | skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
| 12787 | else |
| 12788 | i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12789 | |
| 12790 | intel_finish_crtc_commit(crtc, old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12791 | } |
| 12792 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12793 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12794 | { |
| 12795 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12796 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12797 | int i; |
| 12798 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12799 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12800 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12801 | continue; |
| 12802 | |
| 12803 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12804 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12805 | } |
| 12806 | } |
| 12807 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12808 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12809 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12810 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12811 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 12812 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12813 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12814 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12815 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12816 | unsigned int updated = 0; |
| 12817 | bool progress; |
| 12818 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12819 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12820 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 12821 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12822 | struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12823 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12824 | 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] | 12825 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12826 | if (new_crtc_state->active) |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12827 | entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12828 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12829 | /* If 2nd DBuf slice required, enable it here */ |
| 12830 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 12831 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 12832 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12833 | /* |
| 12834 | * Whenever the number of active pipes changes, we need to make sure we |
| 12835 | * update the pipes in the right order so that their ddb allocations |
| 12836 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 12837 | * cause pipe underruns and other bad stuff. |
| 12838 | */ |
| 12839 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12840 | progress = false; |
| 12841 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12842 | 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] | 12843 | bool vbl_wait = false; |
| 12844 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12845 | |
| 12846 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12847 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12848 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12849 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12850 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12851 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12852 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12853 | if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb, |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 12854 | entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12855 | INTEL_INFO(dev_priv)->num_pipes, i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12856 | continue; |
| 12857 | |
| 12858 | updated |= cmask; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12859 | entries[i] = cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12860 | |
| 12861 | /* |
| 12862 | * If this is an already active pipe, it's DDB changed, |
| 12863 | * and this isn't the last pipe that needs updating |
| 12864 | * then we need to wait for a vblank to pass for the |
| 12865 | * new ddb allocation to take effect. |
| 12866 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12867 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 12868 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12869 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12870 | intel_state->wm_results.dirty_pipes != updated) |
| 12871 | vbl_wait = true; |
| 12872 | |
| 12873 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12874 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12875 | |
| 12876 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12877 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12878 | |
| 12879 | progress = true; |
| 12880 | } |
| 12881 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12882 | |
| 12883 | /* If 2nd DBuf slice is no more required disable it */ |
| 12884 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 12885 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12886 | } |
| 12887 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 12888 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 12889 | { |
| 12890 | struct intel_atomic_state *state, *next; |
| 12891 | struct llist_node *freed; |
| 12892 | |
| 12893 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 12894 | llist_for_each_entry_safe(state, next, freed, freed) |
| 12895 | drm_atomic_state_put(&state->base); |
| 12896 | } |
| 12897 | |
| 12898 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 12899 | { |
| 12900 | struct drm_i915_private *dev_priv = |
| 12901 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 12902 | |
| 12903 | intel_atomic_helper_free_state(dev_priv); |
| 12904 | } |
| 12905 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12906 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 12907 | { |
| 12908 | struct wait_queue_entry wait_fence, wait_reset; |
| 12909 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 12910 | |
| 12911 | init_wait_entry(&wait_fence, 0); |
| 12912 | init_wait_entry(&wait_reset, 0); |
| 12913 | for (;;) { |
| 12914 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 12915 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 12916 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 12917 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 12918 | |
| 12919 | |
| 12920 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 12921 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 12922 | break; |
| 12923 | |
| 12924 | schedule(); |
| 12925 | } |
| 12926 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 12927 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 12928 | } |
| 12929 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 12930 | static void intel_atomic_cleanup_work(struct work_struct *work) |
| 12931 | { |
| 12932 | struct drm_atomic_state *state = |
| 12933 | container_of(work, struct drm_atomic_state, commit_work); |
| 12934 | struct drm_i915_private *i915 = to_i915(state->dev); |
| 12935 | |
| 12936 | drm_atomic_helper_cleanup_planes(&i915->drm, state); |
| 12937 | drm_atomic_helper_commit_cleanup_done(state); |
| 12938 | drm_atomic_state_put(state); |
| 12939 | |
| 12940 | intel_atomic_helper_free_state(i915); |
| 12941 | } |
| 12942 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12943 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12944 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12945 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12946 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12947 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12948 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12949 | struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 12950 | struct drm_crtc *crtc; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12951 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 12952 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 12953 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12954 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12955 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12956 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 12957 | drm_atomic_helper_wait_for_dependencies(state); |
| 12958 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12959 | if (intel_state->modeset) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12960 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12961 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12962 | 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] | 12963 | old_intel_crtc_state = to_intel_crtc_state(old_crtc_state); |
| 12964 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 12965 | intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12966 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12967 | if (needs_modeset(new_crtc_state) || |
| 12968 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12969 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12970 | put_domains[intel_crtc->pipe] = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12971 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12972 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12973 | } |
| 12974 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12975 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12976 | continue; |
| 12977 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12978 | intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 12979 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 12980 | if (old_crtc_state->active) { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 12981 | intel_crtc_disable_planes(intel_state, intel_crtc); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12982 | |
| 12983 | /* |
| 12984 | * We need to disable pipe CRC before disabling the pipe, |
| 12985 | * or we race against vblank off. |
| 12986 | */ |
| 12987 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 12988 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12989 | dev_priv->display.crtc_disable(old_intel_crtc_state, state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12990 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 12991 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 12992 | intel_disable_shared_dpll(old_intel_crtc_state); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 12993 | |
| 12994 | /* |
| 12995 | * Underruns don't always raise |
| 12996 | * interrupts, so check manually. |
| 12997 | */ |
| 12998 | intel_check_cpu_fifo_underruns(dev_priv); |
| 12999 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13000 | |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 13001 | /* FIXME unify this for all platforms */ |
| 13002 | if (!new_crtc_state->active && |
| 13003 | !HAS_GMCH_DISPLAY(dev_priv) && |
| 13004 | dev_priv->display.initial_watermarks) |
| 13005 | dev_priv->display.initial_watermarks(intel_state, |
| 13006 | new_intel_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13007 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13008 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13009 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 13010 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 13011 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 13012 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13013 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13014 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13015 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13016 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 13017 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 13018 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13019 | /* |
| 13020 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 13021 | * have more then one pipe enabled |
| 13022 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13023 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13024 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13025 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13026 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13027 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13028 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13029 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13030 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 13031 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13032 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13033 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13034 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13035 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13036 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13037 | spin_unlock_irq(&dev->event_lock); |
| 13038 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13039 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13040 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13041 | } |
| 13042 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13043 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13044 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13045 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13046 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 13047 | * already, but still need the state for the delayed optimization. To |
| 13048 | * fix this: |
| 13049 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 13050 | * - schedule that vblank worker _before_ calling hw_done |
| 13051 | * - at the start of commit_tail, cancel it _synchrously |
| 13052 | * - switch over to the vblank wait helper in the core after that since |
| 13053 | * we don't need out special handling any more. |
| 13054 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13055 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13056 | |
| 13057 | /* |
| 13058 | * Now that the vblank has passed, we can go ahead and program the |
| 13059 | * optimal watermarks on platforms that need two-step watermark |
| 13060 | * programming. |
| 13061 | * |
| 13062 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13063 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13064 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13065 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13066 | |
| 13067 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13068 | dev_priv->display.optimize_watermarks(intel_state, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13069 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13070 | } |
| 13071 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13072 | 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] | 13073 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13074 | |
| 13075 | if (put_domains[i]) |
| 13076 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13077 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13078 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13079 | } |
| 13080 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 13081 | if (intel_state->modeset) |
| 13082 | intel_verify_planes(intel_state); |
| 13083 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13084 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13085 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13086 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13087 | drm_atomic_helper_commit_hw_done(state); |
| 13088 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13089 | if (intel_state->modeset) { |
| 13090 | /* As one of the primary mmio accessors, KMS has a high |
| 13091 | * likelihood of triggering bugs in unclaimed access. After we |
| 13092 | * finish modesetting, see if an error has been flagged, and if |
| 13093 | * so enable debugging for the next modeset - and hope we catch |
| 13094 | * the culprit. |
| 13095 | */ |
| 13096 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13097 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13098 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13099 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 13100 | /* |
| 13101 | * Defer the cleanup of the old state to a separate worker to not |
| 13102 | * impede the current task (userspace for blocking modesets) that |
| 13103 | * are executed inline. For out-of-line asynchronous modesets/flips, |
| 13104 | * deferring to a new worker seems overkill, but we would place a |
| 13105 | * schedule point (cond_resched()) here anyway to keep latencies |
| 13106 | * down. |
| 13107 | */ |
| 13108 | INIT_WORK(&state->commit_work, intel_atomic_cleanup_work); |
Chris Wilson | 41db645 | 2018-07-12 12:57:29 +0100 | [diff] [blame] | 13109 | queue_work(system_highpri_wq, &state->commit_work); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13110 | } |
| 13111 | |
| 13112 | static void intel_atomic_commit_work(struct work_struct *work) |
| 13113 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13114 | struct drm_atomic_state *state = |
| 13115 | container_of(work, struct drm_atomic_state, commit_work); |
| 13116 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13117 | intel_atomic_commit_tail(state); |
| 13118 | } |
| 13119 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13120 | static int __i915_sw_fence_call |
| 13121 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 13122 | enum i915_sw_fence_notify notify) |
| 13123 | { |
| 13124 | struct intel_atomic_state *state = |
| 13125 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 13126 | |
| 13127 | switch (notify) { |
| 13128 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13129 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13130 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13131 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 13132 | { |
| 13133 | struct intel_atomic_helper *helper = |
| 13134 | &to_i915(state->base.dev)->atomic_helper; |
| 13135 | |
| 13136 | if (llist_add(&state->freed, &helper->free_list)) |
| 13137 | schedule_work(&helper->free_work); |
| 13138 | break; |
| 13139 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13140 | } |
| 13141 | |
| 13142 | return NOTIFY_DONE; |
| 13143 | } |
| 13144 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13145 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 13146 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13147 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13148 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13149 | int i; |
| 13150 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13151 | 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] | 13152 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13153 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 13154 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13155 | } |
| 13156 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13157 | /** |
| 13158 | * intel_atomic_commit - commit validated state object |
| 13159 | * @dev: DRM device |
| 13160 | * @state: the top-level driver state object |
| 13161 | * @nonblock: nonblocking commit |
| 13162 | * |
| 13163 | * This function commits a top-level state object that has been validated |
| 13164 | * with drm_atomic_helper_check(). |
| 13165 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13166 | * RETURNS |
| 13167 | * Zero for success or -errno. |
| 13168 | */ |
| 13169 | static int intel_atomic_commit(struct drm_device *dev, |
| 13170 | struct drm_atomic_state *state, |
| 13171 | bool nonblock) |
| 13172 | { |
| 13173 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13174 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13175 | int ret = 0; |
| 13176 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13177 | drm_atomic_state_get(state); |
| 13178 | i915_sw_fence_init(&intel_state->commit_ready, |
| 13179 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13180 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13181 | /* |
| 13182 | * The intel_legacy_cursor_update() fast path takes care |
| 13183 | * of avoiding the vblank waits for simple cursor |
| 13184 | * movement and flips. For cursor on/off and size changes, |
| 13185 | * we want to perform the vblank waits so that watermark |
| 13186 | * updates happen during the correct frames. Gen9+ have |
| 13187 | * double buffered watermarks and so shouldn't need this. |
| 13188 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13189 | * Unset state->legacy_cursor_update before the call to |
| 13190 | * drm_atomic_helper_setup_commit() because otherwise |
| 13191 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 13192 | * we get FIFO underruns because we didn't wait |
| 13193 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13194 | * |
| 13195 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 13196 | * (assuming we had any) would solve these problems. |
| 13197 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 13198 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 13199 | struct intel_crtc_state *new_crtc_state; |
| 13200 | struct intel_crtc *crtc; |
| 13201 | int i; |
| 13202 | |
| 13203 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 13204 | if (new_crtc_state->wm.need_postvbl_update || |
| 13205 | new_crtc_state->update_wm_post) |
| 13206 | state->legacy_cursor_update = false; |
| 13207 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13208 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13209 | ret = intel_atomic_prepare_commit(dev, state); |
| 13210 | if (ret) { |
| 13211 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 13212 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13213 | return ret; |
| 13214 | } |
| 13215 | |
| 13216 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 13217 | if (!ret) |
| 13218 | ret = drm_atomic_helper_swap_state(state, true); |
| 13219 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13220 | if (ret) { |
| 13221 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13222 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13223 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13224 | return ret; |
| 13225 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13226 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 13227 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13228 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13229 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13230 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 13231 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 13232 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 13233 | memcpy(dev_priv->min_voltage_level, |
| 13234 | intel_state->min_voltage_level, |
| 13235 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13236 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 13237 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 13238 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13239 | } |
| 13240 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 13241 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13242 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13243 | |
| 13244 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13245 | if (nonblock && intel_state->modeset) { |
| 13246 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 13247 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13248 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13249 | } else { |
| 13250 | if (intel_state->modeset) |
| 13251 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13252 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13253 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13254 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13255 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13256 | } |
| 13257 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13258 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 13259 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13260 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13261 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 13262 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13263 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13264 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 13265 | .set_crc_source = intel_crtc_set_crc_source, |
Mahesh Kumar | a8c2083 | 2018-07-13 19:29:38 +0530 | [diff] [blame] | 13266 | .verify_crc_source = intel_crtc_verify_crc_source, |
Mahesh Kumar | 260bc55 | 2018-07-13 19:29:39 +0530 | [diff] [blame] | 13267 | .get_crc_sources = intel_crtc_get_crc_sources, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13268 | }; |
| 13269 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13270 | struct wait_rps_boost { |
| 13271 | struct wait_queue_entry wait; |
| 13272 | |
| 13273 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13274 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13275 | }; |
| 13276 | |
| 13277 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 13278 | unsigned mode, int sync, void *key) |
| 13279 | { |
| 13280 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13281 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13282 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13283 | /* |
| 13284 | * If we missed the vblank, but the request is already running it |
| 13285 | * is reasonable to assume that it will complete before the next |
| 13286 | * vblank without our intervention, so leave RPS alone. |
| 13287 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13288 | if (!i915_request_started(rq)) |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13289 | gen6_rps_boost(rq, NULL); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13290 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13291 | |
| 13292 | drm_crtc_vblank_put(wait->crtc); |
| 13293 | |
| 13294 | list_del(&wait->wait.entry); |
| 13295 | kfree(wait); |
| 13296 | return 1; |
| 13297 | } |
| 13298 | |
| 13299 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 13300 | struct dma_fence *fence) |
| 13301 | { |
| 13302 | struct wait_rps_boost *wait; |
| 13303 | |
| 13304 | if (!dma_fence_is_i915(fence)) |
| 13305 | return; |
| 13306 | |
| 13307 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 13308 | return; |
| 13309 | |
| 13310 | if (drm_crtc_vblank_get(crtc)) |
| 13311 | return; |
| 13312 | |
| 13313 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 13314 | if (!wait) { |
| 13315 | drm_crtc_vblank_put(crtc); |
| 13316 | return; |
| 13317 | } |
| 13318 | |
| 13319 | wait->request = to_request(dma_fence_get(fence)); |
| 13320 | wait->crtc = crtc; |
| 13321 | |
| 13322 | wait->wait.func = do_rps_boost; |
| 13323 | wait->wait.flags = 0; |
| 13324 | |
| 13325 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 13326 | } |
| 13327 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13328 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 13329 | { |
| 13330 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 13331 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 13332 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 13333 | struct i915_vma *vma; |
| 13334 | |
| 13335 | if (plane->id == PLANE_CURSOR && |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 13336 | INTEL_INFO(dev_priv)->display.cursor_needs_physical) { |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13337 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13338 | const int align = intel_cursor_alignment(dev_priv); |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13339 | int err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13340 | |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13341 | err = i915_gem_object_attach_phys(obj, align); |
| 13342 | if (err) |
| 13343 | return err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13344 | } |
| 13345 | |
| 13346 | vma = intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 13347 | &plane_state->view, |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13348 | intel_plane_uses_fence(plane_state), |
| 13349 | &plane_state->flags); |
| 13350 | if (IS_ERR(vma)) |
| 13351 | return PTR_ERR(vma); |
| 13352 | |
| 13353 | plane_state->vma = vma; |
| 13354 | |
| 13355 | return 0; |
| 13356 | } |
| 13357 | |
| 13358 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 13359 | { |
| 13360 | struct i915_vma *vma; |
| 13361 | |
| 13362 | vma = fetch_and_zero(&old_plane_state->vma); |
| 13363 | if (vma) |
| 13364 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 13365 | } |
| 13366 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 13367 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 13368 | { |
| 13369 | struct i915_sched_attr attr = { |
| 13370 | .priority = I915_PRIORITY_DISPLAY, |
| 13371 | }; |
| 13372 | |
| 13373 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 13374 | } |
| 13375 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13376 | /** |
| 13377 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13378 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13379 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13380 | * |
| 13381 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13382 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13383 | * bits. Some older platforms need special physical address handling for |
| 13384 | * cursor planes. |
| 13385 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13386 | * Must be called with struct_mutex held. |
| 13387 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13388 | * Returns 0 on success, negative error code on failure. |
| 13389 | */ |
| 13390 | int |
| 13391 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13392 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13393 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13394 | struct intel_atomic_state *intel_state = |
| 13395 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 13396 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13397 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13398 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13399 | 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] | 13400 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13401 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13402 | if (old_obj) { |
| 13403 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13404 | drm_atomic_get_new_crtc_state(new_state->state, |
| 13405 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13406 | |
| 13407 | /* Big Hammer, we also need to ensure that any pending |
| 13408 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13409 | * current scanout is retired before unpinning the old |
| 13410 | * framebuffer. Note that we rely on userspace rendering |
| 13411 | * into the buffer attached to the pipe they are waiting |
| 13412 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13413 | * point to the MI_WAIT_FOR_EVENT. |
| 13414 | * |
| 13415 | * This should only fail upon a hung GPU, in which case we |
| 13416 | * can safely continue. |
| 13417 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13418 | if (needs_modeset(crtc_state)) { |
| 13419 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13420 | old_obj->resv, NULL, |
| 13421 | false, 0, |
| 13422 | GFP_KERNEL); |
| 13423 | if (ret < 0) |
| 13424 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13425 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13426 | } |
| 13427 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13428 | if (new_state->fence) { /* explicit fencing */ |
| 13429 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 13430 | new_state->fence, |
| 13431 | I915_FENCE_TIMEOUT, |
| 13432 | GFP_KERNEL); |
| 13433 | if (ret < 0) |
| 13434 | return ret; |
| 13435 | } |
| 13436 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 13437 | if (!obj) |
| 13438 | return 0; |
| 13439 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13440 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13441 | if (ret) |
| 13442 | return ret; |
| 13443 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13444 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13445 | if (ret) { |
| 13446 | i915_gem_object_unpin_pages(obj); |
| 13447 | return ret; |
| 13448 | } |
| 13449 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13450 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13451 | |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13452 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13453 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13454 | if (ret) |
| 13455 | return ret; |
| 13456 | |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 13457 | fb_obj_bump_render_priority(obj); |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13458 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 13459 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13460 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13461 | struct dma_fence *fence; |
| 13462 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13463 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13464 | obj->resv, NULL, |
| 13465 | false, I915_FENCE_TIMEOUT, |
| 13466 | GFP_KERNEL); |
| 13467 | if (ret < 0) |
| 13468 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13469 | |
| 13470 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 13471 | if (fence) { |
| 13472 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 13473 | dma_fence_put(fence); |
| 13474 | } |
| 13475 | } else { |
| 13476 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13477 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13478 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13479 | /* |
| 13480 | * We declare pageflips to be interactive and so merit a small bias |
| 13481 | * towards upclocking to deliver the frame on time. By only changing |
| 13482 | * the RPS thresholds to sample more regularly and aim for higher |
| 13483 | * clocks we can hopefully deliver low power workloads (like kodi) |
| 13484 | * that are not quite steady state without resorting to forcing |
| 13485 | * maximum clocks following a vblank miss (see do_rps_boost()). |
| 13486 | */ |
| 13487 | if (!intel_state->rps_interactive) { |
| 13488 | intel_rps_mark_interactive(dev_priv, true); |
| 13489 | intel_state->rps_interactive = true; |
| 13490 | } |
| 13491 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 13492 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13493 | } |
| 13494 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13495 | /** |
| 13496 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13497 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13498 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13499 | * |
| 13500 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13501 | * |
| 13502 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13503 | */ |
| 13504 | void |
| 13505 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13506 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13507 | { |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13508 | struct intel_atomic_state *intel_state = |
| 13509 | to_intel_atomic_state(old_state->state); |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13510 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13511 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13512 | if (intel_state->rps_interactive) { |
| 13513 | intel_rps_mark_interactive(dev_priv, false); |
| 13514 | intel_state->rps_interactive = false; |
| 13515 | } |
| 13516 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 13517 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13518 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 13519 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 13520 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13521 | } |
| 13522 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13523 | int |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13524 | skl_max_scale(const struct intel_crtc_state *crtc_state, |
| 13525 | u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13526 | { |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13527 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 13528 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13529 | int max_scale, mult; |
| 13530 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13531 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13532 | if (!crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13533 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13534 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13535 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 13536 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 13537 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 13538 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13539 | max_dotclk *= 2; |
| 13540 | |
| 13541 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13542 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13543 | |
| 13544 | /* |
| 13545 | * skl max scale is lower of: |
| 13546 | * close to 3 but not 3, -1 is for that purpose |
| 13547 | * or |
| 13548 | * cdclk/crtc_clock |
| 13549 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13550 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 13551 | tmpclk1 = (1 << 16) * mult - 1; |
| 13552 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 13553 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13554 | |
| 13555 | return max_scale; |
| 13556 | } |
| 13557 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13558 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13559 | struct drm_crtc_state *old_crtc_state) |
| 13560 | { |
| 13561 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13562 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13563 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13564 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13565 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13566 | struct intel_atomic_state *old_intel_state = |
| 13567 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13568 | struct intel_crtc_state *intel_cstate = |
| 13569 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13570 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13571 | |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13572 | if (!modeset && |
| 13573 | (intel_cstate->base.color_mgmt_changed || |
| 13574 | intel_cstate->update_pipe)) { |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 13575 | intel_color_set_csc(intel_cstate); |
| 13576 | intel_color_load_luts(intel_cstate); |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13577 | } |
| 13578 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13579 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13580 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13581 | |
| 13582 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13583 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13584 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13585 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13586 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13587 | else if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 13588 | skl_detach_scalers(intel_cstate); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13589 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13590 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13591 | if (dev_priv->display.atomic_update_watermarks) |
| 13592 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13593 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13594 | } |
| 13595 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13596 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13597 | struct intel_crtc_state *crtc_state) |
| 13598 | { |
| 13599 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13600 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 13601 | if (!IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13602 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13603 | |
| 13604 | if (crtc_state->has_pch_encoder) { |
| 13605 | enum pipe pch_transcoder = |
| 13606 | intel_crtc_pch_transcoder(crtc); |
| 13607 | |
| 13608 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13609 | } |
| 13610 | } |
| 13611 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13612 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13613 | struct drm_crtc_state *old_crtc_state) |
| 13614 | { |
| 13615 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13616 | struct intel_atomic_state *old_intel_state = |
| 13617 | to_intel_atomic_state(old_crtc_state->state); |
| 13618 | struct intel_crtc_state *new_crtc_state = |
| 13619 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13620 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13621 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13622 | |
| 13623 | if (new_crtc_state->update_pipe && |
| 13624 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13625 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13626 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13627 | } |
| 13628 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13629 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13630 | * intel_plane_destroy - destroy a plane |
| 13631 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13632 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13633 | * Common destruction function for all types of planes (primary, cursor, |
| 13634 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13635 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13636 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13637 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13638 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13639 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13640 | } |
| 13641 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13642 | static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane, |
| 13643 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13644 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13645 | switch (modifier) { |
| 13646 | case DRM_FORMAT_MOD_LINEAR: |
| 13647 | case I915_FORMAT_MOD_X_TILED: |
| 13648 | break; |
| 13649 | default: |
| 13650 | return false; |
| 13651 | } |
| 13652 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13653 | switch (format) { |
| 13654 | case DRM_FORMAT_C8: |
| 13655 | case DRM_FORMAT_RGB565: |
| 13656 | case DRM_FORMAT_XRGB1555: |
| 13657 | case DRM_FORMAT_XRGB8888: |
| 13658 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13659 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13660 | default: |
| 13661 | return false; |
| 13662 | } |
| 13663 | } |
| 13664 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13665 | static bool i965_plane_format_mod_supported(struct drm_plane *_plane, |
| 13666 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13667 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13668 | switch (modifier) { |
| 13669 | case DRM_FORMAT_MOD_LINEAR: |
| 13670 | case I915_FORMAT_MOD_X_TILED: |
| 13671 | break; |
| 13672 | default: |
| 13673 | return false; |
| 13674 | } |
| 13675 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13676 | switch (format) { |
| 13677 | case DRM_FORMAT_C8: |
| 13678 | case DRM_FORMAT_RGB565: |
| 13679 | case DRM_FORMAT_XRGB8888: |
| 13680 | case DRM_FORMAT_XBGR8888: |
| 13681 | case DRM_FORMAT_XRGB2101010: |
| 13682 | case DRM_FORMAT_XBGR2101010: |
| 13683 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13684 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13685 | default: |
| 13686 | return false; |
| 13687 | } |
| 13688 | } |
| 13689 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13690 | static bool intel_cursor_format_mod_supported(struct drm_plane *_plane, |
| 13691 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13692 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13693 | return modifier == DRM_FORMAT_MOD_LINEAR && |
| 13694 | format == DRM_FORMAT_ARGB8888; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13695 | } |
| 13696 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13697 | static const struct drm_plane_funcs i965_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13698 | .update_plane = drm_atomic_helper_update_plane, |
| 13699 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13700 | .destroy = intel_plane_destroy, |
| 13701 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13702 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13703 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13704 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13705 | .format_mod_supported = i965_plane_format_mod_supported, |
| 13706 | }; |
| 13707 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13708 | static const struct drm_plane_funcs i8xx_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13709 | .update_plane = drm_atomic_helper_update_plane, |
| 13710 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13711 | .destroy = intel_plane_destroy, |
| 13712 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13713 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13714 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13715 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13716 | .format_mod_supported = i8xx_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13717 | }; |
| 13718 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13719 | static int |
| 13720 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13721 | struct drm_crtc *crtc, |
| 13722 | struct drm_framebuffer *fb, |
| 13723 | int crtc_x, int crtc_y, |
| 13724 | unsigned int crtc_w, unsigned int crtc_h, |
| 13725 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13726 | uint32_t src_w, uint32_t src_h, |
| 13727 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13728 | { |
| 13729 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13730 | int ret; |
| 13731 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13732 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13733 | struct drm_framebuffer *old_fb; |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13734 | struct intel_crtc_state *crtc_state = |
| 13735 | to_intel_crtc_state(crtc->state); |
| 13736 | struct intel_crtc_state *new_crtc_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13737 | |
| 13738 | /* |
| 13739 | * When crtc is inactive or there is a modeset pending, |
| 13740 | * wait for it to complete in the slowpath |
| 13741 | */ |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13742 | if (!crtc_state->base.active || needs_modeset(&crtc_state->base) || |
| 13743 | crtc_state->update_pipe) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13744 | goto slow; |
| 13745 | |
| 13746 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13747 | /* |
| 13748 | * Don't do an async update if there is an outstanding commit modifying |
| 13749 | * the plane. This prevents our async update's changes from getting |
| 13750 | * overridden by a previous synchronous update's state. |
| 13751 | */ |
| 13752 | if (old_plane_state->commit && |
| 13753 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 13754 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13755 | |
| 13756 | /* |
| 13757 | * If any parameters change that may affect watermarks, |
| 13758 | * take the slowpath. Only changing fb or position should be |
| 13759 | * in the fastpath. |
| 13760 | */ |
| 13761 | if (old_plane_state->crtc != crtc || |
| 13762 | old_plane_state->src_w != src_w || |
| 13763 | old_plane_state->src_h != src_h || |
| 13764 | old_plane_state->crtc_w != crtc_w || |
| 13765 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13766 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13767 | goto slow; |
| 13768 | |
| 13769 | new_plane_state = intel_plane_duplicate_state(plane); |
| 13770 | if (!new_plane_state) |
| 13771 | return -ENOMEM; |
| 13772 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13773 | new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc)); |
| 13774 | if (!new_crtc_state) { |
| 13775 | ret = -ENOMEM; |
| 13776 | goto out_free; |
| 13777 | } |
| 13778 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13779 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 13780 | |
| 13781 | new_plane_state->src_x = src_x; |
| 13782 | new_plane_state->src_y = src_y; |
| 13783 | new_plane_state->src_w = src_w; |
| 13784 | new_plane_state->src_h = src_h; |
| 13785 | new_plane_state->crtc_x = crtc_x; |
| 13786 | new_plane_state->crtc_y = crtc_y; |
| 13787 | new_plane_state->crtc_w = crtc_w; |
| 13788 | new_plane_state->crtc_h = crtc_h; |
| 13789 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13790 | ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state, |
| 13791 | to_intel_plane_state(old_plane_state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13792 | to_intel_plane_state(new_plane_state)); |
| 13793 | if (ret) |
| 13794 | goto out_free; |
| 13795 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13796 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13797 | if (ret) |
| 13798 | goto out_free; |
| 13799 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13800 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 13801 | if (ret) |
| 13802 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13803 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 13804 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13805 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13806 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13807 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 13808 | intel_plane->frontbuffer_bit); |
| 13809 | |
| 13810 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13811 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13812 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13813 | /* |
| 13814 | * We cannot swap crtc_state as it may be in use by an atomic commit or |
| 13815 | * page flip that's running simultaneously. If we swap crtc_state and |
| 13816 | * destroy the old state, we will cause a use-after-free there. |
| 13817 | * |
| 13818 | * Only update active_planes, which is needed for our internal |
| 13819 | * bookkeeping. Either value will do the right thing when updating |
| 13820 | * planes atomically. If the cursor was part of the atomic update then |
| 13821 | * we would have taken the slowpath. |
| 13822 | */ |
| 13823 | crtc_state->active_planes = new_crtc_state->active_planes; |
| 13824 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13825 | if (plane->state->visible) { |
| 13826 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13827 | intel_plane->update_plane(intel_plane, crtc_state, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13828 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13829 | } else { |
| 13830 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 13831 | intel_plane->disable_plane(intel_plane, crtc_state); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13832 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13833 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13834 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13835 | |
| 13836 | out_unlock: |
| 13837 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 13838 | out_free: |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13839 | if (new_crtc_state) |
| 13840 | intel_crtc_destroy_state(crtc, &new_crtc_state->base); |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13841 | if (ret) |
| 13842 | intel_plane_destroy_state(plane, new_plane_state); |
| 13843 | else |
| 13844 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13845 | return ret; |
| 13846 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13847 | slow: |
| 13848 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 13849 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13850 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13851 | } |
| 13852 | |
| 13853 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 13854 | .update_plane = intel_legacy_cursor_update, |
| 13855 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13856 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13857 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13858 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13859 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13860 | .atomic_destroy_state = intel_plane_destroy_state, |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13861 | .format_mod_supported = intel_cursor_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13862 | }; |
| 13863 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13864 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 13865 | enum i9xx_plane_id i9xx_plane) |
| 13866 | { |
| 13867 | if (!HAS_FBC(dev_priv)) |
| 13868 | return false; |
| 13869 | |
| 13870 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 13871 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 13872 | else if (IS_IVYBRIDGE(dev_priv)) |
| 13873 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 13874 | i9xx_plane == PLANE_C; |
| 13875 | else if (INTEL_GEN(dev_priv) >= 4) |
| 13876 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 13877 | else |
| 13878 | return i9xx_plane == PLANE_A; |
| 13879 | } |
| 13880 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13881 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13882 | 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] | 13883 | { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13884 | struct intel_plane *plane; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13885 | const struct drm_plane_funcs *plane_funcs; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13886 | unsigned int supported_rotations; |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13887 | unsigned int possible_crtcs; |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13888 | const u64 *modifiers; |
| 13889 | const u32 *formats; |
| 13890 | int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13891 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13892 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13893 | if (INTEL_GEN(dev_priv) >= 9) |
| 13894 | return skl_universal_plane_create(dev_priv, pipe, |
| 13895 | PLANE_PRIMARY); |
| 13896 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13897 | plane = intel_plane_alloc(); |
| 13898 | if (IS_ERR(plane)) |
| 13899 | return plane; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13900 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13901 | plane->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13902 | /* |
| 13903 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 13904 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 13905 | */ |
| 13906 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13907 | plane->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13908 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13909 | plane->i9xx_plane = (enum i9xx_plane_id) pipe; |
| 13910 | plane->id = PLANE_PRIMARY; |
| 13911 | plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13912 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13913 | plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane); |
| 13914 | if (plane->has_fbc) { |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13915 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 13916 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13917 | fbc->possible_framebuffer_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13918 | } |
| 13919 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13920 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13921 | formats = i965_primary_formats; |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13922 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13923 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13924 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13925 | plane->max_stride = i9xx_plane_max_stride; |
| 13926 | plane->update_plane = i9xx_update_plane; |
| 13927 | plane->disable_plane = i9xx_disable_plane; |
| 13928 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13929 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13930 | |
| 13931 | plane_funcs = &i965_plane_funcs; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13932 | } else { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13933 | formats = i8xx_primary_formats; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13934 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13935 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13936 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13937 | plane->max_stride = i9xx_plane_max_stride; |
| 13938 | plane->update_plane = i9xx_update_plane; |
| 13939 | plane->disable_plane = i9xx_disable_plane; |
| 13940 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13941 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13942 | |
| 13943 | plane_funcs = &i8xx_plane_funcs; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13944 | } |
| 13945 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13946 | possible_crtcs = BIT(pipe); |
| 13947 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13948 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13949 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13950 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13951 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13952 | DRM_PLANE_TYPE_PRIMARY, |
| 13953 | "primary %c", pipe_name(pipe)); |
| 13954 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13955 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13956 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13957 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13958 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13959 | "plane %c", |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13960 | plane_name(plane->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13961 | if (ret) |
| 13962 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13963 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13964 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 13965 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13966 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 13967 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13968 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13969 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13970 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13971 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13972 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13973 | } |
| 13974 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13975 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13976 | drm_plane_create_rotation_property(&plane->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13977 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13978 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13979 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13980 | drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13981 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13982 | return plane; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13983 | |
| 13984 | fail: |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13985 | intel_plane_free(plane); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13986 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13987 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13988 | } |
| 13989 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13990 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13991 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 13992 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13993 | { |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13994 | unsigned int possible_crtcs; |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13995 | struct intel_plane *cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13996 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13997 | |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13998 | cursor = intel_plane_alloc(); |
| 13999 | if (IS_ERR(cursor)) |
| 14000 | return cursor; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14001 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14002 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 14003 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 14004 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 14005 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14006 | |
| 14007 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14008 | cursor->max_stride = i845_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14009 | cursor->update_plane = i845_update_cursor; |
| 14010 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14011 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14012 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14013 | } else { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14014 | cursor->max_stride = i9xx_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14015 | cursor->update_plane = i9xx_update_cursor; |
| 14016 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14017 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14018 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14019 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14020 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 14021 | cursor->cursor.base = ~0; |
| 14022 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 14023 | |
| 14024 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 14025 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14026 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14027 | possible_crtcs = BIT(pipe); |
| 14028 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14029 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14030 | possible_crtcs, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14031 | intel_cursor_formats, |
| 14032 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14033 | cursor_format_modifiers, |
| 14034 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14035 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14036 | if (ret) |
| 14037 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14038 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14039 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14040 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14041 | DRM_MODE_ROTATE_0, |
| 14042 | DRM_MODE_ROTATE_0 | |
| 14043 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14044 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14045 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14046 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14047 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14048 | |
| 14049 | fail: |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14050 | intel_plane_free(cursor); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14051 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14052 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14053 | } |
| 14054 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14055 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 14056 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14057 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14058 | struct intel_crtc_scaler_state *scaler_state = |
| 14059 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14060 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14061 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14062 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 14063 | crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe]; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14064 | if (!crtc->num_scalers) |
| 14065 | return; |
| 14066 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14067 | for (i = 0; i < crtc->num_scalers; i++) { |
| 14068 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 14069 | |
| 14070 | scaler->in_use = 0; |
Maarten Lankhorst | 0aaf29b | 2018-09-21 16:44:37 +0200 | [diff] [blame] | 14071 | scaler->mode = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14072 | } |
| 14073 | |
| 14074 | scaler_state->scaler_id = -1; |
| 14075 | } |
| 14076 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14077 | 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] | 14078 | { |
| 14079 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14080 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14081 | struct intel_plane *primary = NULL; |
| 14082 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14083 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14084 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14085 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14086 | if (!intel_crtc) |
| 14087 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14088 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14089 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14090 | if (!crtc_state) { |
| 14091 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14092 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14093 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14094 | intel_crtc->config = crtc_state; |
| 14095 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14096 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14097 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14098 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14099 | if (IS_ERR(primary)) { |
| 14100 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14101 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14102 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14103 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14104 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14105 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14106 | struct intel_plane *plane; |
| 14107 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14108 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14109 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14110 | ret = PTR_ERR(plane); |
| 14111 | goto fail; |
| 14112 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14113 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14114 | } |
| 14115 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14116 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14117 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14118 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14119 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14120 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14121 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14122 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14123 | 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] | 14124 | &primary->base, &cursor->base, |
| 14125 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 14126 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14127 | if (ret) |
| 14128 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14129 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14130 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14131 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14132 | /* initialize shared scalers */ |
| 14133 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 14134 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 14135 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 14136 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 14137 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 14138 | |
| 14139 | if (INTEL_GEN(dev_priv) < 9) { |
| 14140 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 14141 | |
| 14142 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14143 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 14144 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 14145 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14146 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14147 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14148 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 14149 | intel_color_init(intel_crtc); |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14150 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14151 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14152 | |
| 14153 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14154 | |
| 14155 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14156 | /* |
| 14157 | * drm_mode_config_cleanup() will free up any |
| 14158 | * crtcs/planes already initialized. |
| 14159 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14160 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14161 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14162 | |
| 14163 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14164 | } |
| 14165 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 14166 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 14167 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14168 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14169 | 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] | 14170 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14171 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14172 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 14173 | 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] | 14174 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14175 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14176 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14177 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14178 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14179 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14180 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14181 | } |
| 14182 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14183 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14184 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14185 | struct drm_device *dev = encoder->base.dev; |
| 14186 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14187 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14188 | int entry = 0; |
| 14189 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14190 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14191 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14192 | index_mask |= (1 << entry); |
| 14193 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14194 | entry++; |
| 14195 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14196 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14197 | return index_mask; |
| 14198 | } |
| 14199 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14200 | static bool has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14201 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14202 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14203 | return false; |
| 14204 | |
| 14205 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14206 | return false; |
| 14207 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14208 | 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] | 14209 | return false; |
| 14210 | |
| 14211 | return true; |
| 14212 | } |
| 14213 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14214 | static bool intel_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14215 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14216 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14217 | return false; |
| 14218 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 14219 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14220 | return false; |
| 14221 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14222 | if (IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14223 | return false; |
| 14224 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14225 | if (HAS_PCH_LPT_H(dev_priv) && |
| 14226 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14227 | return false; |
| 14228 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14229 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14230 | if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14231 | return false; |
| 14232 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14233 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14234 | return false; |
| 14235 | |
| 14236 | return true; |
| 14237 | } |
| 14238 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14239 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 14240 | { |
| 14241 | int pps_num; |
| 14242 | int pps_idx; |
| 14243 | |
| 14244 | if (HAS_DDI(dev_priv)) |
| 14245 | return; |
| 14246 | /* |
| 14247 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 14248 | * everywhere where registers can be write protected. |
| 14249 | */ |
| 14250 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14251 | pps_num = 2; |
| 14252 | else |
| 14253 | pps_num = 1; |
| 14254 | |
| 14255 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 14256 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 14257 | |
| 14258 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 14259 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 14260 | } |
| 14261 | } |
| 14262 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14263 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 14264 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 14265 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14266 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 14267 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14268 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 14269 | else |
| 14270 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14271 | |
| 14272 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14273 | } |
| 14274 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14275 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14276 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14277 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14278 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14279 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14280 | intel_pps_init(dev_priv); |
| 14281 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 14282 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | fc0c5a9 | 2018-08-15 21:12:07 +0100 | [diff] [blame] | 14283 | return; |
| 14284 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 14285 | /* |
| 14286 | * intel_edp_init_connector() depends on this completing first, to |
| 14287 | * prevent the registeration of both eDP and LVDS and the incorrect |
| 14288 | * sharing of the PPS. |
| 14289 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14290 | intel_lvds_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14291 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14292 | if (intel_crt_present(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14293 | intel_crt_init(dev_priv); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14294 | |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14295 | if (IS_ICELAKE(dev_priv)) { |
| 14296 | intel_ddi_init(dev_priv, PORT_A); |
| 14297 | intel_ddi_init(dev_priv, PORT_B); |
| 14298 | intel_ddi_init(dev_priv, PORT_C); |
| 14299 | intel_ddi_init(dev_priv, PORT_D); |
| 14300 | intel_ddi_init(dev_priv, PORT_E); |
| 14301 | intel_ddi_init(dev_priv, PORT_F); |
Madhav Chauhan | bf4d57f | 2018-10-30 13:56:23 +0200 | [diff] [blame] | 14302 | icl_dsi_init(dev_priv); |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14303 | } else if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14304 | /* |
| 14305 | * FIXME: Broxton doesn't support port detection via the |
| 14306 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14307 | * detect the ports. |
| 14308 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14309 | intel_ddi_init(dev_priv, PORT_A); |
| 14310 | intel_ddi_init(dev_priv, PORT_B); |
| 14311 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14312 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14313 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14314 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14315 | int found; |
| 14316 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14317 | /* |
| 14318 | * Haswell uses DDI functions to detect digital outputs. |
| 14319 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14320 | * it's there. |
| 14321 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14322 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14323 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14324 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14325 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14326 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14327 | /* 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] | 14328 | * register */ |
| 14329 | found = I915_READ(SFUSE_STRAP); |
| 14330 | |
| 14331 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14332 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14333 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14334 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14335 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14336 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14337 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 14338 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14339 | /* |
| 14340 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14341 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14342 | if (IS_GEN9_BC(dev_priv) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14343 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 14344 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 14345 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14346 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14347 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14348 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14349 | int found; |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14350 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14351 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14352 | if (has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14353 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14354 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14355 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14356 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14357 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14358 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14359 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14360 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14361 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14362 | } |
| 14363 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14364 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14365 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14366 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14367 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14368 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14369 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14370 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14371 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14372 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14373 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14374 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14375 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14376 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 14377 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14378 | /* |
| 14379 | * The DP_DETECTED bit is the latched state of the DDC |
| 14380 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14381 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14382 | * eDP ports may have been muxed to an alternate function. |
| 14383 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14384 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14385 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14386 | * |
| 14387 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 14388 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 14389 | * and VBT for the presence of the port. Additionally we can't |
| 14390 | * trust the port type the VBT declares as we've seen at least |
| 14391 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14392 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14393 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14394 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14395 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14396 | 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] | 14397 | 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] | 14398 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14399 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14400 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14401 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14402 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14403 | 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] | 14404 | 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] | 14405 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14406 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14407 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14408 | /* |
| 14409 | * eDP not supported on port D, |
| 14410 | * so no need to worry about it |
| 14411 | */ |
| 14412 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14413 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14414 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14415 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14416 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14417 | } |
| 14418 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14419 | vlv_dsi_init(dev_priv); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14420 | } else if (!IS_GEN(dev_priv, 2) && !IS_PINEVIEW(dev_priv)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14421 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14422 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14423 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14424 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14425 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14426 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14427 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14428 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14429 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14430 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14431 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14432 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14433 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14434 | |
| 14435 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14436 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14437 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14438 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14439 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14440 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14441 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14442 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14443 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14444 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14445 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14446 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14447 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14448 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14449 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14450 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14451 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14452 | 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] | 14453 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14454 | } else if (IS_GEN(dev_priv, 2)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14455 | intel_dvo_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14456 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 14457 | if (SUPPORTS_TV(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14458 | intel_tv_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14459 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14460 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14461 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14462 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14463 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14464 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14465 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14466 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14467 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14468 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14469 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14470 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14471 | } |
| 14472 | |
| 14473 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14474 | { |
| 14475 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14476 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14477 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14478 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14479 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14480 | i915_gem_object_lock(obj); |
| 14481 | WARN_ON(!obj->framebuffer_references--); |
| 14482 | i915_gem_object_unlock(obj); |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14483 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14484 | i915_gem_object_put(obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14485 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14486 | kfree(intel_fb); |
| 14487 | } |
| 14488 | |
| 14489 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14490 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14491 | unsigned int *handle) |
| 14492 | { |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14493 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14494 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14495 | if (obj->userptr.mm) { |
| 14496 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14497 | return -EINVAL; |
| 14498 | } |
| 14499 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14500 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14501 | } |
| 14502 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14503 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14504 | struct drm_file *file, |
| 14505 | unsigned flags, unsigned color, |
| 14506 | struct drm_clip_rect *clips, |
| 14507 | unsigned num_clips) |
| 14508 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14509 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14510 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14511 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14512 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14513 | |
| 14514 | return 0; |
| 14515 | } |
| 14516 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14517 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14518 | .destroy = intel_user_framebuffer_destroy, |
| 14519 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14520 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14521 | }; |
| 14522 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14523 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14524 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14525 | u32 pixel_format, u64 fb_modifier) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14526 | { |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14527 | struct intel_crtc *crtc; |
| 14528 | struct intel_plane *plane; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14529 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14530 | /* |
| 14531 | * We assume the primary plane for pipe A has |
| 14532 | * the highest stride limits of them all. |
| 14533 | */ |
| 14534 | crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A); |
| 14535 | plane = to_intel_plane(crtc->base.primary); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14536 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14537 | return plane->max_stride(plane, pixel_format, fb_modifier, |
| 14538 | DRM_MODE_ROTATE_0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14539 | } |
| 14540 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14541 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14542 | struct drm_i915_gem_object *obj, |
| 14543 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14544 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14545 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14546 | struct drm_framebuffer *fb = &intel_fb->base; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14547 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14548 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14549 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14550 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14551 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14552 | i915_gem_object_lock(obj); |
| 14553 | obj->framebuffer_references++; |
| 14554 | tiling = i915_gem_object_get_tiling(obj); |
| 14555 | stride = i915_gem_object_get_stride(obj); |
| 14556 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14557 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14558 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14559 | /* |
| 14560 | * If there's a fence, enforce that |
| 14561 | * the fb modifier and tiling mode match. |
| 14562 | */ |
| 14563 | if (tiling != I915_TILING_NONE && |
| 14564 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14565 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14566 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14567 | } |
| 14568 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14569 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14570 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14571 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14572 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14573 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14574 | } |
| 14575 | } |
| 14576 | |
Ville Syrjälä | 17e8fd1 | 2018-10-29 20:34:53 +0200 | [diff] [blame] | 14577 | if (!drm_any_plane_has_format(&dev_priv->drm, |
| 14578 | mode_cmd->pixel_format, |
| 14579 | mode_cmd->modifier[0])) { |
| 14580 | struct drm_format_name_buf format_name; |
| 14581 | |
| 14582 | DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n", |
| 14583 | drm_get_format_name(mode_cmd->pixel_format, |
| 14584 | &format_name), |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14585 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14586 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14587 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14588 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14589 | /* |
| 14590 | * gen2/3 display engine uses the fence if present, |
| 14591 | * so the tiling mode must match the fb modifier exactly. |
| 14592 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14593 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14594 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14595 | 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] | 14596 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14597 | } |
| 14598 | |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14599 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format, |
| 14600 | mode_cmd->modifier[0]); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14601 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14602 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14603 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14604 | "tiled" : "linear", |
| 14605 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14606 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14607 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14608 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14609 | /* |
| 14610 | * If there's a fence, enforce that |
| 14611 | * the fb pitch and fence stride match. |
| 14612 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14613 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14614 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14615 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14616 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14617 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14618 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14619 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14620 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14621 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14622 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14623 | 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] | 14624 | |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14625 | if (fb->format->format == DRM_FORMAT_NV12 && |
| 14626 | (fb->width < SKL_MIN_YUV_420_SRC_W || |
| 14627 | fb->height < SKL_MIN_YUV_420_SRC_H || |
| 14628 | (fb->width % 4) != 0 || (fb->height % 4) != 0)) { |
| 14629 | DRM_DEBUG_KMS("src dimensions not correct for NV12\n"); |
Ville Syrjälä | 3b90946 | 2018-10-29 16:00:31 +0200 | [diff] [blame] | 14630 | goto err; |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14631 | } |
| 14632 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14633 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14634 | u32 stride_alignment; |
| 14635 | |
| 14636 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14637 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14638 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14639 | } |
| 14640 | |
| 14641 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14642 | |
| 14643 | /* |
| 14644 | * Display WA #0531: skl,bxt,kbl,glk |
| 14645 | * |
| 14646 | * Render decompression and plane width > 3840 |
| 14647 | * combined with horizontal panning requires the |
| 14648 | * plane stride to be a multiple of 4. We'll just |
| 14649 | * require the entire fb to accommodate that to avoid |
| 14650 | * potential runtime errors at plane configuration time. |
| 14651 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14652 | if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 && |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 14653 | is_ccs_modifier(fb->modifier)) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14654 | stride_alignment *= 4; |
| 14655 | |
| 14656 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14657 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14658 | i, fb->pitches[i], stride_alignment); |
| 14659 | goto err; |
| 14660 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14661 | |
Daniel Stone | a268bcd | 2018-05-18 15:30:08 +0100 | [diff] [blame] | 14662 | fb->obj[i] = &obj->base; |
| 14663 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14664 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14665 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14666 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14667 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14668 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14669 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14670 | if (ret) { |
| 14671 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14672 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14673 | } |
| 14674 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14675 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14676 | |
| 14677 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14678 | i915_gem_object_lock(obj); |
| 14679 | obj->framebuffer_references--; |
| 14680 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14681 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14682 | } |
| 14683 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14684 | static struct drm_framebuffer * |
| 14685 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14686 | struct drm_file *filp, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14687 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14688 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14689 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14690 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14691 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14692 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14693 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14694 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14695 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14696 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14697 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14698 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14699 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14700 | |
| 14701 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14702 | } |
| 14703 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14704 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14705 | { |
| 14706 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14707 | |
| 14708 | drm_atomic_state_default_release(state); |
| 14709 | |
| 14710 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14711 | |
| 14712 | kfree(state); |
| 14713 | } |
| 14714 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14715 | static enum drm_mode_status |
| 14716 | intel_mode_valid(struct drm_device *dev, |
| 14717 | const struct drm_display_mode *mode) |
| 14718 | { |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14719 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14720 | int hdisplay_max, htotal_max; |
| 14721 | int vdisplay_max, vtotal_max; |
| 14722 | |
Ville Syrjälä | e4dd27a | 2018-05-24 15:54:03 +0300 | [diff] [blame] | 14723 | /* |
| 14724 | * Can't reject DBLSCAN here because Xorg ddxen can add piles |
| 14725 | * of DBLSCAN modes to the output's mode list when they detect |
| 14726 | * the scaling mode property on the connector. And they don't |
| 14727 | * ask the kernel to validate those modes in any way until |
| 14728 | * modeset time at which point the client gets a protocol error. |
| 14729 | * So in order to not upset those clients we silently ignore the |
| 14730 | * DBLSCAN flag on such connectors. For other connectors we will |
| 14731 | * reject modes with the DBLSCAN flag in encoder->compute_config(). |
| 14732 | * And we always reject DBLSCAN modes in connector->mode_valid() |
| 14733 | * as we never want such modes on the connector's mode list. |
| 14734 | */ |
| 14735 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14736 | if (mode->vscan > 1) |
| 14737 | return MODE_NO_VSCAN; |
| 14738 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14739 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 14740 | return MODE_H_ILLEGAL; |
| 14741 | |
| 14742 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 14743 | DRM_MODE_FLAG_NCSYNC | |
| 14744 | DRM_MODE_FLAG_PCSYNC)) |
| 14745 | return MODE_HSYNC; |
| 14746 | |
| 14747 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 14748 | DRM_MODE_FLAG_PIXMUX | |
| 14749 | DRM_MODE_FLAG_CLKDIV2)) |
| 14750 | return MODE_BAD; |
| 14751 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14752 | if (INTEL_GEN(dev_priv) >= 9 || |
| 14753 | IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { |
| 14754 | hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ |
| 14755 | vdisplay_max = 4096; |
| 14756 | htotal_max = 8192; |
| 14757 | vtotal_max = 8192; |
| 14758 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 14759 | hdisplay_max = 4096; |
| 14760 | vdisplay_max = 4096; |
| 14761 | htotal_max = 8192; |
| 14762 | vtotal_max = 8192; |
| 14763 | } else { |
| 14764 | hdisplay_max = 2048; |
| 14765 | vdisplay_max = 2048; |
| 14766 | htotal_max = 4096; |
| 14767 | vtotal_max = 4096; |
| 14768 | } |
| 14769 | |
| 14770 | if (mode->hdisplay > hdisplay_max || |
| 14771 | mode->hsync_start > htotal_max || |
| 14772 | mode->hsync_end > htotal_max || |
| 14773 | mode->htotal > htotal_max) |
| 14774 | return MODE_H_ILLEGAL; |
| 14775 | |
| 14776 | if (mode->vdisplay > vdisplay_max || |
| 14777 | mode->vsync_start > vtotal_max || |
| 14778 | mode->vsync_end > vtotal_max || |
| 14779 | mode->vtotal > vtotal_max) |
| 14780 | return MODE_V_ILLEGAL; |
| 14781 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14782 | return MODE_OK; |
| 14783 | } |
| 14784 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14785 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14786 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 14787 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14788 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14789 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14790 | .atomic_check = intel_atomic_check, |
| 14791 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14792 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14793 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14794 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14795 | }; |
| 14796 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14797 | /** |
| 14798 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14799 | * @dev_priv: device private |
| 14800 | */ |
| 14801 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14802 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 14803 | intel_init_cdclk_hooks(dev_priv); |
| 14804 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14805 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14806 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14807 | dev_priv->display.get_initial_plane_config = |
| 14808 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14809 | dev_priv->display.crtc_compute_clock = |
| 14810 | haswell_crtc_compute_clock; |
| 14811 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14812 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14813 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14814 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14815 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14816 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14817 | dev_priv->display.crtc_compute_clock = |
| 14818 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14819 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14820 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14821 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14822 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14823 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14824 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14825 | dev_priv->display.crtc_compute_clock = |
| 14826 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14827 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14828 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14829 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14830 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14831 | dev_priv->display.get_initial_plane_config = |
| 14832 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14833 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 14834 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14835 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14836 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 14837 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14838 | dev_priv->display.get_initial_plane_config = |
| 14839 | i9xx_get_initial_plane_config; |
| 14840 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14841 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14842 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 14843 | } else if (IS_G4X(dev_priv)) { |
| 14844 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14845 | dev_priv->display.get_initial_plane_config = |
| 14846 | i9xx_get_initial_plane_config; |
| 14847 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 14848 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14849 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 14850 | } else if (IS_PINEVIEW(dev_priv)) { |
| 14851 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14852 | dev_priv->display.get_initial_plane_config = |
| 14853 | i9xx_get_initial_plane_config; |
| 14854 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 14855 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14856 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14857 | } else if (!IS_GEN(dev_priv, 2)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14858 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14859 | dev_priv->display.get_initial_plane_config = |
| 14860 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14861 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14862 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14863 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14864 | } else { |
| 14865 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14866 | dev_priv->display.get_initial_plane_config = |
| 14867 | i9xx_get_initial_plane_config; |
| 14868 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 14869 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14870 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14871 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14872 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14873 | if (IS_GEN(dev_priv, 5)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14874 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14875 | } else if (IS_GEN(dev_priv, 6)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14876 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14877 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14878 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14879 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14880 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14881 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 14882 | } |
| 14883 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 14884 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14885 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 14886 | else |
| 14887 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14888 | } |
| 14889 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14890 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 14891 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14892 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14893 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14894 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14895 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14896 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14897 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14898 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14899 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14900 | sr1 = inb(VGA_SR_DATA); |
| 14901 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14902 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14903 | udelay(300); |
| 14904 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14905 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14906 | POSTING_READ(vga_reg); |
| 14907 | } |
| 14908 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14909 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14910 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14911 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 14912 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 14913 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 14914 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 14915 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14916 | } |
| 14917 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14918 | /* |
| 14919 | * Calculate what we think the watermarks should be for the state we've read |
| 14920 | * out of the hardware and then immediately program those watermarks so that |
| 14921 | * we ensure the hardware settings match our internal state. |
| 14922 | * |
| 14923 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 14924 | * current state (which was constructed during hardware readout) and running it |
| 14925 | * through the atomic check code to calculate new watermark values in the |
| 14926 | * state object. |
| 14927 | */ |
| 14928 | static void sanitize_watermarks(struct drm_device *dev) |
| 14929 | { |
| 14930 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14931 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14932 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14933 | struct drm_crtc *crtc; |
| 14934 | struct drm_crtc_state *cstate; |
| 14935 | struct drm_modeset_acquire_ctx ctx; |
| 14936 | int ret; |
| 14937 | int i; |
| 14938 | |
| 14939 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14940 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14941 | return; |
| 14942 | |
| 14943 | /* |
| 14944 | * We need to hold connection_mutex before calling duplicate_state so |
| 14945 | * that the connector loop is protected. |
| 14946 | */ |
| 14947 | drm_modeset_acquire_init(&ctx, 0); |
| 14948 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14949 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14950 | if (ret == -EDEADLK) { |
| 14951 | drm_modeset_backoff(&ctx); |
| 14952 | goto retry; |
| 14953 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14954 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14955 | } |
| 14956 | |
| 14957 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 14958 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14959 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14960 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14961 | intel_state = to_intel_atomic_state(state); |
| 14962 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14963 | /* |
| 14964 | * Hardware readout is the only time we don't want to calculate |
| 14965 | * intermediate watermarks (since we don't trust the current |
| 14966 | * watermarks). |
| 14967 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 14968 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 14969 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14970 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14971 | ret = intel_atomic_check(dev, state); |
| 14972 | if (ret) { |
| 14973 | /* |
| 14974 | * If we fail here, it means that the hardware appears to be |
| 14975 | * programmed in a way that shouldn't be possible, given our |
| 14976 | * understanding of watermark requirements. This might mean a |
| 14977 | * mistake in the hardware readout code or a mistake in the |
| 14978 | * watermark calculations for a given platform. Raise a WARN |
| 14979 | * so that this is noticeable. |
| 14980 | * |
| 14981 | * If this actually happens, we'll have to just leave the |
| 14982 | * BIOS-programmed watermarks untouched and hope for the best. |
| 14983 | */ |
| 14984 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14985 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14986 | } |
| 14987 | |
| 14988 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 14989 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14990 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 14991 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14992 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14993 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 14994 | |
| 14995 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14996 | } |
| 14997 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14998 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14999 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15000 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15001 | drm_modeset_drop_locks(&ctx); |
| 15002 | drm_modeset_acquire_fini(&ctx); |
| 15003 | } |
| 15004 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15005 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 15006 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15007 | if (IS_GEN(dev_priv, 5)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15008 | u32 fdi_pll_clk = |
| 15009 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 15010 | |
| 15011 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15012 | } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15013 | dev_priv->fdi_pll_freq = 270000; |
| 15014 | } else { |
| 15015 | return; |
| 15016 | } |
| 15017 | |
| 15018 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 15019 | } |
| 15020 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15021 | static int intel_initial_commit(struct drm_device *dev) |
| 15022 | { |
| 15023 | struct drm_atomic_state *state = NULL; |
| 15024 | struct drm_modeset_acquire_ctx ctx; |
| 15025 | struct drm_crtc *crtc; |
| 15026 | struct drm_crtc_state *crtc_state; |
| 15027 | int ret = 0; |
| 15028 | |
| 15029 | state = drm_atomic_state_alloc(dev); |
| 15030 | if (!state) |
| 15031 | return -ENOMEM; |
| 15032 | |
| 15033 | drm_modeset_acquire_init(&ctx, 0); |
| 15034 | |
| 15035 | retry: |
| 15036 | state->acquire_ctx = &ctx; |
| 15037 | |
| 15038 | drm_for_each_crtc(crtc, dev) { |
| 15039 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 15040 | if (IS_ERR(crtc_state)) { |
| 15041 | ret = PTR_ERR(crtc_state); |
| 15042 | goto out; |
| 15043 | } |
| 15044 | |
| 15045 | if (crtc_state->active) { |
| 15046 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 15047 | if (ret) |
| 15048 | goto out; |
Ville Syrjälä | fa6af514 | 2018-11-20 15:54:49 +0200 | [diff] [blame] | 15049 | |
| 15050 | /* |
| 15051 | * FIXME hack to force a LUT update to avoid the |
| 15052 | * plane update forcing the pipe gamma on without |
| 15053 | * having a proper LUT loaded. Remove once we |
| 15054 | * have readout for pipe gamma enable. |
| 15055 | */ |
| 15056 | crtc_state->color_mgmt_changed = true; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15057 | } |
| 15058 | } |
| 15059 | |
| 15060 | ret = drm_atomic_commit(state); |
| 15061 | |
| 15062 | out: |
| 15063 | if (ret == -EDEADLK) { |
| 15064 | drm_atomic_state_clear(state); |
| 15065 | drm_modeset_backoff(&ctx); |
| 15066 | goto retry; |
| 15067 | } |
| 15068 | |
| 15069 | drm_atomic_state_put(state); |
| 15070 | |
| 15071 | drm_modeset_drop_locks(&ctx); |
| 15072 | drm_modeset_acquire_fini(&ctx); |
| 15073 | |
| 15074 | return ret; |
| 15075 | } |
| 15076 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15077 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15078 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15079 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15080 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15081 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15082 | struct intel_crtc *crtc; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15083 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15084 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15085 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 15086 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15087 | drm_mode_config_init(dev); |
| 15088 | |
| 15089 | dev->mode_config.min_width = 0; |
| 15090 | dev->mode_config.min_height = 0; |
| 15091 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15092 | dev->mode_config.preferred_depth = 24; |
| 15093 | dev->mode_config.prefer_shadow = 1; |
| 15094 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15095 | dev->mode_config.allow_fb_modifiers = true; |
| 15096 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15097 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15098 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 15099 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15100 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 15101 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15102 | |
Jani Nikula | 27a981b | 2018-10-17 12:35:39 +0300 | [diff] [blame] | 15103 | intel_init_quirks(dev_priv); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15104 | |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 15105 | intel_fbc_init(dev_priv); |
| 15106 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 15107 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15108 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15109 | /* |
| 15110 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15111 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15112 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15113 | * indicates as much. |
| 15114 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15115 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15116 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15117 | DREF_SSC1_ENABLE); |
| 15118 | |
| 15119 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15120 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15121 | bios_lvds_use_ssc ? "en" : "dis", |
| 15122 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15123 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15124 | } |
| 15125 | } |
| 15126 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15127 | /* maximum framebuffer dimensions */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15128 | if (IS_GEN(dev_priv, 2)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15129 | dev->mode_config.max_width = 2048; |
| 15130 | dev->mode_config.max_height = 2048; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15131 | } else if (IS_GEN(dev_priv, 3)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15132 | dev->mode_config.max_width = 4096; |
| 15133 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15134 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15135 | dev->mode_config.max_width = 8192; |
| 15136 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15137 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15138 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 15139 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 15140 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15141 | dev->mode_config.cursor_height = 1023; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15142 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15143 | dev->mode_config.cursor_width = 64; |
| 15144 | dev->mode_config.cursor_height = 64; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15145 | } else { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15146 | dev->mode_config.cursor_width = 256; |
| 15147 | dev->mode_config.cursor_height = 256; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15148 | } |
| 15149 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 15150 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15151 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15152 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15153 | INTEL_INFO(dev_priv)->num_pipes, |
| 15154 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15155 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15156 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15157 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15158 | if (ret) { |
| 15159 | drm_mode_config_cleanup(dev); |
| 15160 | return ret; |
| 15161 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15162 | } |
| 15163 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15164 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15165 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15166 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 15167 | intel_update_czclk(dev_priv); |
| 15168 | intel_modeset_init_hw(dev); |
| 15169 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15170 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15171 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15172 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15173 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15174 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15175 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15176 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15177 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15178 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15179 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15180 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15181 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15182 | struct intel_initial_plane_config plane_config = {}; |
| 15183 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15184 | if (!crtc->active) |
| 15185 | continue; |
| 15186 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15187 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15188 | * Note that reserving the BIOS fb up front prevents us |
| 15189 | * from stuffing other stolen allocations like the ring |
| 15190 | * on top. This prevents some ugliness at boot time, and |
| 15191 | * can even allow for smooth boot transitions if the BIOS |
| 15192 | * fb is large enough for the active pipe configuration. |
| 15193 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15194 | dev_priv->display.get_initial_plane_config(crtc, |
| 15195 | &plane_config); |
| 15196 | |
| 15197 | /* |
| 15198 | * If the fb is shared between multiple heads, we'll |
| 15199 | * just get the first one. |
| 15200 | */ |
| 15201 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15202 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15203 | |
| 15204 | /* |
| 15205 | * Make sure hardware watermarks really match the state we read out. |
| 15206 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15207 | * since the watermark calculation done here will use pstate->fb. |
| 15208 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15209 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 15210 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15211 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15212 | /* |
| 15213 | * Force all active planes to recompute their states. So that on |
| 15214 | * mode_setcrtc after probe, all the intel_plane_state variables |
| 15215 | * are already calculated and there is no assert_plane warnings |
| 15216 | * during bootup. |
| 15217 | */ |
| 15218 | ret = intel_initial_commit(dev); |
| 15219 | if (ret) |
| 15220 | DRM_DEBUG_KMS("Initial commit in probe failed.\n"); |
| 15221 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15222 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15223 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15224 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15225 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15226 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15227 | 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] | 15228 | /* 640x480@60Hz, ~25175 kHz */ |
| 15229 | struct dpll clock = { |
| 15230 | .m1 = 18, |
| 15231 | .m2 = 7, |
| 15232 | .p1 = 13, |
| 15233 | .p2 = 4, |
| 15234 | .n = 2, |
| 15235 | }; |
| 15236 | u32 dpll, fp; |
| 15237 | int i; |
| 15238 | |
| 15239 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 15240 | |
| 15241 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 15242 | pipe_name(pipe), clock.vco, clock.dot); |
| 15243 | |
| 15244 | fp = i9xx_dpll_compute_fp(&clock); |
| 15245 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 15246 | DPLL_VGA_MODE_DIS | |
| 15247 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 15248 | PLL_P2_DIVIDE_BY_4 | |
| 15249 | PLL_REF_INPUT_DREFCLK | |
| 15250 | DPLL_VCO_ENABLE; |
| 15251 | |
| 15252 | I915_WRITE(FP0(pipe), fp); |
| 15253 | I915_WRITE(FP1(pipe), fp); |
| 15254 | |
| 15255 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15256 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15257 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15258 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15259 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15260 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15261 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15262 | |
| 15263 | /* |
| 15264 | * Apparently we need to have VGA mode enabled prior to changing |
| 15265 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15266 | * dividers, even though the register value does change. |
| 15267 | */ |
| 15268 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15269 | I915_WRITE(DPLL(pipe), dpll); |
| 15270 | |
| 15271 | /* Wait for the clocks to stabilize. */ |
| 15272 | POSTING_READ(DPLL(pipe)); |
| 15273 | udelay(150); |
| 15274 | |
| 15275 | /* The pixel multiplier can only be updated once the |
| 15276 | * DPLL is enabled and the clocks are stable. |
| 15277 | * |
| 15278 | * So write it again. |
| 15279 | */ |
| 15280 | I915_WRITE(DPLL(pipe), dpll); |
| 15281 | |
| 15282 | /* We do this three times for luck */ |
| 15283 | for (i = 0; i < 3 ; i++) { |
| 15284 | I915_WRITE(DPLL(pipe), dpll); |
| 15285 | POSTING_READ(DPLL(pipe)); |
| 15286 | udelay(150); /* wait for warmup */ |
| 15287 | } |
| 15288 | |
| 15289 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15290 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15291 | |
| 15292 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15293 | } |
| 15294 | |
| 15295 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15296 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15297 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15298 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15299 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15300 | pipe_name(pipe)); |
| 15301 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15302 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15303 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15304 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 15305 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE); |
| 15306 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15307 | |
| 15308 | I915_WRITE(PIPECONF(pipe), 0); |
| 15309 | POSTING_READ(PIPECONF(pipe)); |
| 15310 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15311 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15312 | |
| 15313 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15314 | POSTING_READ(DPLL(pipe)); |
| 15315 | } |
| 15316 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15317 | static void |
| 15318 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15319 | { |
| 15320 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15321 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15322 | if (INTEL_GEN(dev_priv) >= 4) |
| 15323 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15324 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15325 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15326 | struct intel_plane *plane = |
| 15327 | to_intel_plane(crtc->base.primary); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15328 | struct intel_crtc *plane_crtc; |
| 15329 | enum pipe pipe; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15330 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15331 | if (!plane->get_hw_state(plane, &pipe)) |
| 15332 | continue; |
| 15333 | |
| 15334 | if (pipe == crtc->pipe) |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15335 | continue; |
| 15336 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15337 | DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", |
| 15338 | plane->base.base.id, plane->base.name); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15339 | |
| 15340 | plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15341 | intel_plane_disable_noatomic(plane_crtc, plane); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15342 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15343 | } |
| 15344 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15345 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15346 | { |
| 15347 | struct drm_device *dev = crtc->base.dev; |
| 15348 | struct intel_encoder *encoder; |
| 15349 | |
| 15350 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15351 | return true; |
| 15352 | |
| 15353 | return false; |
| 15354 | } |
| 15355 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15356 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15357 | { |
| 15358 | struct drm_device *dev = encoder->base.dev; |
| 15359 | struct intel_connector *connector; |
| 15360 | |
| 15361 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15362 | return connector; |
| 15363 | |
| 15364 | return NULL; |
| 15365 | } |
| 15366 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15367 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15368 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15369 | { |
| 15370 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15371 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15372 | } |
| 15373 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15374 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15375 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15376 | { |
| 15377 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15378 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15379 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15380 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15381 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15382 | /* 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] | 15383 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15384 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15385 | |
| 15386 | I915_WRITE(reg, |
| 15387 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15388 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15389 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15390 | if (crtc_state->base.active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15391 | struct intel_plane *plane; |
| 15392 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15393 | /* Disable everything but the primary plane */ |
| 15394 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15395 | const struct intel_plane_state *plane_state = |
| 15396 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15397 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15398 | if (plane_state->base.visible && |
| 15399 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15400 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15401 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15402 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15403 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15404 | /* Adjust the state of the output pipe according to whether we |
| 15405 | * have active connectors/encoders. */ |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15406 | if (crtc_state->base.active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15407 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15408 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15409 | if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15410 | /* |
| 15411 | * We start out with underrun reporting disabled to avoid races. |
| 15412 | * For correct bookkeeping mark this on active crtcs. |
| 15413 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15414 | * Also on gmch platforms we dont have any hardware bits to |
| 15415 | * disable the underrun reporting. Which means we need to start |
| 15416 | * out with underrun reporting disabled also on inactive pipes, |
| 15417 | * since otherwise we'll complain about the garbage we read when |
| 15418 | * e.g. coming up after runtime pm. |
| 15419 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15420 | * No protection against concurrent access is required - at |
| 15421 | * worst a fifo underrun happens which also sets this to false. |
| 15422 | */ |
| 15423 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15424 | /* |
| 15425 | * We track the PCH trancoder underrun reporting state |
| 15426 | * within the crtc. With crtc for pipe A housing the underrun |
| 15427 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15428 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15429 | * and marking underrun reporting as disabled for the non-existing |
| 15430 | * PCH transcoders B and C would prevent enabling the south |
| 15431 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15432 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15433 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15434 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15435 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15436 | } |
| 15437 | |
| 15438 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15439 | { |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15440 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15441 | struct intel_connector *connector; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15442 | |
| 15443 | /* We need to check both for a crtc link (meaning that the |
| 15444 | * encoder is active and trying to read from a pipe) and the |
| 15445 | * pipe itself being active. */ |
| 15446 | bool has_active_crtc = encoder->base.crtc && |
| 15447 | to_intel_crtc(encoder->base.crtc)->active; |
| 15448 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15449 | connector = intel_encoder_find_connector(encoder); |
| 15450 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15451 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15452 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15453 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15454 | |
| 15455 | /* Connector is active, but has no active pipe. This is |
| 15456 | * fallout from our resume register restoring. Disable |
| 15457 | * the encoder manually again. */ |
| 15458 | if (encoder->base.crtc) { |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15459 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
| 15460 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15461 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15462 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15463 | encoder->base.name); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 15464 | if (encoder->disable) |
| 15465 | encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15466 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15467 | encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15468 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15469 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15470 | |
| 15471 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15472 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15473 | * in our code, like the register restore mess on resume. Clamp |
| 15474 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15475 | |
| 15476 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15477 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15478 | } |
Maarten Lankhorst | d6cae4a | 2018-05-16 10:50:38 +0200 | [diff] [blame] | 15479 | |
| 15480 | /* notify opregion of the sanitized encoder state */ |
| 15481 | intel_opregion_notify_encoder(encoder, connector && has_active_crtc); |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15482 | |
| 15483 | if (INTEL_GEN(dev_priv) >= 11) |
| 15484 | icl_sanitize_encoder_pll_mapping(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15485 | } |
| 15486 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15487 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15488 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15489 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15490 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15491 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15492 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15493 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15494 | } |
| 15495 | } |
| 15496 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15497 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15498 | { |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15499 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15500 | * at a very early point in our resume sequence, where the power well |
| 15501 | * structures are not yet restored. Since this function is at a very |
| 15502 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15503 | * level, just check if the power well is enabled instead of trying to |
| 15504 | * follow the "don't touch the power well if we don't need it" policy |
| 15505 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15506 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15507 | return; |
| 15508 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15509 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15510 | |
| 15511 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15512 | } |
| 15513 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15514 | /* FIXME read out full plane state for all planes */ |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15515 | static void readout_plane_state(struct drm_i915_private *dev_priv) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15516 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15517 | struct intel_plane *plane; |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15518 | struct intel_crtc *crtc; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15519 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15520 | for_each_intel_plane(&dev_priv->drm, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15521 | struct intel_plane_state *plane_state = |
| 15522 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15523 | struct intel_crtc_state *crtc_state; |
| 15524 | enum pipe pipe = PIPE_A; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 15525 | bool visible; |
| 15526 | |
| 15527 | visible = plane->get_hw_state(plane, &pipe); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15528 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15529 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15530 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15531 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15532 | intel_set_plane_visible(crtc_state, plane_state, visible); |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15533 | |
| 15534 | DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n", |
| 15535 | plane->base.base.id, plane->base.name, |
| 15536 | enableddisabled(visible), pipe_name(pipe)); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15537 | } |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15538 | |
| 15539 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15540 | struct intel_crtc_state *crtc_state = |
| 15541 | to_intel_crtc_state(crtc->base.state); |
| 15542 | |
| 15543 | fixup_active_planes(crtc_state); |
| 15544 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15545 | } |
| 15546 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15547 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15548 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15549 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15550 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15551 | struct intel_crtc *crtc; |
| 15552 | struct intel_encoder *encoder; |
| 15553 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15554 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15555 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15556 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15557 | dev_priv->active_crtcs = 0; |
| 15558 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15559 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15560 | struct intel_crtc_state *crtc_state = |
| 15561 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15562 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15563 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15564 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15565 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15566 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15567 | crtc_state->base.active = crtc_state->base.enable = |
| 15568 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15569 | |
| 15570 | crtc->base.enabled = crtc_state->base.enable; |
| 15571 | crtc->active = crtc_state->base.active; |
| 15572 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15573 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15574 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15575 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15576 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15577 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15578 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15579 | } |
| 15580 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15581 | readout_plane_state(dev_priv); |
| 15582 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15583 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15584 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15585 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15586 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15587 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15588 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15589 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15590 | struct intel_crtc_state *crtc_state = |
| 15591 | to_intel_crtc_state(crtc->base.state); |
| 15592 | |
| 15593 | if (crtc_state->base.active && |
| 15594 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15595 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15596 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15597 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15598 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15599 | 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] | 15600 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15601 | } |
| 15602 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15603 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15604 | pipe = 0; |
| 15605 | |
| 15606 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15607 | struct intel_crtc_state *crtc_state; |
| 15608 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15609 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15610 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15611 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15612 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15613 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15614 | } else { |
| 15615 | encoder->base.crtc = NULL; |
| 15616 | } |
| 15617 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15618 | 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] | 15619 | encoder->base.base.id, encoder->base.name, |
| 15620 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15621 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15622 | } |
| 15623 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15624 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15625 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15626 | if (connector->get_hw_state(connector)) { |
| 15627 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15628 | |
| 15629 | encoder = connector->encoder; |
| 15630 | connector->base.encoder = &encoder->base; |
| 15631 | |
| 15632 | if (encoder->base.crtc && |
| 15633 | encoder->base.crtc->state->active) { |
| 15634 | /* |
| 15635 | * This has to be done during hardware readout |
| 15636 | * because anything calling .crtc_disable may |
| 15637 | * rely on the connector_mask being accurate. |
| 15638 | */ |
| 15639 | encoder->base.crtc->state->connector_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15640 | drm_connector_mask(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15641 | encoder->base.crtc->state->encoder_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15642 | drm_encoder_mask(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15643 | } |
| 15644 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15645 | } else { |
| 15646 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15647 | connector->base.encoder = NULL; |
| 15648 | } |
| 15649 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15650 | connector->base.base.id, connector->base.name, |
| 15651 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15652 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15653 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15654 | |
| 15655 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15656 | struct intel_crtc_state *crtc_state = |
| 15657 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15658 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15659 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15660 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15661 | if (crtc_state->base.active) { |
| 15662 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15663 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15664 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15665 | 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] | 15666 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15667 | |
| 15668 | /* |
| 15669 | * The initial mode needs to be set in order to keep |
| 15670 | * the atomic core happy. It wants a valid mode if the |
| 15671 | * crtc's enabled, so we do the above call. |
| 15672 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 15673 | * But we don't set all the derived state fully, hence |
| 15674 | * set a flag to indicate that a full recalculation is |
| 15675 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15676 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15677 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15678 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 15679 | intel_crtc_compute_pixel_rate(crtc_state); |
| 15680 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15681 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15682 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15683 | if (WARN_ON(min_cdclk < 0)) |
| 15684 | min_cdclk = 0; |
| 15685 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15686 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 15687 | drm_calc_timestamping_constants(&crtc->base, |
| 15688 | &crtc_state->base.adjusted_mode); |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 15689 | update_scanline_offset(crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15690 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15691 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15692 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 15693 | dev_priv->min_voltage_level[crtc->pipe] = |
| 15694 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15695 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15696 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15697 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15698 | } |
| 15699 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15700 | static void |
| 15701 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 15702 | { |
| 15703 | struct intel_encoder *encoder; |
| 15704 | |
| 15705 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 15706 | u64 get_domains; |
| 15707 | enum intel_display_power_domain domain; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15708 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15709 | |
| 15710 | if (!encoder->get_power_domains) |
| 15711 | continue; |
| 15712 | |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15713 | /* |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15714 | * MST-primary and inactive encoders don't have a crtc state |
| 15715 | * and neither of these require any power domain references. |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15716 | */ |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15717 | if (!encoder->base.crtc) |
| 15718 | continue; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15719 | |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15720 | crtc_state = to_intel_crtc_state(encoder->base.crtc->state); |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15721 | get_domains = encoder->get_power_domains(encoder, crtc_state); |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15722 | for_each_power_domain(domain, get_domains) |
| 15723 | intel_display_power_get(dev_priv, domain); |
| 15724 | } |
| 15725 | } |
| 15726 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15727 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 15728 | { |
| 15729 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 15730 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 15731 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 15732 | DARBF_GATING_DIS); |
| 15733 | |
| 15734 | if (IS_HASWELL(dev_priv)) { |
| 15735 | /* |
| 15736 | * WaRsPkgCStateDisplayPMReq:hsw |
| 15737 | * System hang if this isn't done before disabling all planes! |
| 15738 | */ |
| 15739 | I915_WRITE(CHICKEN_PAR1_1, |
| 15740 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 15741 | } |
| 15742 | } |
| 15743 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 15744 | static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv, |
| 15745 | enum port port, i915_reg_t hdmi_reg) |
| 15746 | { |
| 15747 | u32 val = I915_READ(hdmi_reg); |
| 15748 | |
| 15749 | if (val & SDVO_ENABLE || |
| 15750 | (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A)) |
| 15751 | return; |
| 15752 | |
| 15753 | DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n", |
| 15754 | port_name(port)); |
| 15755 | |
| 15756 | val &= ~SDVO_PIPE_SEL_MASK; |
| 15757 | val |= SDVO_PIPE_SEL(PIPE_A); |
| 15758 | |
| 15759 | I915_WRITE(hdmi_reg, val); |
| 15760 | } |
| 15761 | |
| 15762 | static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv, |
| 15763 | enum port port, i915_reg_t dp_reg) |
| 15764 | { |
| 15765 | u32 val = I915_READ(dp_reg); |
| 15766 | |
| 15767 | if (val & DP_PORT_EN || |
| 15768 | (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A)) |
| 15769 | return; |
| 15770 | |
| 15771 | DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n", |
| 15772 | port_name(port)); |
| 15773 | |
| 15774 | val &= ~DP_PIPE_SEL_MASK; |
| 15775 | val |= DP_PIPE_SEL(PIPE_A); |
| 15776 | |
| 15777 | I915_WRITE(dp_reg, val); |
| 15778 | } |
| 15779 | |
| 15780 | static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv) |
| 15781 | { |
| 15782 | /* |
| 15783 | * The BIOS may select transcoder B on some of the PCH |
| 15784 | * ports even it doesn't enable the port. This would trip |
| 15785 | * assert_pch_dp_disabled() and assert_pch_hdmi_disabled(). |
| 15786 | * Sanitize the transcoder select bits to prevent that. We |
| 15787 | * assume that the BIOS never actually enabled the port, |
| 15788 | * because if it did we'd actually have to toggle the port |
| 15789 | * on and back off to make the transcoder A select stick |
| 15790 | * (see. intel_dp_link_down(), intel_disable_hdmi(), |
| 15791 | * intel_disable_sdvo()). |
| 15792 | */ |
| 15793 | ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B); |
| 15794 | ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C); |
| 15795 | ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D); |
| 15796 | |
| 15797 | /* PCH SDVOB multiplex with HDMIB */ |
| 15798 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB); |
| 15799 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC); |
| 15800 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID); |
| 15801 | } |
| 15802 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15803 | /* Scan out the current hw modeset state, |
| 15804 | * and sanitizes it to the current state |
| 15805 | */ |
| 15806 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15807 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 15808 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15809 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15810 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15811 | struct intel_crtc *crtc; |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15812 | struct intel_crtc_state *crtc_state; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15813 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15814 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15815 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15816 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
| 15817 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15818 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15819 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15820 | |
| 15821 | /* 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] | 15822 | get_encoder_power_domains(dev_priv); |
| 15823 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 15824 | if (HAS_PCH_IBX(dev_priv)) |
| 15825 | ibx_sanitize_pch_ports(dev_priv); |
| 15826 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15827 | /* |
| 15828 | * intel_sanitize_plane_mapping() may need to do vblank |
| 15829 | * waits, so we need vblank interrupts restored beforehand. |
| 15830 | */ |
| 15831 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15832 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15833 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15834 | if (crtc->base.state->active) |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15835 | drm_crtc_vblank_on(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15836 | } |
| 15837 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15838 | intel_sanitize_plane_mapping(dev_priv); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15839 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15840 | for_each_intel_encoder(dev, encoder) |
| 15841 | intel_sanitize_encoder(encoder); |
| 15842 | |
| 15843 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15844 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15845 | intel_sanitize_crtc(crtc, ctx); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15846 | intel_dump_pipe_config(crtc, crtc_state, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15847 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15848 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15849 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15850 | intel_modeset_update_connector_atomic_state(dev); |
| 15851 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15852 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15853 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15854 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15855 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15856 | continue; |
| 15857 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 15858 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 15859 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15860 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15861 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15862 | pll->on = false; |
| 15863 | } |
| 15864 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15865 | if (IS_G4X(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15866 | g4x_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15867 | g4x_wm_sanitize(dev_priv); |
| 15868 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15869 | vlv_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15870 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 15871 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15872 | skl_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15873 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15874 | ilk_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15875 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15876 | |
| 15877 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 15878 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15879 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15880 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15881 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15882 | if (WARN_ON(put_domains)) |
| 15883 | modeset_put_power_domains(dev_priv, put_domains); |
| 15884 | } |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15885 | |
| 15886 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15887 | |
| 15888 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15889 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15890 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15891 | void intel_display_resume(struct drm_device *dev) |
| 15892 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15893 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15894 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15895 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15896 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15897 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15898 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15899 | if (state) |
| 15900 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15901 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15902 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15903 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15904 | while (1) { |
| 15905 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 15906 | if (ret != -EDEADLK) |
| 15907 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15908 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15909 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15910 | } |
| 15911 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15912 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 15913 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15914 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 15915 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15916 | drm_modeset_drop_locks(&ctx); |
| 15917 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15918 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15919 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15920 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 15921 | if (state) |
| 15922 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15923 | } |
| 15924 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15925 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 15926 | { |
| 15927 | struct intel_connector *connector; |
| 15928 | struct drm_connector_list_iter conn_iter; |
| 15929 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 15930 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15931 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15932 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 15933 | if (connector->modeset_retry_work.func) |
| 15934 | cancel_work_sync(&connector->modeset_retry_work); |
Ramalingam C | d3dacc7 | 2018-10-29 15:15:46 +0530 | [diff] [blame] | 15935 | if (connector->hdcp.shim) { |
| 15936 | cancel_delayed_work_sync(&connector->hdcp.check_work); |
| 15937 | cancel_work_sync(&connector->hdcp.prop_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 15938 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15939 | } |
| 15940 | drm_connector_list_iter_end(&conn_iter); |
| 15941 | } |
| 15942 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15943 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15944 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15945 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15946 | |
Chris Wilson | 8bcf9f7 | 2018-07-10 10:44:20 +0100 | [diff] [blame] | 15947 | flush_workqueue(dev_priv->modeset_wq); |
| 15948 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15949 | flush_work(&dev_priv->atomic_helper.free_work); |
| 15950 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 15951 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15952 | /* |
| 15953 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15954 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15955 | * experience fancy races otherwise. |
| 15956 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15957 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15958 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15959 | /* |
| 15960 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15961 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15962 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15963 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15964 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 15965 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 15966 | intel_fbdev_fini(dev_priv); |
| 15967 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15968 | intel_unregister_dsm_handler(); |
| 15969 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 15970 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 15971 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15972 | /* flush any delayed tasks or pending work */ |
| 15973 | flush_scheduled_work(); |
| 15974 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15975 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15976 | |
José Roberto de Souza | 58db08a7 | 2018-11-07 16:16:47 -0800 | [diff] [blame] | 15977 | intel_overlay_cleanup(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15978 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 15979 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15980 | |
| 15981 | destroy_workqueue(dev_priv->modeset_wq); |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 15982 | |
| 15983 | intel_fbc_cleanup_cfb(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15984 | } |
| 15985 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15986 | /* |
| 15987 | * set vga decode state - true == enable VGA decode |
| 15988 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15989 | 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] | 15990 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15991 | 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] | 15992 | u16 gmch_ctrl; |
| 15993 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15994 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15995 | DRM_ERROR("failed to read control word\n"); |
| 15996 | return -EIO; |
| 15997 | } |
| 15998 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15999 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 16000 | return 0; |
| 16001 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16002 | if (state) |
| 16003 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 16004 | else |
| 16005 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16006 | |
| 16007 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 16008 | DRM_ERROR("failed to write control word\n"); |
| 16009 | return -EIO; |
| 16010 | } |
| 16011 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16012 | return 0; |
| 16013 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16014 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16015 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 16016 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16017 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16018 | |
| 16019 | u32 power_well_driver; |
| 16020 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16021 | int num_transcoders; |
| 16022 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16023 | struct intel_cursor_error_state { |
| 16024 | u32 control; |
| 16025 | u32 position; |
| 16026 | u32 base; |
| 16027 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16028 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16029 | |
| 16030 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16031 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16032 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16033 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16034 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16035 | |
| 16036 | struct intel_plane_error_state { |
| 16037 | u32 control; |
| 16038 | u32 stride; |
| 16039 | u32 size; |
| 16040 | u32 pos; |
| 16041 | u32 addr; |
| 16042 | u32 surface; |
| 16043 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16044 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16045 | |
| 16046 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16047 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16048 | enum transcoder cpu_transcoder; |
| 16049 | |
| 16050 | u32 conf; |
| 16051 | |
| 16052 | u32 htotal; |
| 16053 | u32 hblank; |
| 16054 | u32 hsync; |
| 16055 | u32 vtotal; |
| 16056 | u32 vblank; |
| 16057 | u32 vsync; |
| 16058 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16059 | }; |
| 16060 | |
| 16061 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16062 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16063 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16064 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16065 | int transcoders[] = { |
| 16066 | TRANSCODER_A, |
| 16067 | TRANSCODER_B, |
| 16068 | TRANSCODER_C, |
| 16069 | TRANSCODER_EDP, |
| 16070 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16071 | int i; |
| 16072 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 16073 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16074 | return NULL; |
| 16075 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16076 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16077 | if (error == NULL) |
| 16078 | return NULL; |
| 16079 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16080 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 16081 | error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16082 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16083 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16084 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16085 | __intel_display_power_is_enabled(dev_priv, |
| 16086 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16087 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16088 | continue; |
| 16089 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16090 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16091 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16092 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16093 | |
| 16094 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16095 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16096 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16097 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16098 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16099 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16100 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16101 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16102 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16103 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16104 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16105 | } |
| 16106 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16107 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16108 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16109 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16110 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16111 | } |
| 16112 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16113 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16114 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 16115 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16116 | error->num_transcoders++; /* Account for eDP. */ |
| 16117 | |
| 16118 | for (i = 0; i < error->num_transcoders; i++) { |
| 16119 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16120 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16121 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16122 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16123 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16124 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16125 | continue; |
| 16126 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16127 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16128 | |
| 16129 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16130 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16131 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16132 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16133 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16134 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16135 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16136 | } |
| 16137 | |
| 16138 | return error; |
| 16139 | } |
| 16140 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16141 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16142 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16143 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16144 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16145 | struct intel_display_error_state *error) |
| 16146 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 16147 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16148 | int i; |
| 16149 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16150 | if (!error) |
| 16151 | return; |
| 16152 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16153 | 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] | 16154 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16155 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16156 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16157 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16158 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16159 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16160 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16161 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16162 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16163 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16164 | err_printf(m, "Plane [%d]:\n", i); |
| 16165 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16166 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16167 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16168 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16169 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16170 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 16171 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16172 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16173 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16174 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16175 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16176 | } |
| 16177 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16178 | err_printf(m, "Cursor [%d]:\n", i); |
| 16179 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16180 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16181 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16182 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16183 | |
| 16184 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16185 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16186 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16187 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16188 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16189 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16190 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16191 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16192 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16193 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16194 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16195 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16196 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16197 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16198 | |
| 16199 | #endif |