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 | |
Daniel Vetter | 618563e | 2012-04-01 13:38:50 +0200 | [diff] [blame] | 27 | #include <linux/dmi.h> |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 30 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 34 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
Chris Wilson | 5d723d7 | 2016-08-04 16:32:35 +0100 | [diff] [blame] | 37 | #include "intel_frontbuffer.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 38 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 39 | #include "i915_drv.h" |
Chris Wilson | 57822dc | 2017-02-22 11:40:48 +0000 | [diff] [blame] | 40 | #include "i915_gem_clflush.h" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 41 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 42 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 43 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 44 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 45 | #include <drm/drm_dp_helper.h> |
| 46 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 47 | #include <drm/drm_plane_helper.h> |
| 48 | #include <drm/drm_rect.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 | |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 76 | static const uint32_t skl_primary_formats[] = { |
| 77 | DRM_FORMAT_C8, |
| 78 | DRM_FORMAT_RGB565, |
| 79 | DRM_FORMAT_XRGB8888, |
| 80 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 81 | DRM_FORMAT_ARGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 82 | DRM_FORMAT_ABGR8888, |
| 83 | DRM_FORMAT_XRGB2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 84 | DRM_FORMAT_XBGR2101010, |
Kumar, Mahesh | ea916ea | 2015-09-03 16:17:09 +0530 | [diff] [blame] | 85 | DRM_FORMAT_YUYV, |
| 86 | DRM_FORMAT_YVYU, |
| 87 | DRM_FORMAT_UYVY, |
| 88 | DRM_FORMAT_VYUY, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Chandra Konduru | c0b56ab | 2018-05-12 03:03:16 +0530 | [diff] [blame] | 91 | static const uint32_t skl_pri_planar_formats[] = { |
| 92 | DRM_FORMAT_C8, |
| 93 | DRM_FORMAT_RGB565, |
| 94 | DRM_FORMAT_XRGB8888, |
| 95 | DRM_FORMAT_XBGR8888, |
| 96 | DRM_FORMAT_ARGB8888, |
| 97 | DRM_FORMAT_ABGR8888, |
| 98 | DRM_FORMAT_XRGB2101010, |
| 99 | DRM_FORMAT_XBGR2101010, |
| 100 | DRM_FORMAT_YUYV, |
| 101 | DRM_FORMAT_YVYU, |
| 102 | DRM_FORMAT_UYVY, |
| 103 | DRM_FORMAT_VYUY, |
| 104 | DRM_FORMAT_NV12, |
| 105 | }; |
| 106 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 107 | static const uint64_t skl_format_modifiers_noccs[] = { |
| 108 | I915_FORMAT_MOD_Yf_TILED, |
| 109 | I915_FORMAT_MOD_Y_TILED, |
| 110 | I915_FORMAT_MOD_X_TILED, |
| 111 | DRM_FORMAT_MOD_LINEAR, |
| 112 | DRM_FORMAT_MOD_INVALID |
| 113 | }; |
| 114 | |
| 115 | static const uint64_t skl_format_modifiers_ccs[] = { |
| 116 | I915_FORMAT_MOD_Yf_TILED_CCS, |
| 117 | I915_FORMAT_MOD_Y_TILED_CCS, |
| 118 | I915_FORMAT_MOD_Yf_TILED, |
| 119 | I915_FORMAT_MOD_Y_TILED, |
| 120 | I915_FORMAT_MOD_X_TILED, |
| 121 | DRM_FORMAT_MOD_LINEAR, |
| 122 | DRM_FORMAT_MOD_INVALID |
| 123 | }; |
| 124 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 125 | /* Cursor formats */ |
| 126 | static const uint32_t intel_cursor_formats[] = { |
| 127 | DRM_FORMAT_ARGB8888, |
| 128 | }; |
| 129 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 130 | static const uint64_t cursor_format_modifiers[] = { |
| 131 | DRM_FORMAT_MOD_LINEAR, |
| 132 | DRM_FORMAT_MOD_INVALID |
| 133 | }; |
| 134 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 135 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 136 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 137 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 138 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 139 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 140 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
| 141 | struct drm_i915_gem_object *obj, |
| 142 | struct drm_mode_fb_cmd2 *mode_cmd); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 143 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 144 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 145 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 146 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 147 | struct intel_link_m_n *m_n, |
| 148 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 149 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 150 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 151 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 152 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 153 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 154 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 155 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 156 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 157 | 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] | 158 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 159 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 160 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
| 161 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); |
| 162 | static void ironlake_pfit_enable(struct intel_crtc *crtc); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 163 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 164 | struct drm_modeset_acquire_ctx *ctx); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 165 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 166 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 167 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 168 | struct { |
| 169 | int min, max; |
| 170 | } dot, vco, n, m, m1, m2, p, p1; |
| 171 | |
| 172 | struct { |
| 173 | int dot_limit; |
| 174 | int p2_slow, p2_fast; |
| 175 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 176 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 177 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 178 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 179 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 180 | { |
| 181 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 182 | |
| 183 | /* Obtain SKU information */ |
| 184 | mutex_lock(&dev_priv->sb_lock); |
| 185 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 186 | CCK_FUSE_HPLL_FREQ_MASK; |
| 187 | mutex_unlock(&dev_priv->sb_lock); |
| 188 | |
| 189 | return vco_freq[hpll_freq] * 1000; |
| 190 | } |
| 191 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 192 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 193 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 194 | { |
| 195 | u32 val; |
| 196 | int divider; |
| 197 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 198 | mutex_lock(&dev_priv->sb_lock); |
| 199 | val = vlv_cck_read(dev_priv, reg); |
| 200 | mutex_unlock(&dev_priv->sb_lock); |
| 201 | |
| 202 | divider = val & CCK_FREQUENCY_VALUES; |
| 203 | |
| 204 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 205 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 206 | "%s change in progress\n", name); |
| 207 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 208 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 209 | } |
| 210 | |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 211 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 212 | const char *name, u32 reg) |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 213 | { |
| 214 | if (dev_priv->hpll_freq == 0) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 215 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 216 | |
| 217 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 218 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 219 | } |
| 220 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 221 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 222 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 223 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 224 | return; |
| 225 | |
| 226 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 227 | CCK_CZ_CLOCK_CONTROL); |
| 228 | |
| 229 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 230 | } |
| 231 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 232 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 233 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 234 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 235 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 236 | if (HAS_DDI(dev_priv)) |
| 237 | return pipe_config->port_clock; /* SPLL */ |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 238 | else |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 239 | return dev_priv->fdi_pll_freq; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 240 | } |
| 241 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 242 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 243 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 244 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 245 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 246 | .m = { .min = 96, .max = 140 }, |
| 247 | .m1 = { .min = 18, .max = 26 }, |
| 248 | .m2 = { .min = 6, .max = 16 }, |
| 249 | .p = { .min = 4, .max = 128 }, |
| 250 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 251 | .p2 = { .dot_limit = 165000, |
| 252 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 255 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 256 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 257 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 258 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 259 | .m = { .min = 96, .max = 140 }, |
| 260 | .m1 = { .min = 18, .max = 26 }, |
| 261 | .m2 = { .min = 6, .max = 16 }, |
| 262 | .p = { .min = 4, .max = 128 }, |
| 263 | .p1 = { .min = 2, .max = 33 }, |
| 264 | .p2 = { .dot_limit = 165000, |
| 265 | .p2_slow = 4, .p2_fast = 4 }, |
| 266 | }; |
| 267 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 268 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 269 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 270 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 271 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 272 | .m = { .min = 96, .max = 140 }, |
| 273 | .m1 = { .min = 18, .max = 26 }, |
| 274 | .m2 = { .min = 6, .max = 16 }, |
| 275 | .p = { .min = 4, .max = 128 }, |
| 276 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 277 | .p2 = { .dot_limit = 165000, |
| 278 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 279 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 280 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 281 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 282 | .dot = { .min = 20000, .max = 400000 }, |
| 283 | .vco = { .min = 1400000, .max = 2800000 }, |
| 284 | .n = { .min = 1, .max = 6 }, |
| 285 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 286 | .m1 = { .min = 8, .max = 18 }, |
| 287 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 288 | .p = { .min = 5, .max = 80 }, |
| 289 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 290 | .p2 = { .dot_limit = 200000, |
| 291 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 292 | }; |
| 293 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 294 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 295 | .dot = { .min = 20000, .max = 400000 }, |
| 296 | .vco = { .min = 1400000, .max = 2800000 }, |
| 297 | .n = { .min = 1, .max = 6 }, |
| 298 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 299 | .m1 = { .min = 8, .max = 18 }, |
| 300 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 301 | .p = { .min = 7, .max = 98 }, |
| 302 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 303 | .p2 = { .dot_limit = 112000, |
| 304 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 305 | }; |
| 306 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 307 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 308 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 309 | .dot = { .min = 25000, .max = 270000 }, |
| 310 | .vco = { .min = 1750000, .max = 3500000}, |
| 311 | .n = { .min = 1, .max = 4 }, |
| 312 | .m = { .min = 104, .max = 138 }, |
| 313 | .m1 = { .min = 17, .max = 23 }, |
| 314 | .m2 = { .min = 5, .max = 11 }, |
| 315 | .p = { .min = 10, .max = 30 }, |
| 316 | .p1 = { .min = 1, .max = 3}, |
| 317 | .p2 = { .dot_limit = 270000, |
| 318 | .p2_slow = 10, |
| 319 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 320 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 321 | }; |
| 322 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 323 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 324 | .dot = { .min = 22000, .max = 400000 }, |
| 325 | .vco = { .min = 1750000, .max = 3500000}, |
| 326 | .n = { .min = 1, .max = 4 }, |
| 327 | .m = { .min = 104, .max = 138 }, |
| 328 | .m1 = { .min = 16, .max = 23 }, |
| 329 | .m2 = { .min = 5, .max = 11 }, |
| 330 | .p = { .min = 5, .max = 80 }, |
| 331 | .p1 = { .min = 1, .max = 8}, |
| 332 | .p2 = { .dot_limit = 165000, |
| 333 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 334 | }; |
| 335 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 336 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 337 | .dot = { .min = 20000, .max = 115000 }, |
| 338 | .vco = { .min = 1750000, .max = 3500000 }, |
| 339 | .n = { .min = 1, .max = 3 }, |
| 340 | .m = { .min = 104, .max = 138 }, |
| 341 | .m1 = { .min = 17, .max = 23 }, |
| 342 | .m2 = { .min = 5, .max = 11 }, |
| 343 | .p = { .min = 28, .max = 112 }, |
| 344 | .p1 = { .min = 2, .max = 8 }, |
| 345 | .p2 = { .dot_limit = 0, |
| 346 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 347 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 348 | }; |
| 349 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 350 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 351 | .dot = { .min = 80000, .max = 224000 }, |
| 352 | .vco = { .min = 1750000, .max = 3500000 }, |
| 353 | .n = { .min = 1, .max = 3 }, |
| 354 | .m = { .min = 104, .max = 138 }, |
| 355 | .m1 = { .min = 17, .max = 23 }, |
| 356 | .m2 = { .min = 5, .max = 11 }, |
| 357 | .p = { .min = 14, .max = 42 }, |
| 358 | .p1 = { .min = 2, .max = 6 }, |
| 359 | .p2 = { .dot_limit = 0, |
| 360 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 361 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 362 | }; |
| 363 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 364 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 365 | .dot = { .min = 20000, .max = 400000}, |
| 366 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 367 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 368 | .n = { .min = 3, .max = 6 }, |
| 369 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 370 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 371 | .m1 = { .min = 0, .max = 0 }, |
| 372 | .m2 = { .min = 0, .max = 254 }, |
| 373 | .p = { .min = 5, .max = 80 }, |
| 374 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 375 | .p2 = { .dot_limit = 200000, |
| 376 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 377 | }; |
| 378 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 379 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 380 | .dot = { .min = 20000, .max = 400000 }, |
| 381 | .vco = { .min = 1700000, .max = 3500000 }, |
| 382 | .n = { .min = 3, .max = 6 }, |
| 383 | .m = { .min = 2, .max = 256 }, |
| 384 | .m1 = { .min = 0, .max = 0 }, |
| 385 | .m2 = { .min = 0, .max = 254 }, |
| 386 | .p = { .min = 7, .max = 112 }, |
| 387 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 388 | .p2 = { .dot_limit = 112000, |
| 389 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 390 | }; |
| 391 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 392 | /* Ironlake / Sandybridge |
| 393 | * |
| 394 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 395 | * the range value for them is (actual_value - 2). |
| 396 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 397 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 398 | .dot = { .min = 25000, .max = 350000 }, |
| 399 | .vco = { .min = 1760000, .max = 3510000 }, |
| 400 | .n = { .min = 1, .max = 5 }, |
| 401 | .m = { .min = 79, .max = 127 }, |
| 402 | .m1 = { .min = 12, .max = 22 }, |
| 403 | .m2 = { .min = 5, .max = 9 }, |
| 404 | .p = { .min = 5, .max = 80 }, |
| 405 | .p1 = { .min = 1, .max = 8 }, |
| 406 | .p2 = { .dot_limit = 225000, |
| 407 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 408 | }; |
| 409 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 410 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 411 | .dot = { .min = 25000, .max = 350000 }, |
| 412 | .vco = { .min = 1760000, .max = 3510000 }, |
| 413 | .n = { .min = 1, .max = 3 }, |
| 414 | .m = { .min = 79, .max = 118 }, |
| 415 | .m1 = { .min = 12, .max = 22 }, |
| 416 | .m2 = { .min = 5, .max = 9 }, |
| 417 | .p = { .min = 28, .max = 112 }, |
| 418 | .p1 = { .min = 2, .max = 8 }, |
| 419 | .p2 = { .dot_limit = 225000, |
| 420 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 421 | }; |
| 422 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 423 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 424 | .dot = { .min = 25000, .max = 350000 }, |
| 425 | .vco = { .min = 1760000, .max = 3510000 }, |
| 426 | .n = { .min = 1, .max = 3 }, |
| 427 | .m = { .min = 79, .max = 127 }, |
| 428 | .m1 = { .min = 12, .max = 22 }, |
| 429 | .m2 = { .min = 5, .max = 9 }, |
| 430 | .p = { .min = 14, .max = 56 }, |
| 431 | .p1 = { .min = 2, .max = 8 }, |
| 432 | .p2 = { .dot_limit = 225000, |
| 433 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 434 | }; |
| 435 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 436 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 437 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 438 | .dot = { .min = 25000, .max = 350000 }, |
| 439 | .vco = { .min = 1760000, .max = 3510000 }, |
| 440 | .n = { .min = 1, .max = 2 }, |
| 441 | .m = { .min = 79, .max = 126 }, |
| 442 | .m1 = { .min = 12, .max = 22 }, |
| 443 | .m2 = { .min = 5, .max = 9 }, |
| 444 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 445 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 446 | .p2 = { .dot_limit = 225000, |
| 447 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 448 | }; |
| 449 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 450 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 451 | .dot = { .min = 25000, .max = 350000 }, |
| 452 | .vco = { .min = 1760000, .max = 3510000 }, |
| 453 | .n = { .min = 1, .max = 3 }, |
| 454 | .m = { .min = 79, .max = 126 }, |
| 455 | .m1 = { .min = 12, .max = 22 }, |
| 456 | .m2 = { .min = 5, .max = 9 }, |
| 457 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 458 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 459 | .p2 = { .dot_limit = 225000, |
| 460 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 461 | }; |
| 462 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 463 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 464 | /* |
| 465 | * These are the data rate limits (measured in fast clocks) |
| 466 | * since those are the strictest limits we have. The fast |
| 467 | * clock and actual rate limits are more relaxed, so checking |
| 468 | * them would make no difference. |
| 469 | */ |
| 470 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 471 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 472 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 473 | .m1 = { .min = 2, .max = 3 }, |
| 474 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 475 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 476 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 477 | }; |
| 478 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 479 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 480 | /* |
| 481 | * These are the data rate limits (measured in fast clocks) |
| 482 | * since those are the strictest limits we have. The fast |
| 483 | * clock and actual rate limits are more relaxed, so checking |
| 484 | * them would make no difference. |
| 485 | */ |
| 486 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 487 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 488 | .n = { .min = 1, .max = 1 }, |
| 489 | .m1 = { .min = 2, .max = 2 }, |
| 490 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 491 | .p1 = { .min = 2, .max = 4 }, |
| 492 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 493 | }; |
| 494 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 495 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 496 | /* FIXME: find real dot limits */ |
| 497 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 498 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 499 | .n = { .min = 1, .max = 1 }, |
| 500 | .m1 = { .min = 2, .max = 2 }, |
| 501 | /* FIXME: find real m2 limits */ |
| 502 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 503 | .p1 = { .min = 2, .max = 4 }, |
| 504 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 505 | }; |
| 506 | |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 507 | static void |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 508 | skl_wa_528(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 509 | { |
| 510 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
| 511 | return; |
| 512 | |
| 513 | if (enable) |
| 514 | I915_WRITE(CHICKEN_PIPESL_1(pipe), HSW_FBCQ_DIS); |
| 515 | else |
| 516 | I915_WRITE(CHICKEN_PIPESL_1(pipe), 0); |
| 517 | } |
| 518 | |
| 519 | static void |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 520 | skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 521 | { |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 522 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 523 | return; |
| 524 | |
| 525 | if (enable) |
| 526 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 527 | DUPS1_GATING_DIS | DUPS2_GATING_DIS); |
| 528 | else |
| 529 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 530 | I915_READ(CLKGATE_DIS_PSL(pipe)) & |
| 531 | ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); |
| 532 | } |
| 533 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 534 | static bool |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 535 | needs_modeset(const struct drm_crtc_state *state) |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 536 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 537 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 540 | /* |
| 541 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 542 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 543 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 544 | * The helpers' return value is the rate of the clock that is fed to the |
| 545 | * display engine's pipe which can be the above fast dot clock rate or a |
| 546 | * divided-down version of it. |
| 547 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 548 | /* 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] | 549 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 550 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 551 | clock->m = clock->m2 + 2; |
| 552 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 553 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 554 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 555 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 556 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 557 | |
| 558 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 559 | } |
| 560 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 561 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 562 | { |
| 563 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 564 | } |
| 565 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 566 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 567 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 568 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 569 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 570 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 571 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 572 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 573 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 574 | |
| 575 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 578 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 579 | { |
| 580 | clock->m = clock->m1 * clock->m2; |
| 581 | clock->p = clock->p1 * clock->p2; |
| 582 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 583 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 584 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 585 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 586 | |
| 587 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 588 | } |
| 589 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 590 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 591 | { |
| 592 | clock->m = clock->m1 * clock->m2; |
| 593 | clock->p = clock->p1 * clock->p2; |
| 594 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 595 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 596 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 597 | clock->n << 22); |
| 598 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 599 | |
| 600 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 601 | } |
| 602 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 603 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 604 | |
| 605 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 606 | * Returns whether the given set of divisors are valid for a given refclk with |
| 607 | * the given connectors. |
| 608 | */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 609 | 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] | 610 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 611 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 613 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 614 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 615 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 616 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 617 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 618 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 619 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 620 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 621 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 622 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 623 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 624 | if (clock->m1 <= clock->m2) |
| 625 | INTELPllInvalid("m1 <= m2\n"); |
| 626 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 627 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 628 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 629 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 630 | INTELPllInvalid("p out of range\n"); |
| 631 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 632 | INTELPllInvalid("m out of range\n"); |
| 633 | } |
| 634 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 635 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 636 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 637 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 638 | * connector, etc., rather than just a single range. |
| 639 | */ |
| 640 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 641 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 642 | |
| 643 | return true; |
| 644 | } |
| 645 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 646 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 647 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 648 | const struct intel_crtc_state *crtc_state, |
| 649 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 650 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 651 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 652 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 653 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 654 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 655 | * For LVDS just rely on its current settings for dual-channel. |
| 656 | * We haven't figured out how to reliably set up different |
| 657 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 658 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 659 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 660 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 661 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 662 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 663 | } else { |
| 664 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 665 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 666 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 667 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 668 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 669 | } |
| 670 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 671 | /* |
| 672 | * Returns a set of divisors for the desired target clock with the given |
| 673 | * refclk, or FALSE. The returned values represent the clock equation: |
| 674 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 675 | * |
| 676 | * Target and reference clocks are specified in kHz. |
| 677 | * |
| 678 | * If match_clock is provided, then best_clock P divider must match the P |
| 679 | * divider from @match_clock used for LVDS downclocking. |
| 680 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 681 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 682 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 683 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 684 | int target, int refclk, struct dpll *match_clock, |
| 685 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 686 | { |
| 687 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 688 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 689 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 690 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 691 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 692 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 693 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 694 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 695 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 696 | clock.m1++) { |
| 697 | for (clock.m2 = limit->m2.min; |
| 698 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 699 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 700 | break; |
| 701 | for (clock.n = limit->n.min; |
| 702 | clock.n <= limit->n.max; clock.n++) { |
| 703 | for (clock.p1 = limit->p1.min; |
| 704 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 705 | int this_err; |
| 706 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 707 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 708 | if (!intel_PLL_is_valid(to_i915(dev), |
| 709 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 710 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 711 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 712 | if (match_clock && |
| 713 | clock.p != match_clock->p) |
| 714 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 715 | |
| 716 | this_err = abs(clock.dot - target); |
| 717 | if (this_err < err) { |
| 718 | *best_clock = clock; |
| 719 | err = this_err; |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | return (err != target); |
| 727 | } |
| 728 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 729 | /* |
| 730 | * Returns a set of divisors for the desired target clock with the given |
| 731 | * refclk, or FALSE. The returned values represent the clock equation: |
| 732 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 733 | * |
| 734 | * Target and reference clocks are specified in kHz. |
| 735 | * |
| 736 | * If match_clock is provided, then best_clock P divider must match the P |
| 737 | * divider from @match_clock used for LVDS downclocking. |
| 738 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 739 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 740 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 741 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 742 | int target, int refclk, struct dpll *match_clock, |
| 743 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 744 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 745 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 746 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 747 | int err = target; |
| 748 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 749 | memset(best_clock, 0, sizeof(*best_clock)); |
| 750 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 751 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 752 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 753 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 754 | clock.m1++) { |
| 755 | for (clock.m2 = limit->m2.min; |
| 756 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 757 | for (clock.n = limit->n.min; |
| 758 | clock.n <= limit->n.max; clock.n++) { |
| 759 | for (clock.p1 = limit->p1.min; |
| 760 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 761 | int this_err; |
| 762 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 763 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 764 | if (!intel_PLL_is_valid(to_i915(dev), |
| 765 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 766 | &clock)) |
| 767 | continue; |
| 768 | if (match_clock && |
| 769 | clock.p != match_clock->p) |
| 770 | continue; |
| 771 | |
| 772 | this_err = abs(clock.dot - target); |
| 773 | if (this_err < err) { |
| 774 | *best_clock = clock; |
| 775 | err = this_err; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | return (err != target); |
| 783 | } |
| 784 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 785 | /* |
| 786 | * Returns a set of divisors for the desired target clock with the given |
| 787 | * refclk, or FALSE. The returned values represent the clock equation: |
| 788 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 789 | * |
| 790 | * Target and reference clocks are specified in kHz. |
| 791 | * |
| 792 | * If match_clock is provided, then best_clock P divider must match the P |
| 793 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 794 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 795 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 796 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 797 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 798 | int target, int refclk, struct dpll *match_clock, |
| 799 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 800 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 801 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 802 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 803 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 804 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 805 | /* approximately equals target * 0.00585 */ |
| 806 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 807 | |
| 808 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 809 | |
| 810 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 811 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 812 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 813 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 814 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 815 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 816 | for (clock.m1 = limit->m1.max; |
| 817 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 818 | for (clock.m2 = limit->m2.max; |
| 819 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 820 | for (clock.p1 = limit->p1.max; |
| 821 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 822 | int this_err; |
| 823 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 824 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 825 | if (!intel_PLL_is_valid(to_i915(dev), |
| 826 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 827 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 828 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 829 | |
| 830 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 831 | if (this_err < err_most) { |
| 832 | *best_clock = clock; |
| 833 | err_most = this_err; |
| 834 | max_n = clock.n; |
| 835 | found = true; |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 841 | return found; |
| 842 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 843 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 844 | /* |
| 845 | * Check if the calculated PLL configuration is more optimal compared to the |
| 846 | * best configuration and error found so far. Return the calculated error. |
| 847 | */ |
| 848 | 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] | 849 | const struct dpll *calculated_clock, |
| 850 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 851 | unsigned int best_error_ppm, |
| 852 | unsigned int *error_ppm) |
| 853 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 854 | /* |
| 855 | * For CHV ignore the error and consider only the P value. |
| 856 | * Prefer a bigger P value based on HW requirements. |
| 857 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 858 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 859 | *error_ppm = 0; |
| 860 | |
| 861 | return calculated_clock->p > best_clock->p; |
| 862 | } |
| 863 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 864 | if (WARN_ON_ONCE(!target_freq)) |
| 865 | return false; |
| 866 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 867 | *error_ppm = div_u64(1000000ULL * |
| 868 | abs(target_freq - calculated_clock->dot), |
| 869 | target_freq); |
| 870 | /* |
| 871 | * Prefer a better P value over a better (smaller) error if the error |
| 872 | * is small. Ensure this preference for future configurations too by |
| 873 | * setting the error to 0. |
| 874 | */ |
| 875 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 876 | *error_ppm = 0; |
| 877 | |
| 878 | return true; |
| 879 | } |
| 880 | |
| 881 | return *error_ppm + 10 < best_error_ppm; |
| 882 | } |
| 883 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 884 | /* |
| 885 | * Returns a set of divisors for the desired target clock with the given |
| 886 | * refclk, or FALSE. The returned values represent the clock equation: |
| 887 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 888 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 889 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 890 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 891 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 892 | int target, int refclk, struct dpll *match_clock, |
| 893 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 894 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 895 | 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] | 896 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 897 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 898 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 899 | /* min update 19.2 MHz */ |
| 900 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 901 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 902 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 903 | target *= 5; /* fast clock */ |
| 904 | |
| 905 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 906 | |
| 907 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 908 | 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] | 909 | 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] | 910 | 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] | 911 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 912 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 913 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 914 | 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] | 915 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 916 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 917 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 918 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 919 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 920 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 921 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 922 | if (!intel_PLL_is_valid(to_i915(dev), |
| 923 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 924 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 925 | continue; |
| 926 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 927 | if (!vlv_PLL_is_optimal(dev, target, |
| 928 | &clock, |
| 929 | best_clock, |
| 930 | bestppm, &ppm)) |
| 931 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 932 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 933 | *best_clock = clock; |
| 934 | bestppm = ppm; |
| 935 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | } |
| 939 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 940 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 941 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 942 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 943 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 944 | /* |
| 945 | * Returns a set of divisors for the desired target clock with the given |
| 946 | * refclk, or FALSE. The returned values represent the clock equation: |
| 947 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 948 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 949 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 950 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 951 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 952 | int target, int refclk, struct dpll *match_clock, |
| 953 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 954 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 955 | 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] | 956 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 957 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 958 | struct dpll clock; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 959 | uint64_t m2; |
| 960 | int found = false; |
| 961 | |
| 962 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 963 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 964 | |
| 965 | /* |
| 966 | * Based on hardware doc, the n always set to 1, and m1 always |
| 967 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 968 | * revisit this because n may not 1 anymore. |
| 969 | */ |
| 970 | clock.n = 1, clock.m1 = 2; |
| 971 | target *= 5; /* fast clock */ |
| 972 | |
| 973 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 974 | for (clock.p2 = limit->p2.p2_fast; |
| 975 | clock.p2 >= limit->p2.p2_slow; |
| 976 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 977 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 978 | |
| 979 | clock.p = clock.p1 * clock.p2; |
| 980 | |
| 981 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 982 | clock.n) << 22, refclk * clock.m1); |
| 983 | |
| 984 | if (m2 > INT_MAX/clock.m1) |
| 985 | continue; |
| 986 | |
| 987 | clock.m2 = m2; |
| 988 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 989 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 990 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 991 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 992 | continue; |
| 993 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 994 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 995 | best_error_ppm, &error_ppm)) |
| 996 | continue; |
| 997 | |
| 998 | *best_clock = clock; |
| 999 | best_error_ppm = error_ppm; |
| 1000 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | return found; |
| 1005 | } |
| 1006 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1007 | 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] | 1008 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1009 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1010 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 1011 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1012 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1013 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1014 | target_clock, refclk, NULL, best_clock); |
| 1015 | } |
| 1016 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 1017 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1018 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1019 | /* Be paranoid as we can arrive here with only partial |
| 1020 | * state retrieved from the hardware during setup. |
| 1021 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1022 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1023 | * as Haswell has gained clock readout/fastboot support. |
| 1024 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 1025 | * We can ditch the crtc->primary->fb check as soon as we can |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1026 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1027 | * |
| 1028 | * FIXME: The intel_crtc->active here should be switched to |
| 1029 | * crtc->state->active once we have proper CRTC states wired up |
| 1030 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1031 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 1032 | return crtc->active && crtc->base.primary->state->fb && |
| 1033 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1034 | } |
| 1035 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1036 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1037 | enum pipe pipe) |
| 1038 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 1039 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1040 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 1041 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1042 | } |
| 1043 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1044 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
| 1045 | enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1046 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1047 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1048 | u32 line1, line2; |
| 1049 | u32 line_mask; |
| 1050 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1051 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1052 | line_mask = DSL_LINEMASK_GEN2; |
| 1053 | else |
| 1054 | line_mask = DSL_LINEMASK_GEN3; |
| 1055 | |
| 1056 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1057 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1058 | line2 = I915_READ(reg) & line_mask; |
| 1059 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1060 | return line1 != line2; |
| 1061 | } |
| 1062 | |
| 1063 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) |
| 1064 | { |
| 1065 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1066 | enum pipe pipe = crtc->pipe; |
| 1067 | |
| 1068 | /* Wait for the display line to settle/start moving */ |
| 1069 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) |
| 1070 | DRM_ERROR("pipe %c scanline %s wait timed out\n", |
| 1071 | pipe_name(pipe), onoff(state)); |
| 1072 | } |
| 1073 | |
| 1074 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) |
| 1075 | { |
| 1076 | wait_for_pipe_scanline_moving(crtc, false); |
| 1077 | } |
| 1078 | |
| 1079 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) |
| 1080 | { |
| 1081 | wait_for_pipe_scanline_moving(crtc, true); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1082 | } |
| 1083 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1084 | static void |
| 1085 | 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] | 1086 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1087 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1088 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1089 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1090 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1091 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1092 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1093 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1094 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1095 | if (intel_wait_for_register(dev_priv, |
| 1096 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1097 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1098 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1099 | } else { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1100 | intel_wait_for_pipe_scanline_stopped(crtc); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1101 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1104 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1105 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1106 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1107 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1108 | u32 val; |
| 1109 | bool cur_state; |
| 1110 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1111 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1112 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1113 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1114 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1115 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1116 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1117 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1118 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1119 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1120 | { |
| 1121 | u32 val; |
| 1122 | bool cur_state; |
| 1123 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1124 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1125 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1126 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1127 | |
| 1128 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1129 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1130 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1131 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1132 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1133 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1134 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1135 | enum pipe pipe, bool state) |
| 1136 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1137 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1138 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1139 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1140 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1141 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1142 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1143 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1144 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1145 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1146 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1147 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1148 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1149 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1150 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1151 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1152 | } |
| 1153 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1154 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1155 | |
| 1156 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1157 | enum pipe pipe, bool state) |
| 1158 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1159 | u32 val; |
| 1160 | bool cur_state; |
| 1161 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1162 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1163 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1164 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1165 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1166 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1167 | } |
| 1168 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1169 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1170 | |
| 1171 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1172 | enum pipe pipe) |
| 1173 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1174 | u32 val; |
| 1175 | |
| 1176 | /* ILK FDI PLL is always enabled */ |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 1177 | if (IS_GEN5(dev_priv)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1178 | return; |
| 1179 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1180 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1181 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1182 | return; |
| 1183 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1184 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1185 | 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] | 1186 | } |
| 1187 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1188 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1189 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1190 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1191 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1192 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1193 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1194 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1195 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1196 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1197 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1198 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1199 | } |
| 1200 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1201 | 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] | 1202 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1203 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1204 | u32 val; |
| 1205 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1206 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1207 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1208 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1209 | return; |
| 1210 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1211 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1212 | u32 port_sel; |
| 1213 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1214 | pp_reg = PP_CONTROL(0); |
| 1215 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1216 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1217 | if (port_sel == PANEL_PORT_SELECT_LVDS) |
| 1218 | intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1219 | /* XXX: else fix for eDP */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1220 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1221 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1222 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1223 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1224 | } else { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1225 | pp_reg = PP_CONTROL(0); |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1226 | intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | val = I915_READ(pp_reg); |
| 1230 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1231 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1232 | locked = false; |
| 1233 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1234 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1235 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1236 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1239 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1240 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1241 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1242 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1243 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1244 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1245 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1246 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1247 | /* we keep both pipes enabled on 830 */ |
| 1248 | if (IS_I830(dev_priv)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1249 | state = true; |
| 1250 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1251 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1252 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1253 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1254 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1255 | |
| 1256 | intel_display_power_put(dev_priv, power_domain); |
| 1257 | } else { |
| 1258 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1259 | } |
| 1260 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1261 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1262 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1263 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1266 | static void assert_plane(struct intel_plane *plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1267 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1268 | bool cur_state = plane->get_hw_state(plane); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1269 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1270 | I915_STATE_WARN(cur_state != state, |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1271 | "%s assertion failure (expected %s, current %s)\n", |
| 1272 | plane->base.name, onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1273 | } |
| 1274 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1275 | #define assert_plane_enabled(p) assert_plane(p, true) |
| 1276 | #define assert_plane_disabled(p) assert_plane(p, false) |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1277 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1278 | static void assert_planes_disabled(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1279 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1280 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1281 | struct intel_plane *plane; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1282 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1283 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
| 1284 | assert_plane_disabled(plane); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1287 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1288 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1289 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1290 | drm_crtc_vblank_put(crtc); |
| 1291 | } |
| 1292 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1293 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1294 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1295 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1296 | u32 val; |
| 1297 | bool enabled; |
| 1298 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1299 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1300 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1301 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1302 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1303 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1306 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1307 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1308 | { |
| 1309 | if ((val & DP_PORT_EN) == 0) |
| 1310 | return false; |
| 1311 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1312 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1313 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1314 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1315 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1316 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1317 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1318 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1319 | } else { |
| 1320 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1321 | return false; |
| 1322 | } |
| 1323 | return true; |
| 1324 | } |
| 1325 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1326 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1327 | enum pipe pipe, i915_reg_t reg, |
| 1328 | u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1329 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1330 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1331 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1332 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1333 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1334 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1335 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1336 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1337 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | 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] | 1341 | enum pipe pipe, enum port port, |
| 1342 | i915_reg_t hdmi_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1343 | { |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1344 | enum pipe port_pipe; |
| 1345 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1346 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1347 | state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe); |
| 1348 | |
| 1349 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1350 | "PCH HDMI %c enabled on transcoder %c, should be disabled\n", |
| 1351 | port_name(port), pipe_name(pipe)); |
| 1352 | |
| 1353 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1354 | "IBX PCH HDMI %c still using transcoder B\n", |
| 1355 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1359 | enum pipe pipe) |
| 1360 | { |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1361 | enum pipe port_pipe; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1362 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1363 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1364 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1365 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1366 | |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1367 | I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) && |
| 1368 | port_pipe == pipe, |
| 1369 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
| 1370 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1371 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1372 | I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) && |
| 1373 | port_pipe == pipe, |
| 1374 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
| 1375 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1376 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1377 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB); |
| 1378 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC); |
| 1379 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1382 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1383 | const struct intel_crtc_state *pipe_config) |
| 1384 | { |
| 1385 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1386 | enum pipe pipe = crtc->pipe; |
| 1387 | |
| 1388 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1389 | POSTING_READ(DPLL(pipe)); |
| 1390 | udelay(150); |
| 1391 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1392 | if (intel_wait_for_register(dev_priv, |
| 1393 | DPLL(pipe), |
| 1394 | DPLL_LOCK_VLV, |
| 1395 | DPLL_LOCK_VLV, |
| 1396 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1397 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1398 | } |
| 1399 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1400 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1401 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1402 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1403 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1404 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1405 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1406 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1407 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1408 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1409 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1410 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1411 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1412 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1413 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1414 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1415 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1416 | } |
| 1417 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1418 | |
| 1419 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1420 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1421 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1422 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1423 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1424 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1425 | u32 tmp; |
| 1426 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1427 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1428 | |
| 1429 | /* Enable back the 10bit clock to display controller */ |
| 1430 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1431 | tmp |= DPIO_DCLKP_EN; |
| 1432 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1433 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1434 | mutex_unlock(&dev_priv->sb_lock); |
| 1435 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1436 | /* |
| 1437 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1438 | */ |
| 1439 | udelay(1); |
| 1440 | |
| 1441 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1442 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1443 | |
| 1444 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1445 | if (intel_wait_for_register(dev_priv, |
| 1446 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1447 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1448 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1452 | const struct intel_crtc_state *pipe_config) |
| 1453 | { |
| 1454 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1455 | enum pipe pipe = crtc->pipe; |
| 1456 | |
| 1457 | assert_pipe_disabled(dev_priv, pipe); |
| 1458 | |
| 1459 | /* PLL is protected by panel, make sure we can write it */ |
| 1460 | assert_panel_unlocked(dev_priv, pipe); |
| 1461 | |
| 1462 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1463 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1464 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1465 | if (pipe != PIPE_A) { |
| 1466 | /* |
| 1467 | * WaPixelRepeatModeFixForC0:chv |
| 1468 | * |
| 1469 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1470 | * the value from DPLLBMD to either pipe B or C. |
| 1471 | */ |
Ville Syrjälä | dfa311f | 2017-09-13 17:08:54 +0300 | [diff] [blame] | 1472 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1473 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1474 | I915_WRITE(CBR4_VLV, 0); |
| 1475 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1476 | |
| 1477 | /* |
| 1478 | * DPLLB VGA mode also seems to cause problems. |
| 1479 | * We should always have it disabled. |
| 1480 | */ |
| 1481 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1482 | } else { |
| 1483 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1484 | POSTING_READ(DPLL_MD(pipe)); |
| 1485 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1486 | } |
| 1487 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1488 | 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] | 1489 | { |
| 1490 | struct intel_crtc *crtc; |
| 1491 | int count = 0; |
| 1492 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1493 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1494 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1495 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1496 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1497 | |
| 1498 | return count; |
| 1499 | } |
| 1500 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1501 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
| 1502 | const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1503 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1504 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1505 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1506 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1507 | int i; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1508 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1509 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1510 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1511 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1512 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1513 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1514 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1515 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1516 | 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] | 1517 | /* |
| 1518 | * It appears to be important that we don't enable this |
| 1519 | * for the current pipe before otherwise configuring the |
| 1520 | * PLL. No idea how this should be handled if multiple |
| 1521 | * DVO outputs are enabled simultaneosly. |
| 1522 | */ |
| 1523 | dpll |= DPLL_DVO_2X_MODE; |
| 1524 | I915_WRITE(DPLL(!crtc->pipe), |
| 1525 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1526 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1527 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1528 | /* |
| 1529 | * Apparently we need to have VGA mode enabled prior to changing |
| 1530 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1531 | * dividers, even though the register value does change. |
| 1532 | */ |
| 1533 | I915_WRITE(reg, 0); |
| 1534 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1535 | I915_WRITE(reg, dpll); |
| 1536 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1537 | /* Wait for the clocks to stabilize. */ |
| 1538 | POSTING_READ(reg); |
| 1539 | udelay(150); |
| 1540 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1541 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1542 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1543 | crtc_state->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1544 | } else { |
| 1545 | /* The pixel multiplier can only be updated once the |
| 1546 | * DPLL is enabled and the clocks are stable. |
| 1547 | * |
| 1548 | * So write it again. |
| 1549 | */ |
| 1550 | I915_WRITE(reg, dpll); |
| 1551 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1552 | |
| 1553 | /* We do this three times for luck */ |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1554 | for (i = 0; i < 3; i++) { |
| 1555 | I915_WRITE(reg, dpll); |
| 1556 | POSTING_READ(reg); |
| 1557 | udelay(150); /* wait for warmup */ |
| 1558 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1559 | } |
| 1560 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1561 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1562 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1563 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1564 | enum pipe pipe = crtc->pipe; |
| 1565 | |
| 1566 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1567 | if (IS_I830(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1568 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1569 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1570 | I915_WRITE(DPLL(PIPE_B), |
| 1571 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1572 | I915_WRITE(DPLL(PIPE_A), |
| 1573 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1574 | } |
| 1575 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1576 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1577 | if (IS_I830(dev_priv)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1578 | return; |
| 1579 | |
| 1580 | /* Make sure the pipe isn't still relying on us */ |
| 1581 | assert_pipe_disabled(dev_priv, pipe); |
| 1582 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1583 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1584 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1585 | } |
| 1586 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1587 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1588 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1589 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1590 | |
| 1591 | /* Make sure the pipe isn't still relying on us */ |
| 1592 | assert_pipe_disabled(dev_priv, pipe); |
| 1593 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1594 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1595 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1596 | if (pipe != PIPE_A) |
| 1597 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1598 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1599 | I915_WRITE(DPLL(pipe), val); |
| 1600 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1604 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1605 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1606 | u32 val; |
| 1607 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1608 | /* Make sure the pipe isn't still relying on us */ |
| 1609 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1610 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1611 | val = DPLL_SSC_REF_CLK_CHV | |
| 1612 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1613 | if (pipe != PIPE_A) |
| 1614 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1615 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1616 | I915_WRITE(DPLL(pipe), val); |
| 1617 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1618 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1619 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1620 | |
| 1621 | /* Disable 10bit clock to display controller */ |
| 1622 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1623 | val &= ~DPIO_DCLKP_EN; |
| 1624 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1625 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1626 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1629 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1630 | struct intel_digital_port *dport, |
| 1631 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1632 | { |
| 1633 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1634 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1635 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1636 | switch (dport->base.port) { |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1637 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1638 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1639 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1640 | break; |
| 1641 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1642 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1643 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1644 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1645 | break; |
| 1646 | case PORT_D: |
| 1647 | port_mask = DPLL_PORTD_READY_MASK; |
| 1648 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1649 | break; |
| 1650 | default: |
| 1651 | BUG(); |
| 1652 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1653 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1654 | if (intel_wait_for_register(dev_priv, |
| 1655 | dpll_reg, port_mask, expected_mask, |
| 1656 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1657 | 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] | 1658 | port_name(dport->base.port), |
| 1659 | I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1662 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1663 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1664 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 1665 | struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv, |
| 1666 | pipe); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1667 | i915_reg_t reg; |
| 1668 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1669 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1670 | /* Make sure PCH DPLL is enabled */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 1671 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1672 | |
| 1673 | /* FDI must be feeding us bits for PCH ports */ |
| 1674 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1675 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1676 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1677 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1678 | /* Workaround: Set the timing override bit before enabling the |
| 1679 | * pch transcoder. */ |
| 1680 | reg = TRANS_CHICKEN2(pipe); |
| 1681 | val = I915_READ(reg); |
| 1682 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1683 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1684 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1685 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1686 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1687 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1688 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1689 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1690 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1691 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1692 | * Make the BPC in transcoder be consistent with |
| 1693 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1694 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1695 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1696 | val &= ~PIPECONF_BPC_MASK; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1697 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1698 | val |= PIPECONF_8BPC; |
| 1699 | else |
| 1700 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1701 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1702 | |
| 1703 | val &= ~TRANS_INTERLACE_MASK; |
| 1704 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1705 | if (HAS_PCH_IBX(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1706 | intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1707 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1708 | else |
| 1709 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1710 | else |
| 1711 | val |= TRANS_PROGRESSIVE; |
| 1712 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1713 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1714 | if (intel_wait_for_register(dev_priv, |
| 1715 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1716 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1717 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1720 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1721 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1722 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1723 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1724 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1725 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1726 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1727 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1728 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1729 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1730 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1731 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1732 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1733 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1734 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1735 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1736 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1737 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1738 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1739 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1740 | else |
| 1741 | val |= TRANS_PROGRESSIVE; |
| 1742 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1743 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1744 | if (intel_wait_for_register(dev_priv, |
| 1745 | LPT_TRANSCONF, |
| 1746 | TRANS_STATE_ENABLE, |
| 1747 | TRANS_STATE_ENABLE, |
| 1748 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1749 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1750 | } |
| 1751 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1752 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1753 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1754 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1755 | i915_reg_t reg; |
| 1756 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1757 | |
| 1758 | /* FDI relies on the transcoder */ |
| 1759 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1760 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1761 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1762 | /* Ports must be off as well */ |
| 1763 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1764 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1765 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1766 | val = I915_READ(reg); |
| 1767 | val &= ~TRANS_ENABLE; |
| 1768 | I915_WRITE(reg, val); |
| 1769 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1770 | if (intel_wait_for_register(dev_priv, |
| 1771 | reg, TRANS_STATE_ENABLE, 0, |
| 1772 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1773 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1774 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1775 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1776 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1777 | reg = TRANS_CHICKEN2(pipe); |
| 1778 | val = I915_READ(reg); |
| 1779 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1780 | I915_WRITE(reg, val); |
| 1781 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1782 | } |
| 1783 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1784 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1785 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1786 | u32 val; |
| 1787 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1788 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1789 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1790 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1791 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1792 | if (intel_wait_for_register(dev_priv, |
| 1793 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1794 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1795 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1796 | |
| 1797 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1798 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1799 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1800 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1803 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1804 | { |
| 1805 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1806 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1807 | if (HAS_PCH_LPT(dev_priv)) |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1808 | return PIPE_A; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1809 | else |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1810 | return crtc->pipe; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1811 | } |
| 1812 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1813 | 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] | 1814 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1815 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1816 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1817 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [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("enabling pipe %c\n", pipe_name(pipe)); |
| 1823 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1824 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1825 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1826 | /* |
| 1827 | * A pipe without a PLL won't actually be able to drive bits from |
| 1828 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1829 | * need the check. |
| 1830 | */ |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1831 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1832 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1833 | assert_dsi_pll_enabled(dev_priv); |
| 1834 | else |
| 1835 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1836 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1837 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1838 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1839 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1840 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1841 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1842 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1843 | } |
| 1844 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1845 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1846 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1847 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1848 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1849 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1850 | /* we keep both pipes enabled on 830 */ |
| 1851 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1852 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1853 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1854 | |
| 1855 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1856 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1857 | |
| 1858 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1859 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1860 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1861 | * resets to its proper value. That also messes up the frame count |
| 1862 | * when it's derived from the timestamps. So let's wait for the |
| 1863 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1864 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1865 | if (dev_priv->drm.max_vblank_count == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1866 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1867 | } |
| 1868 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1869 | 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] | 1870 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1871 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1872 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1873 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1874 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1875 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1876 | u32 val; |
| 1877 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1878 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1879 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1880 | /* |
| 1881 | * Make sure planes won't keep trying to pump pixels to us, |
| 1882 | * or we might hang the display. |
| 1883 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1884 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1885 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1886 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1887 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1888 | if ((val & PIPECONF_ENABLE) == 0) |
| 1889 | return; |
| 1890 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1891 | /* |
| 1892 | * Double wide has implications for planes |
| 1893 | * so best keep it disabled when not needed. |
| 1894 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1895 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1896 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1897 | |
| 1898 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1899 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1900 | val &= ~PIPECONF_ENABLE; |
| 1901 | |
| 1902 | I915_WRITE(reg, val); |
| 1903 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1904 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1905 | } |
| 1906 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1907 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1908 | { |
| 1909 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 1910 | } |
| 1911 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1912 | static unsigned int |
| 1913 | intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1914 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1915 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 1916 | unsigned int cpp = fb->format->cpp[plane]; |
| 1917 | |
| 1918 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1919 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1920 | return cpp; |
| 1921 | case I915_FORMAT_MOD_X_TILED: |
| 1922 | if (IS_GEN2(dev_priv)) |
| 1923 | return 128; |
| 1924 | else |
| 1925 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1926 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 1927 | if (plane == 1) |
| 1928 | return 128; |
| 1929 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1930 | case I915_FORMAT_MOD_Y_TILED: |
| 1931 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 1932 | return 128; |
| 1933 | else |
| 1934 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1935 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 1936 | if (plane == 1) |
| 1937 | return 128; |
| 1938 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1939 | case I915_FORMAT_MOD_Yf_TILED: |
| 1940 | switch (cpp) { |
| 1941 | case 1: |
| 1942 | return 64; |
| 1943 | case 2: |
| 1944 | case 4: |
| 1945 | return 128; |
| 1946 | case 8: |
| 1947 | case 16: |
| 1948 | return 256; |
| 1949 | default: |
| 1950 | MISSING_CASE(cpp); |
| 1951 | return cpp; |
| 1952 | } |
| 1953 | break; |
| 1954 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1955 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1956 | return cpp; |
| 1957 | } |
| 1958 | } |
| 1959 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1960 | static unsigned int |
| 1961 | intel_tile_height(const struct drm_framebuffer *fb, int plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1962 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1963 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1964 | return 1; |
| 1965 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1966 | return intel_tile_size(to_i915(fb->dev)) / |
| 1967 | intel_tile_width_bytes(fb, plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1970 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1971 | static void intel_tile_dims(const struct drm_framebuffer *fb, int plane, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1972 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1973 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1974 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1975 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane); |
| 1976 | unsigned int cpp = fb->format->cpp[plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1977 | |
| 1978 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1979 | *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] | 1980 | } |
| 1981 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1982 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1983 | intel_fb_align_height(const struct drm_framebuffer *fb, |
| 1984 | int plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1985 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1986 | unsigned int tile_height = intel_tile_height(fb, plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1987 | |
| 1988 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1991 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1992 | { |
| 1993 | unsigned int size = 0; |
| 1994 | int i; |
| 1995 | |
| 1996 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1997 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1998 | |
| 1999 | return size; |
| 2000 | } |
| 2001 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 2002 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2003 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 2004 | const struct drm_framebuffer *fb, |
| 2005 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2006 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 2007 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2008 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 2009 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 2010 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 2014 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 2015 | { |
| 2016 | if (IS_I830(dev_priv)) |
| 2017 | return 16 * 1024; |
| 2018 | else if (IS_I85X(dev_priv)) |
| 2019 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 2020 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 2021 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 2022 | else |
| 2023 | return 4 * 1024; |
| 2024 | } |
| 2025 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2026 | 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] | 2027 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 2028 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2029 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 2030 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2031 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2032 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 2033 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2034 | return 4 * 1024; |
| 2035 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2036 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2037 | } |
| 2038 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2039 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
| 2040 | int plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2041 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2042 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2043 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2044 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2045 | if (plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2046 | return 4096; |
| 2047 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2048 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2049 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2050 | return intel_linear_alignment(dev_priv); |
| 2051 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2052 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2053 | return 256 * 1024; |
| 2054 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2055 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2056 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2057 | case I915_FORMAT_MOD_Y_TILED: |
| 2058 | case I915_FORMAT_MOD_Yf_TILED: |
| 2059 | return 1 * 1024 * 1024; |
| 2060 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2061 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2062 | return 0; |
| 2063 | } |
| 2064 | } |
| 2065 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2066 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2067 | { |
| 2068 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2069 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2070 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2071 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2074 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2075 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
| 2076 | unsigned int rotation, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2077 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2078 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2079 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2080 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2081 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2082 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2083 | struct i915_ggtt_view view; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2084 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2085 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2086 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2087 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2088 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2089 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2090 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2091 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2092 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2093 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2094 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2095 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2096 | * we should always have valid PTE following the scanout preventing |
| 2097 | * the VT-d warning. |
| 2098 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2099 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2100 | alignment = 256 * 1024; |
| 2101 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2102 | /* |
| 2103 | * Global gtt pte registers are special registers which actually forward |
| 2104 | * writes to a chunk of system memory. Which means that there is no risk |
| 2105 | * that the register values disappear as soon as we call |
| 2106 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2107 | * pin/unpin/fence and not more. |
| 2108 | */ |
| 2109 | intel_runtime_pm_get(dev_priv); |
| 2110 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2111 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2112 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2113 | pinctl = 0; |
| 2114 | |
| 2115 | /* Valleyview is definitely limited to scanning out the first |
| 2116 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2117 | * g4x display engine and that all earlier gen are similarly |
| 2118 | * limited. Testing suggests that it is a little more |
| 2119 | * complicated than this. For example, Cherryview appears quite |
| 2120 | * happy to scanout from anywhere within its global aperture. |
| 2121 | */ |
| 2122 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 2123 | pinctl |= PIN_MAPPABLE; |
| 2124 | |
| 2125 | vma = i915_gem_object_pin_to_display_plane(obj, |
| 2126 | alignment, &view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2127 | if (IS_ERR(vma)) |
| 2128 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2129 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2130 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2131 | int ret; |
| 2132 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2133 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2134 | * fence, whereas 965+ only requires a fence if using |
| 2135 | * framebuffer compression. For simplicity, we always, when |
| 2136 | * possible, install a fence as the cost is not that onerous. |
| 2137 | * |
| 2138 | * If we fail to fence the tiled scanout, then either the |
| 2139 | * modeset will reject the change (which is highly unlikely as |
| 2140 | * the affected systems, all but one, do not have unmappable |
| 2141 | * space) or we will not be able to enable full powersaving |
| 2142 | * techniques (also likely not to apply due to various limits |
| 2143 | * FBC and the like impose on the size of the buffer, which |
| 2144 | * presumably we violated anyway with this unmappable buffer). |
| 2145 | * Anyway, it is presumably better to stumble onwards with |
| 2146 | * something and try to run the system in a "less than optimal" |
| 2147 | * mode that matches the user configuration. |
| 2148 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2149 | ret = i915_vma_pin_fence(vma); |
| 2150 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2151 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2152 | vma = ERR_PTR(ret); |
| 2153 | goto err; |
| 2154 | } |
| 2155 | |
| 2156 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2157 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2158 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2159 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2160 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2161 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2162 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2163 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2164 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2165 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2168 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2169 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2170 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2171 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2172 | if (flags & PLANE_HAS_FENCE) |
| 2173 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2174 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2175 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2176 | } |
| 2177 | |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2178 | static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane, |
| 2179 | unsigned int rotation) |
| 2180 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2181 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2182 | return to_intel_framebuffer(fb)->rotated[plane].pitch; |
| 2183 | else |
| 2184 | return fb->pitches[plane]; |
| 2185 | } |
| 2186 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2187 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2188 | * Convert the x/y offsets into a linear offset. |
| 2189 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2190 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2191 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2192 | */ |
| 2193 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2194 | const struct intel_plane_state *state, |
| 2195 | int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2196 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2197 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2198 | unsigned int cpp = fb->format->cpp[plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2199 | unsigned int pitch = fb->pitches[plane]; |
| 2200 | |
| 2201 | return y * pitch + x * cpp; |
| 2202 | } |
| 2203 | |
| 2204 | /* |
| 2205 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2206 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2207 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2208 | */ |
| 2209 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2210 | const struct intel_plane_state *state, |
| 2211 | int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2212 | |
| 2213 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2214 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2215 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2216 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2217 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2218 | *x += intel_fb->rotated[plane].x; |
| 2219 | *y += intel_fb->rotated[plane].y; |
| 2220 | } else { |
| 2221 | *x += intel_fb->normal[plane].x; |
| 2222 | *y += intel_fb->normal[plane].y; |
| 2223 | } |
| 2224 | } |
| 2225 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2226 | static u32 __intel_adjust_tile_offset(int *x, int *y, |
| 2227 | unsigned int tile_width, |
| 2228 | unsigned int tile_height, |
| 2229 | unsigned int tile_size, |
| 2230 | unsigned int pitch_tiles, |
| 2231 | u32 old_offset, |
| 2232 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2233 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2234 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2235 | unsigned int tiles; |
| 2236 | |
| 2237 | WARN_ON(old_offset & (tile_size - 1)); |
| 2238 | WARN_ON(new_offset & (tile_size - 1)); |
| 2239 | WARN_ON(new_offset > old_offset); |
| 2240 | |
| 2241 | tiles = (old_offset - new_offset) / tile_size; |
| 2242 | |
| 2243 | *y += tiles / pitch_tiles * tile_height; |
| 2244 | *x += tiles % pitch_tiles * tile_width; |
| 2245 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2246 | /* minimize x in case it got needlessly big */ |
| 2247 | *y += *x / pitch_pixels * tile_height; |
| 2248 | *x %= pitch_pixels; |
| 2249 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2250 | return new_offset; |
| 2251 | } |
| 2252 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2253 | static u32 _intel_adjust_tile_offset(int *x, int *y, |
| 2254 | const struct drm_framebuffer *fb, int plane, |
| 2255 | unsigned int rotation, |
| 2256 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2257 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2258 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2259 | unsigned int cpp = fb->format->cpp[plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2260 | unsigned int pitch = intel_fb_pitch(fb, plane, rotation); |
| 2261 | |
| 2262 | WARN_ON(new_offset > old_offset); |
| 2263 | |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2264 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2265 | unsigned int tile_size, tile_width, tile_height; |
| 2266 | unsigned int pitch_tiles; |
| 2267 | |
| 2268 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2269 | intel_tile_dims(fb, plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2270 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2271 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2272 | pitch_tiles = pitch / tile_height; |
| 2273 | swap(tile_width, tile_height); |
| 2274 | } else { |
| 2275 | pitch_tiles = pitch / (tile_width * cpp); |
| 2276 | } |
| 2277 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2278 | __intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2279 | tile_size, pitch_tiles, |
| 2280 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2281 | } else { |
| 2282 | old_offset += *y * pitch + *x * cpp; |
| 2283 | |
| 2284 | *y = (old_offset - new_offset) / pitch; |
| 2285 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2286 | } |
| 2287 | |
| 2288 | return new_offset; |
| 2289 | } |
| 2290 | |
| 2291 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2292 | * Adjust the tile offset by moving the difference into |
| 2293 | * the x/y offsets. |
| 2294 | */ |
| 2295 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2296 | const struct intel_plane_state *state, int plane, |
| 2297 | u32 old_offset, u32 new_offset) |
| 2298 | { |
| 2299 | return _intel_adjust_tile_offset(x, y, state->base.fb, plane, |
| 2300 | state->base.rotation, |
| 2301 | old_offset, new_offset); |
| 2302 | } |
| 2303 | |
| 2304 | /* |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2305 | * Computes the linear offset to the base tile and adjusts |
| 2306 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2307 | * |
| 2308 | * In the 90/270 rotated case, x and y are assumed |
| 2309 | * to be already rotated to match the rotated GTT view, and |
| 2310 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2311 | * |
| 2312 | * This function is used when computing the derived information |
| 2313 | * under intel_framebuffer, so using any of that information |
| 2314 | * here is not allowed. Anything under drm_framebuffer can be |
| 2315 | * used. This is why the user has to pass in the pitch since it |
| 2316 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2317 | */ |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2318 | static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv, |
| 2319 | int *x, int *y, |
| 2320 | const struct drm_framebuffer *fb, int plane, |
| 2321 | unsigned int pitch, |
| 2322 | unsigned int rotation, |
| 2323 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2324 | { |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2325 | uint64_t fb_modifier = fb->modifier; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2326 | unsigned int cpp = fb->format->cpp[plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2327 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2328 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2329 | if (alignment) |
| 2330 | alignment--; |
| 2331 | |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2332 | if (fb_modifier != DRM_FORMAT_MOD_LINEAR) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2333 | unsigned int tile_size, tile_width, tile_height; |
| 2334 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2335 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2336 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2337 | intel_tile_dims(fb, plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2338 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2339 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2340 | pitch_tiles = pitch / tile_height; |
| 2341 | swap(tile_width, tile_height); |
| 2342 | } else { |
| 2343 | pitch_tiles = pitch / (tile_width * cpp); |
| 2344 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2345 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2346 | tile_rows = *y / tile_height; |
| 2347 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2348 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2349 | tiles = *x / tile_width; |
| 2350 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2351 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2352 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2353 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2354 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2355 | __intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2356 | tile_size, pitch_tiles, |
| 2357 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2358 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2359 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2360 | offset_aligned = offset & ~alignment; |
| 2361 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2362 | *y = (offset & alignment) / pitch; |
| 2363 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2364 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2365 | |
| 2366 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2367 | } |
| 2368 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2369 | u32 intel_compute_tile_offset(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2370 | const struct intel_plane_state *state, |
| 2371 | int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2372 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2373 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2374 | 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] | 2375 | const struct drm_framebuffer *fb = state->base.fb; |
| 2376 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2377 | int pitch = intel_fb_pitch(fb, plane, rotation); |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2378 | u32 alignment; |
| 2379 | |
| 2380 | if (intel_plane->id == PLANE_CURSOR) |
| 2381 | alignment = intel_cursor_alignment(dev_priv); |
| 2382 | else |
| 2383 | alignment = intel_surf_alignment(fb, plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2384 | |
| 2385 | return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch, |
| 2386 | rotation, alignment); |
| 2387 | } |
| 2388 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2389 | /* Convert the fb->offset[] into x/y offsets */ |
| 2390 | static int intel_fb_offset_to_xy(int *x, int *y, |
| 2391 | const struct drm_framebuffer *fb, int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2392 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2393 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2394 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2395 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
| 2396 | fb->offsets[plane] % intel_tile_size(dev_priv)) |
| 2397 | return -EINVAL; |
| 2398 | |
| 2399 | *x = 0; |
| 2400 | *y = 0; |
| 2401 | |
| 2402 | _intel_adjust_tile_offset(x, y, |
| 2403 | fb, plane, DRM_MODE_ROTATE_0, |
| 2404 | fb->offsets[plane], 0); |
| 2405 | |
| 2406 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2407 | } |
| 2408 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2409 | static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier) |
| 2410 | { |
| 2411 | switch (fb_modifier) { |
| 2412 | case I915_FORMAT_MOD_X_TILED: |
| 2413 | return I915_TILING_X; |
| 2414 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2415 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2416 | return I915_TILING_Y; |
| 2417 | default: |
| 2418 | return I915_TILING_NONE; |
| 2419 | } |
| 2420 | } |
| 2421 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2422 | /* |
| 2423 | * From the Sky Lake PRM: |
| 2424 | * "The Color Control Surface (CCS) contains the compression status of |
| 2425 | * the cache-line pairs. The compression state of the cache-line pair |
| 2426 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2427 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2428 | * cache-line-pairs. CCS is always Y tiled." |
| 2429 | * |
| 2430 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2431 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2432 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2433 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2434 | * main surface. |
| 2435 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2436 | static const struct drm_format_info ccs_formats[] = { |
| 2437 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2438 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2439 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2440 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2441 | }; |
| 2442 | |
| 2443 | static const struct drm_format_info * |
| 2444 | lookup_format_info(const struct drm_format_info formats[], |
| 2445 | int num_formats, u32 format) |
| 2446 | { |
| 2447 | int i; |
| 2448 | |
| 2449 | for (i = 0; i < num_formats; i++) { |
| 2450 | if (formats[i].format == format) |
| 2451 | return &formats[i]; |
| 2452 | } |
| 2453 | |
| 2454 | return NULL; |
| 2455 | } |
| 2456 | |
| 2457 | static const struct drm_format_info * |
| 2458 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2459 | { |
| 2460 | switch (cmd->modifier[0]) { |
| 2461 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2462 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2463 | return lookup_format_info(ccs_formats, |
| 2464 | ARRAY_SIZE(ccs_formats), |
| 2465 | cmd->pixel_format); |
| 2466 | default: |
| 2467 | return NULL; |
| 2468 | } |
| 2469 | } |
| 2470 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2471 | static int |
| 2472 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2473 | struct drm_framebuffer *fb) |
| 2474 | { |
| 2475 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2476 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
| 2477 | u32 gtt_offset_rotated = 0; |
| 2478 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2479 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2480 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2481 | |
| 2482 | for (i = 0; i < num_planes; i++) { |
| 2483 | unsigned int width, height; |
| 2484 | unsigned int cpp, size; |
| 2485 | u32 offset; |
| 2486 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2487 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2488 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2489 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2490 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2491 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2492 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2493 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2494 | if (ret) { |
| 2495 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2496 | i, fb->offsets[i]); |
| 2497 | return ret; |
| 2498 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2499 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2500 | if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2501 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) { |
| 2502 | int hsub = fb->format->hsub; |
| 2503 | int vsub = fb->format->vsub; |
| 2504 | int tile_width, tile_height; |
| 2505 | int main_x, main_y; |
| 2506 | int ccs_x, ccs_y; |
| 2507 | |
| 2508 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2509 | tile_width *= hsub; |
| 2510 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2511 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2512 | ccs_x = (x * hsub) % tile_width; |
| 2513 | ccs_y = (y * vsub) % tile_height; |
| 2514 | main_x = intel_fb->normal[0].x % tile_width; |
| 2515 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2516 | |
| 2517 | /* |
| 2518 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2519 | * x/y offsets must match between CCS and the main surface. |
| 2520 | */ |
| 2521 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2522 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2523 | main_x, main_y, |
| 2524 | ccs_x, ccs_y, |
| 2525 | intel_fb->normal[0].x, |
| 2526 | intel_fb->normal[0].y, |
| 2527 | x, y); |
| 2528 | return -EINVAL; |
| 2529 | } |
| 2530 | } |
| 2531 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2532 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2533 | * The fence (if used) is aligned to the start of the object |
| 2534 | * so having the framebuffer wrap around across the edge of the |
| 2535 | * fenced region doesn't really work. We have no API to configure |
| 2536 | * the fence start offset within the object (nor could we probably |
| 2537 | * on gen2/3). So it's just easier if we just require that the |
| 2538 | * fb layout agrees with the fence layout. We already check that the |
| 2539 | * fb stride matches the fence stride elsewhere. |
| 2540 | */ |
Ville Syrjälä | 2ec4cf4 | 2017-08-24 22:10:50 +0300 | [diff] [blame] | 2541 | if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2542 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2543 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2544 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2545 | return -EINVAL; |
| 2546 | } |
| 2547 | |
| 2548 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2549 | * First pixel of the framebuffer from |
| 2550 | * the start of the normal gtt mapping. |
| 2551 | */ |
| 2552 | intel_fb->normal[i].x = x; |
| 2553 | intel_fb->normal[i].y = y; |
| 2554 | |
| 2555 | offset = _intel_compute_tile_offset(dev_priv, &x, &y, |
Ville Syrjälä | 3ca46c0 | 2017-03-07 21:42:09 +0200 | [diff] [blame] | 2556 | fb, i, fb->pitches[i], |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2557 | DRM_MODE_ROTATE_0, tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2558 | offset /= tile_size; |
| 2559 | |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2560 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2561 | unsigned int tile_width, tile_height; |
| 2562 | unsigned int pitch_tiles; |
| 2563 | struct drm_rect r; |
| 2564 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2565 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2566 | |
| 2567 | rot_info->plane[i].offset = offset; |
| 2568 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2569 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2570 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2571 | |
| 2572 | intel_fb->rotated[i].pitch = |
| 2573 | rot_info->plane[i].height * tile_height; |
| 2574 | |
| 2575 | /* how many tiles does this plane need */ |
| 2576 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2577 | /* |
| 2578 | * If the plane isn't horizontally tile aligned, |
| 2579 | * we need one more tile. |
| 2580 | */ |
| 2581 | if (x != 0) |
| 2582 | size++; |
| 2583 | |
| 2584 | /* rotate the x/y offsets to match the GTT view */ |
| 2585 | r.x1 = x; |
| 2586 | r.y1 = y; |
| 2587 | r.x2 = x + width; |
| 2588 | r.y2 = y + height; |
| 2589 | drm_rect_rotate(&r, |
| 2590 | rot_info->plane[i].width * tile_width, |
| 2591 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2592 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2593 | x = r.x1; |
| 2594 | y = r.y1; |
| 2595 | |
| 2596 | /* rotate the tile dimensions to match the GTT view */ |
| 2597 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2598 | swap(tile_width, tile_height); |
| 2599 | |
| 2600 | /* |
| 2601 | * We only keep the x/y offsets, so push all of the |
| 2602 | * gtt offset into the x/y offsets. |
| 2603 | */ |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2604 | __intel_adjust_tile_offset(&x, &y, |
| 2605 | tile_width, tile_height, |
| 2606 | tile_size, pitch_tiles, |
| 2607 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2608 | |
| 2609 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2610 | |
| 2611 | /* |
| 2612 | * First pixel of the framebuffer from |
| 2613 | * the start of the rotated gtt mapping. |
| 2614 | */ |
| 2615 | intel_fb->rotated[i].x = x; |
| 2616 | intel_fb->rotated[i].y = y; |
| 2617 | } else { |
| 2618 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2619 | x * cpp, tile_size); |
| 2620 | } |
| 2621 | |
| 2622 | /* how many tiles in total needed in the bo */ |
| 2623 | max_size = max(max_size, offset + size); |
| 2624 | } |
| 2625 | |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2626 | if (max_size * tile_size > intel_fb->obj->base.size) { |
| 2627 | DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n", |
| 2628 | max_size * tile_size, intel_fb->obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2629 | return -EINVAL; |
| 2630 | } |
| 2631 | |
| 2632 | return 0; |
| 2633 | } |
| 2634 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2635 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2636 | { |
| 2637 | switch (format) { |
| 2638 | case DISPPLANE_8BPP: |
| 2639 | return DRM_FORMAT_C8; |
| 2640 | case DISPPLANE_BGRX555: |
| 2641 | return DRM_FORMAT_XRGB1555; |
| 2642 | case DISPPLANE_BGRX565: |
| 2643 | return DRM_FORMAT_RGB565; |
| 2644 | default: |
| 2645 | case DISPPLANE_BGRX888: |
| 2646 | return DRM_FORMAT_XRGB8888; |
| 2647 | case DISPPLANE_RGBX888: |
| 2648 | return DRM_FORMAT_XBGR8888; |
| 2649 | case DISPPLANE_BGRX101010: |
| 2650 | return DRM_FORMAT_XRGB2101010; |
| 2651 | case DISPPLANE_RGBX101010: |
| 2652 | return DRM_FORMAT_XBGR2101010; |
| 2653 | } |
| 2654 | } |
| 2655 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2656 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2657 | { |
| 2658 | switch (format) { |
| 2659 | case PLANE_CTL_FORMAT_RGB_565: |
| 2660 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2661 | case PLANE_CTL_FORMAT_NV12: |
| 2662 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2663 | default: |
| 2664 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2665 | if (rgb_order) { |
| 2666 | if (alpha) |
| 2667 | return DRM_FORMAT_ABGR8888; |
| 2668 | else |
| 2669 | return DRM_FORMAT_XBGR8888; |
| 2670 | } else { |
| 2671 | if (alpha) |
| 2672 | return DRM_FORMAT_ARGB8888; |
| 2673 | else |
| 2674 | return DRM_FORMAT_XRGB8888; |
| 2675 | } |
| 2676 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2677 | if (rgb_order) |
| 2678 | return DRM_FORMAT_XBGR2101010; |
| 2679 | else |
| 2680 | return DRM_FORMAT_XRGB2101010; |
| 2681 | } |
| 2682 | } |
| 2683 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2684 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2685 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2686 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2687 | { |
| 2688 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2689 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2690 | struct drm_i915_gem_object *obj = NULL; |
| 2691 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2692 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2693 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2694 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2695 | PAGE_SIZE); |
| 2696 | |
| 2697 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2698 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2699 | if (plane_config->size == 0) |
| 2700 | return false; |
| 2701 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2702 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2703 | * important and we should probably use that space with FBC or other |
| 2704 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2705 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2706 | return false; |
| 2707 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2708 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2709 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2710 | base_aligned, |
| 2711 | base_aligned, |
| 2712 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2713 | mutex_unlock(&dev->struct_mutex); |
| 2714 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2715 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2716 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2717 | if (plane_config->tiling == I915_TILING_X) |
| 2718 | obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2719 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2720 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2721 | mode_cmd.width = fb->width; |
| 2722 | mode_cmd.height = fb->height; |
| 2723 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2724 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2725 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2726 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2727 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2728 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2729 | goto out_unref_obj; |
| 2730 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2731 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2732 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2733 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2734 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2735 | |
| 2736 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2737 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2738 | return false; |
| 2739 | } |
| 2740 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2741 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2742 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2743 | struct intel_plane_state *plane_state, |
| 2744 | bool visible) |
| 2745 | { |
| 2746 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2747 | |
| 2748 | plane_state->base.visible = visible; |
| 2749 | |
| 2750 | /* FIXME pre-g4x don't work like this */ |
| 2751 | if (visible) { |
| 2752 | crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base)); |
| 2753 | crtc_state->active_planes |= BIT(plane->id); |
| 2754 | } else { |
| 2755 | crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base)); |
| 2756 | crtc_state->active_planes &= ~BIT(plane->id); |
| 2757 | } |
| 2758 | |
| 2759 | DRM_DEBUG_KMS("%s active planes 0x%x\n", |
| 2760 | crtc_state->base.crtc->name, |
| 2761 | crtc_state->active_planes); |
| 2762 | } |
| 2763 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2764 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2765 | struct intel_plane *plane) |
| 2766 | { |
| 2767 | struct intel_crtc_state *crtc_state = |
| 2768 | to_intel_crtc_state(crtc->base.state); |
| 2769 | struct intel_plane_state *plane_state = |
| 2770 | to_intel_plane_state(plane->base.state); |
| 2771 | |
| 2772 | intel_set_plane_visible(crtc_state, plane_state, false); |
| 2773 | |
| 2774 | if (plane->id == PLANE_PRIMARY) |
| 2775 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2776 | |
| 2777 | trace_intel_disable_plane(&plane->base, crtc); |
| 2778 | plane->disable_plane(plane, crtc); |
| 2779 | } |
| 2780 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2781 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2782 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2783 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2784 | { |
| 2785 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2786 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2787 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2788 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2789 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2790 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2791 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
| 2792 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2793 | struct intel_plane_state *intel_state = |
| 2794 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2795 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2796 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2797 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2798 | return; |
| 2799 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2800 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2801 | fb = &plane_config->fb->base; |
| 2802 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2803 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2804 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2805 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2806 | |
| 2807 | /* |
| 2808 | * Failed to alloc the obj, check to see if we should share |
| 2809 | * an fb with another CRTC instead |
| 2810 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2811 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2812 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2813 | |
| 2814 | if (c == &intel_crtc->base) |
| 2815 | continue; |
| 2816 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2817 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2818 | continue; |
| 2819 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2820 | state = to_intel_plane_state(c->primary->state); |
| 2821 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2822 | continue; |
| 2823 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2824 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2825 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2826 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2827 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2828 | } |
| 2829 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2830 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2831 | /* |
| 2832 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2833 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2834 | * which will lead to problems later if we don't fix it up. The |
| 2835 | * simplest solution is to just disable the primary plane now and |
| 2836 | * pretend the BIOS never had it enabled. |
| 2837 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2838 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2839 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2840 | return; |
| 2841 | |
| 2842 | valid_fb: |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2843 | mutex_lock(&dev->struct_mutex); |
| 2844 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2845 | intel_pin_and_fence_fb_obj(fb, |
| 2846 | primary->state->rotation, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2847 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2848 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2849 | mutex_unlock(&dev->struct_mutex); |
| 2850 | if (IS_ERR(intel_state->vma)) { |
| 2851 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2852 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2853 | |
| 2854 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2855 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2856 | return; |
| 2857 | } |
| 2858 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2859 | obj = intel_fb_obj(fb); |
| 2860 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2861 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2862 | plane_state->src_x = 0; |
| 2863 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2864 | plane_state->src_w = fb->width << 16; |
| 2865 | plane_state->src_h = fb->height << 16; |
| 2866 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2867 | plane_state->crtc_x = 0; |
| 2868 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2869 | plane_state->crtc_w = fb->width; |
| 2870 | plane_state->crtc_h = fb->height; |
| 2871 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2872 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2873 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2874 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2875 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2876 | dev_priv->preserve_bios_swizzle = true; |
| 2877 | |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2878 | drm_framebuffer_get(fb); |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2879 | primary->fb = primary->state->fb = fb; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2880 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2881 | |
| 2882 | intel_set_plane_visible(to_intel_crtc_state(crtc_state), |
| 2883 | to_intel_plane_state(plane_state), |
| 2884 | true); |
| 2885 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2886 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2887 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2888 | } |
| 2889 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2890 | static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane, |
| 2891 | unsigned int rotation) |
| 2892 | { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2893 | int cpp = fb->format->cpp[plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2894 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2895 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2896 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2897 | case I915_FORMAT_MOD_X_TILED: |
| 2898 | switch (cpp) { |
| 2899 | case 8: |
| 2900 | return 4096; |
| 2901 | case 4: |
| 2902 | case 2: |
| 2903 | case 1: |
| 2904 | return 8192; |
| 2905 | default: |
| 2906 | MISSING_CASE(cpp); |
| 2907 | break; |
| 2908 | } |
| 2909 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2910 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2911 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2912 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2913 | case I915_FORMAT_MOD_Y_TILED: |
| 2914 | case I915_FORMAT_MOD_Yf_TILED: |
| 2915 | switch (cpp) { |
| 2916 | case 8: |
| 2917 | return 2048; |
| 2918 | case 4: |
| 2919 | return 4096; |
| 2920 | case 2: |
| 2921 | case 1: |
| 2922 | return 8192; |
| 2923 | default: |
| 2924 | MISSING_CASE(cpp); |
| 2925 | break; |
| 2926 | } |
| 2927 | break; |
| 2928 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2929 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | return 2048; |
| 2933 | } |
| 2934 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2935 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2936 | int main_x, int main_y, u32 main_offset) |
| 2937 | { |
| 2938 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2939 | int hsub = fb->format->hsub; |
| 2940 | int vsub = fb->format->vsub; |
| 2941 | int aux_x = plane_state->aux.x; |
| 2942 | int aux_y = plane_state->aux.y; |
| 2943 | u32 aux_offset = plane_state->aux.offset; |
| 2944 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2945 | |
| 2946 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2947 | int x, y; |
| 2948 | |
| 2949 | if (aux_x == main_x && aux_y == main_y) |
| 2950 | break; |
| 2951 | |
| 2952 | if (aux_offset == 0) |
| 2953 | break; |
| 2954 | |
| 2955 | x = aux_x / hsub; |
| 2956 | y = aux_y / vsub; |
| 2957 | aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1, |
| 2958 | aux_offset, aux_offset - alignment); |
| 2959 | aux_x = x * hsub + aux_x % hsub; |
| 2960 | aux_y = y * vsub + aux_y % vsub; |
| 2961 | } |
| 2962 | |
| 2963 | if (aux_x != main_x || aux_y != main_y) |
| 2964 | return false; |
| 2965 | |
| 2966 | plane_state->aux.offset = aux_offset; |
| 2967 | plane_state->aux.x = aux_x; |
| 2968 | plane_state->aux.y = aux_y; |
| 2969 | |
| 2970 | return true; |
| 2971 | } |
| 2972 | |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 2973 | static int skl_check_main_surface(const struct intel_crtc_state *crtc_state, |
| 2974 | struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2975 | { |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 2976 | struct drm_i915_private *dev_priv = |
| 2977 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2978 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2979 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2980 | int x = plane_state->base.src.x1 >> 16; |
| 2981 | int y = plane_state->base.src.y1 >> 16; |
| 2982 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 2983 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 2984 | int dst_x = plane_state->base.dst.x1; |
| 2985 | int pipe_src_w = crtc_state->pipe_src_w; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2986 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 2987 | int max_height = 4096; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2988 | u32 alignment, offset, aux_offset = plane_state->aux.offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2989 | |
| 2990 | if (w > max_width || h > max_height) { |
| 2991 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 2992 | w, h, max_width, max_height); |
| 2993 | return -EINVAL; |
| 2994 | } |
| 2995 | |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 2996 | /* |
| 2997 | * Display WA #1175: cnl,glk |
| 2998 | * Planes other than the cursor may cause FIFO underflow and display |
| 2999 | * corruption if starting less than 4 pixels from the right edge of |
| 3000 | * the screen. |
Imre Deak | 394676f | 2018-01-16 13:24:15 +0200 | [diff] [blame] | 3001 | * Besides the above WA fix the similar problem, where planes other |
| 3002 | * than the cursor ending less than 4 pixels from the left edge of the |
| 3003 | * screen may cause FIFO underflow and display corruption. |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 3004 | */ |
| 3005 | if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Imre Deak | 394676f | 2018-01-16 13:24:15 +0200 | [diff] [blame] | 3006 | (dst_x + w < 4 || dst_x > pipe_src_w - 4)) { |
| 3007 | DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n", |
| 3008 | dst_x + w < 4 ? "end" : "start", |
| 3009 | dst_x + w < 4 ? dst_x + w : dst_x, |
| 3010 | 4, pipe_src_w - 4); |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 3011 | return -ERANGE; |
| 3012 | } |
| 3013 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3014 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
| 3015 | offset = intel_compute_tile_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3016 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3017 | |
| 3018 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3019 | * AUX surface offset is specified as the distance from the |
| 3020 | * main surface offset, and it must be non-negative. Make |
| 3021 | * sure that is what we will get. |
| 3022 | */ |
| 3023 | if (offset > aux_offset) |
| 3024 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, |
| 3025 | offset, aux_offset & ~(alignment - 1)); |
| 3026 | |
| 3027 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3028 | * When using an X-tiled surface, the plane blows up |
| 3029 | * if the x offset + width exceed the stride. |
| 3030 | * |
| 3031 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 3032 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3033 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3034 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3035 | |
| 3036 | while ((x + w) * cpp > fb->pitches[0]) { |
| 3037 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3038 | 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] | 3039 | return -EINVAL; |
| 3040 | } |
| 3041 | |
| 3042 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, |
| 3043 | offset, offset - alignment); |
| 3044 | } |
| 3045 | } |
| 3046 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3047 | /* |
| 3048 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3049 | * they match with the main surface x/y offsets. |
| 3050 | */ |
| 3051 | if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 3052 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) { |
| 3053 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3054 | if (offset == 0) |
| 3055 | break; |
| 3056 | |
| 3057 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, |
| 3058 | offset, offset - alignment); |
| 3059 | } |
| 3060 | |
| 3061 | if (x != plane_state->aux.x || y != plane_state->aux.y) { |
| 3062 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3063 | return -EINVAL; |
| 3064 | } |
| 3065 | } |
| 3066 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3067 | plane_state->main.offset = offset; |
| 3068 | plane_state->main.x = x; |
| 3069 | plane_state->main.y = y; |
| 3070 | |
| 3071 | return 0; |
| 3072 | } |
| 3073 | |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 3074 | static int |
| 3075 | skl_check_nv12_surface(const struct intel_crtc_state *crtc_state, |
| 3076 | struct intel_plane_state *plane_state) |
| 3077 | { |
| 3078 | /* Display WA #1106 */ |
| 3079 | if (plane_state->base.rotation != |
| 3080 | (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90) && |
| 3081 | plane_state->base.rotation != DRM_MODE_ROTATE_270) |
| 3082 | return 0; |
| 3083 | |
| 3084 | /* |
| 3085 | * src coordinates are rotated here. |
| 3086 | * We check height but report it as width |
| 3087 | */ |
| 3088 | if (((drm_rect_height(&plane_state->base.src) >> 16) % 4) != 0) { |
| 3089 | DRM_DEBUG_KMS("src width must be multiple " |
| 3090 | "of 4 for rotated NV12\n"); |
| 3091 | return -EINVAL; |
| 3092 | } |
| 3093 | |
| 3094 | return 0; |
| 3095 | } |
| 3096 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3097 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3098 | { |
| 3099 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3100 | unsigned int rotation = plane_state->base.rotation; |
| 3101 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3102 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3103 | int x = plane_state->base.src.x1 >> 17; |
| 3104 | int y = plane_state->base.src.y1 >> 17; |
| 3105 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3106 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3107 | u32 offset; |
| 3108 | |
| 3109 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
| 3110 | offset = intel_compute_tile_offset(&x, &y, plane_state, 1); |
| 3111 | |
| 3112 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3113 | if (w > max_width || h > max_height) { |
| 3114 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3115 | w, h, max_width, max_height); |
| 3116 | return -EINVAL; |
| 3117 | } |
| 3118 | |
| 3119 | plane_state->aux.offset = offset; |
| 3120 | plane_state->aux.x = x; |
| 3121 | plane_state->aux.y = y; |
| 3122 | |
| 3123 | return 0; |
| 3124 | } |
| 3125 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3126 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3127 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3128 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3129 | int src_x = plane_state->base.src.x1 >> 16; |
| 3130 | int src_y = plane_state->base.src.y1 >> 16; |
| 3131 | int hsub = fb->format->hsub; |
| 3132 | int vsub = fb->format->vsub; |
| 3133 | int x = src_x / hsub; |
| 3134 | int y = src_y / vsub; |
| 3135 | u32 offset; |
| 3136 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3137 | if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) { |
| 3138 | DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n", |
| 3139 | plane_state->base.rotation); |
| 3140 | return -EINVAL; |
| 3141 | } |
| 3142 | |
| 3143 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
| 3144 | offset = intel_compute_tile_offset(&x, &y, plane_state, 1); |
| 3145 | |
| 3146 | plane_state->aux.offset = offset; |
| 3147 | plane_state->aux.x = x * hsub + src_x % hsub; |
| 3148 | plane_state->aux.y = y * vsub + src_y % vsub; |
| 3149 | |
| 3150 | return 0; |
| 3151 | } |
| 3152 | |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 3153 | int skl_check_plane_surface(const struct intel_crtc_state *crtc_state, |
| 3154 | struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3155 | { |
| 3156 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3157 | unsigned int rotation = plane_state->base.rotation; |
| 3158 | int ret; |
| 3159 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3160 | if (rotation & DRM_MODE_REFLECT_X && |
| 3161 | fb->modifier == DRM_FORMAT_MOD_LINEAR) { |
| 3162 | DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n"); |
| 3163 | return -EINVAL; |
| 3164 | } |
| 3165 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3166 | if (!plane_state->base.visible) |
| 3167 | return 0; |
| 3168 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3169 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3170 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3171 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3172 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3173 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3174 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3175 | /* |
| 3176 | * Handle the AUX surface first since |
| 3177 | * the main surface setup depends on it. |
| 3178 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3179 | if (fb->format->format == DRM_FORMAT_NV12) { |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 3180 | ret = skl_check_nv12_surface(crtc_state, plane_state); |
| 3181 | if (ret) |
| 3182 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3183 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3184 | if (ret) |
| 3185 | return ret; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3186 | } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 3187 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) { |
| 3188 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3189 | if (ret) |
| 3190 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3191 | } else { |
| 3192 | plane_state->aux.offset = ~0xfff; |
| 3193 | plane_state->aux.x = 0; |
| 3194 | plane_state->aux.y = 0; |
| 3195 | } |
| 3196 | |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 3197 | ret = skl_check_main_surface(crtc_state, plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3198 | if (ret) |
| 3199 | return ret; |
| 3200 | |
| 3201 | return 0; |
| 3202 | } |
| 3203 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3204 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3205 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3206 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3207 | struct drm_i915_private *dev_priv = |
| 3208 | to_i915(plane_state->base.plane->dev); |
| 3209 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3210 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3211 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3212 | u32 dspcntr; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3213 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3214 | dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3215 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3216 | if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) || |
| 3217 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3218 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3219 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3220 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 3221 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3222 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3223 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3224 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3225 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3226 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3227 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3228 | dspcntr |= DISPPLANE_8BPP; |
| 3229 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3230 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3231 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3232 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3233 | case DRM_FORMAT_RGB565: |
| 3234 | dspcntr |= DISPPLANE_BGRX565; |
| 3235 | break; |
| 3236 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3237 | dspcntr |= DISPPLANE_BGRX888; |
| 3238 | break; |
| 3239 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3240 | dspcntr |= DISPPLANE_RGBX888; |
| 3241 | break; |
| 3242 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3243 | dspcntr |= DISPPLANE_BGRX101010; |
| 3244 | break; |
| 3245 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3246 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3247 | break; |
| 3248 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3249 | MISSING_CASE(fb->format->format); |
| 3250 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3251 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3252 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3253 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3254 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3255 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3256 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3257 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3258 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3259 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3260 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3261 | dspcntr |= DISPPLANE_MIRROR; |
| 3262 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3263 | return dspcntr; |
| 3264 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3265 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3266 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3267 | { |
| 3268 | struct drm_i915_private *dev_priv = |
| 3269 | to_i915(plane_state->base.plane->dev); |
| 3270 | int src_x = plane_state->base.src.x1 >> 16; |
| 3271 | int src_y = plane_state->base.src.y1 >> 16; |
| 3272 | u32 offset; |
| 3273 | |
| 3274 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3275 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3276 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3277 | offset = intel_compute_tile_offset(&src_x, &src_y, |
| 3278 | plane_state, 0); |
| 3279 | else |
| 3280 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3281 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3282 | /* HSW/BDW do this automagically in hardware */ |
| 3283 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
| 3284 | unsigned int rotation = plane_state->base.rotation; |
| 3285 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3286 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3287 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3288 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3289 | src_x += src_w - 1; |
| 3290 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3291 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3292 | src_x += src_w - 1; |
| 3293 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3294 | } |
| 3295 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3296 | plane_state->main.offset = offset; |
| 3297 | plane_state->main.x = src_x; |
| 3298 | plane_state->main.y = src_y; |
| 3299 | |
| 3300 | return 0; |
| 3301 | } |
| 3302 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3303 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3304 | const struct intel_crtc_state *crtc_state, |
| 3305 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3306 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3307 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 3308 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3309 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3310 | u32 linear_offset; |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 3311 | u32 dspcntr = plane_state->ctl; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3312 | i915_reg_t reg = DSPCNTR(i9xx_plane); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3313 | int x = plane_state->main.x; |
| 3314 | int y = plane_state->main.y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3315 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3316 | u32 dspaddr_offset; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3317 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3318 | 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] | 3319 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3320 | if (INTEL_GEN(dev_priv) >= 4) |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3321 | dspaddr_offset = plane_state->main.offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3322 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3323 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3324 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3325 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3326 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3327 | if (INTEL_GEN(dev_priv) < 4) { |
| 3328 | /* pipesrc and dspsize control the size that is scaled from, |
| 3329 | * which should always be the user's requested size. |
| 3330 | */ |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3331 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3332 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3333 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3334 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
| 3335 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
| 3336 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3337 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3338 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3339 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
| 3340 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3341 | } |
| 3342 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3343 | I915_WRITE_FW(reg, dspcntr); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3344 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3345 | I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3346 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3347 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3348 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3349 | dspaddr_offset); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3350 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3351 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3352 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3353 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3354 | dspaddr_offset); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3355 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3356 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3357 | } else { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3358 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3359 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3360 | dspaddr_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3361 | } |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3362 | POSTING_READ_FW(reg); |
| 3363 | |
| 3364 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3365 | } |
| 3366 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3367 | static void i9xx_disable_plane(struct intel_plane *plane, |
| 3368 | struct intel_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3369 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3370 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3371 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3372 | unsigned long irqflags; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3373 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3374 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3375 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3376 | I915_WRITE_FW(DSPCNTR(i9xx_plane), 0); |
| 3377 | if (INTEL_GEN(dev_priv) >= 4) |
| 3378 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3379 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3380 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
| 3381 | POSTING_READ_FW(DSPCNTR(i9xx_plane)); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3382 | |
| 3383 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3384 | } |
| 3385 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3386 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3387 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3388 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3389 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3390 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
| 3391 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3392 | bool ret; |
| 3393 | |
| 3394 | /* |
| 3395 | * Not 100% correct for planes that can move between pipes, |
| 3396 | * but that's only the case for gen2-4 which don't have any |
| 3397 | * display power wells. |
| 3398 | */ |
| 3399 | power_domain = POWER_DOMAIN_PIPE(pipe); |
| 3400 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 3401 | return false; |
| 3402 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3403 | ret = I915_READ(DSPCNTR(i9xx_plane)) & DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3404 | |
| 3405 | intel_display_power_put(dev_priv, power_domain); |
| 3406 | |
| 3407 | return ret; |
| 3408 | } |
| 3409 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3410 | static u32 |
| 3411 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3412 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3413 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3414 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3415 | else |
| 3416 | return intel_tile_width_bytes(fb, plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3417 | } |
| 3418 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3419 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3420 | { |
| 3421 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3422 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3423 | |
| 3424 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3425 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3426 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3427 | } |
| 3428 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3429 | /* |
| 3430 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3431 | */ |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 3432 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3433 | { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3434 | struct intel_crtc_scaler_state *scaler_state; |
| 3435 | int i; |
| 3436 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3437 | scaler_state = &intel_crtc->config->scaler_state; |
| 3438 | |
| 3439 | /* loop through and disable scalers that aren't in use */ |
| 3440 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3441 | if (!scaler_state->scalers[i].in_use) |
| 3442 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3443 | } |
| 3444 | } |
| 3445 | |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3446 | u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane, |
| 3447 | unsigned int rotation) |
| 3448 | { |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3449 | u32 stride; |
| 3450 | |
| 3451 | if (plane >= fb->format->num_planes) |
| 3452 | return 0; |
| 3453 | |
| 3454 | stride = intel_fb_pitch(fb, plane, rotation); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3455 | |
| 3456 | /* |
| 3457 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3458 | * linear buffers or in number of tiles for tiled buffers. |
| 3459 | */ |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3460 | if (drm_rotation_90_or_270(rotation)) |
| 3461 | stride /= intel_tile_height(fb, plane); |
| 3462 | else |
| 3463 | stride /= intel_fb_stride_alignment(fb, plane); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3464 | |
| 3465 | return stride; |
| 3466 | } |
| 3467 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3468 | static u32 skl_plane_ctl_format(uint32_t pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3469 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3470 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3471 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3472 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3473 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3474 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3475 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3476 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3477 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3478 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3479 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3480 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3481 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3482 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3483 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3484 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3485 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3486 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3487 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3488 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3489 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3490 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3491 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3492 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3493 | case DRM_FORMAT_NV12: |
| 3494 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3495 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3496 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3497 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3498 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3499 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3502 | /* |
| 3503 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 3504 | * to be already pre-multiplied. We need to add a knob (or a different |
| 3505 | * DRM_FORMAT) for user-space to configure that. |
| 3506 | */ |
| 3507 | static u32 skl_plane_ctl_alpha(uint32_t pixel_format) |
| 3508 | { |
| 3509 | switch (pixel_format) { |
| 3510 | case DRM_FORMAT_ABGR8888: |
| 3511 | case DRM_FORMAT_ARGB8888: |
| 3512 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 3513 | default: |
| 3514 | return PLANE_CTL_ALPHA_DISABLE; |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format) |
| 3519 | { |
| 3520 | switch (pixel_format) { |
| 3521 | case DRM_FORMAT_ABGR8888: |
| 3522 | case DRM_FORMAT_ARGB8888: |
| 3523 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
| 3524 | default: |
| 3525 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3526 | } |
| 3527 | } |
| 3528 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3529 | static u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3530 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3531 | switch (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3532 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3533 | break; |
| 3534 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3535 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3536 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3537 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3538 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 3539 | return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3540 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3541 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3542 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 3543 | return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3544 | default: |
| 3545 | MISSING_CASE(fb_modifier); |
| 3546 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3547 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3548 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3551 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3552 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3553 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3554 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3555 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3556 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3557 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3558 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3559 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3560 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3561 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3562 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3563 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3564 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3565 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3566 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3567 | MISSING_CASE(rotate); |
| 3568 | } |
| 3569 | |
| 3570 | return 0; |
| 3571 | } |
| 3572 | |
| 3573 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3574 | { |
| 3575 | switch (reflect) { |
| 3576 | case 0: |
| 3577 | break; |
| 3578 | case DRM_MODE_REFLECT_X: |
| 3579 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3580 | case DRM_MODE_REFLECT_Y: |
| 3581 | default: |
| 3582 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3585 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3588 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3589 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3590 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3591 | struct drm_i915_private *dev_priv = |
| 3592 | to_i915(plane_state->base.plane->dev); |
| 3593 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3594 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3595 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3596 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3597 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3598 | plane_ctl = PLANE_CTL_ENABLE; |
| 3599 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3600 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
| 3601 | plane_ctl |= skl_plane_ctl_alpha(fb->format->format); |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3602 | plane_ctl |= |
| 3603 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3604 | PLANE_CTL_PIPE_CSC_ENABLE | |
| 3605 | PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3606 | |
| 3607 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3608 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3609 | |
| 3610 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3611 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3612 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3613 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3614 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3615 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3616 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3617 | |
| 3618 | if (INTEL_GEN(dev_priv) >= 10) |
| 3619 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3620 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3621 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3622 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3623 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3624 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3625 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3626 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3627 | return plane_ctl; |
| 3628 | } |
| 3629 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3630 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3631 | const struct intel_plane_state *plane_state) |
| 3632 | { |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3633 | struct drm_i915_private *dev_priv = |
| 3634 | to_i915(plane_state->base.plane->dev); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3635 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3636 | u32 plane_color_ctl = 0; |
| 3637 | |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3638 | if (INTEL_GEN(dev_priv) < 11) { |
| 3639 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3640 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
| 3641 | } |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3642 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
| 3643 | plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format); |
| 3644 | |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3645 | if (intel_format_is_yuv(fb->format->format)) { |
Vidya Srinivas | 8ed30ab | 2018-04-09 09:11:10 +0530 | [diff] [blame] | 3646 | if (fb->format->format == DRM_FORMAT_NV12) { |
| 3647 | plane_color_ctl |= |
| 3648 | PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3649 | goto out; |
| 3650 | } |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3651 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3652 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3653 | else |
| 3654 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3655 | |
| 3656 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3657 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3658 | } |
Vidya Srinivas | 8ed30ab | 2018-04-09 09:11:10 +0530 | [diff] [blame] | 3659 | out: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3660 | return plane_color_ctl; |
| 3661 | } |
| 3662 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3663 | static int |
| 3664 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3665 | struct drm_atomic_state *state, |
| 3666 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3667 | { |
| 3668 | struct drm_crtc_state *crtc_state; |
| 3669 | struct drm_crtc *crtc; |
| 3670 | int i, ret; |
| 3671 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3672 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3673 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3674 | |
| 3675 | if (!state) |
| 3676 | return 0; |
| 3677 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3678 | /* |
| 3679 | * We've duplicated the state, pointers to the old state are invalid. |
| 3680 | * |
| 3681 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3682 | */ |
| 3683 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3684 | /* |
| 3685 | * Force recalculation even if we restore |
| 3686 | * current state. With fast modeset this may not result |
| 3687 | * in a modeset when the state is compatible. |
| 3688 | */ |
| 3689 | crtc_state->mode_changed = true; |
| 3690 | } |
| 3691 | |
| 3692 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3693 | if (!HAS_GMCH_DISPLAY(to_i915(dev))) |
| 3694 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3695 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3696 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3697 | |
| 3698 | WARN_ON(ret == -EDEADLK); |
| 3699 | return ret; |
| 3700 | } |
| 3701 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3702 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3703 | { |
Ville Syrjälä | ae98104 | 2016-08-05 23:28:30 +0300 | [diff] [blame] | 3704 | return intel_has_gpu_reset(dev_priv) && |
| 3705 | INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3706 | } |
| 3707 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3708 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3709 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3710 | struct drm_device *dev = &dev_priv->drm; |
| 3711 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3712 | struct drm_atomic_state *state; |
| 3713 | int ret; |
| 3714 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3715 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3716 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3717 | !gpu_reset_clobbers_display(dev_priv)) |
| 3718 | return; |
| 3719 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3720 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3721 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3722 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3723 | |
| 3724 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3725 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3726 | i915_gem_set_wedged(dev_priv); |
| 3727 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3728 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3729 | /* |
| 3730 | * Need mode_config.mutex so that we don't |
| 3731 | * trample ongoing ->detect() and whatnot. |
| 3732 | */ |
| 3733 | mutex_lock(&dev->mode_config.mutex); |
| 3734 | drm_modeset_acquire_init(ctx, 0); |
| 3735 | while (1) { |
| 3736 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3737 | if (ret != -EDEADLK) |
| 3738 | break; |
| 3739 | |
| 3740 | drm_modeset_backoff(ctx); |
| 3741 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3742 | /* |
| 3743 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3744 | * g33 docs say we should at least disable all the planes. |
| 3745 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3746 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3747 | if (IS_ERR(state)) { |
| 3748 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3749 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3750 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3754 | if (ret) { |
| 3755 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3756 | drm_atomic_state_put(state); |
| 3757 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | dev_priv->modeset_restore_state = state; |
| 3761 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3762 | } |
| 3763 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3764 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3765 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3766 | struct drm_device *dev = &dev_priv->drm; |
| 3767 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3768 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3769 | int ret; |
| 3770 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3771 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3772 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3773 | return; |
| 3774 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3775 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3776 | if (!state) |
| 3777 | goto unlock; |
| 3778 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3779 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3780 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3781 | /* for testing only restore the display */ |
| 3782 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3783 | if (ret) |
| 3784 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3785 | } else { |
| 3786 | /* |
| 3787 | * The display has been reset as well, |
| 3788 | * so need a full re-initialization. |
| 3789 | */ |
| 3790 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3791 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3792 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3793 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3794 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3795 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3796 | |
| 3797 | spin_lock_irq(&dev_priv->irq_lock); |
| 3798 | if (dev_priv->display.hpd_irq_setup) |
| 3799 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3800 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3801 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3802 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3803 | if (ret) |
| 3804 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3805 | |
| 3806 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3807 | } |
| 3808 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3809 | drm_atomic_state_put(state); |
| 3810 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3811 | drm_modeset_drop_locks(ctx); |
| 3812 | drm_modeset_acquire_fini(ctx); |
| 3813 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3814 | |
| 3815 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3816 | } |
| 3817 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3818 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3819 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3820 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3821 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3822 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3823 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3824 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3825 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3826 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3827 | /* |
| 3828 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3829 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3830 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3831 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3832 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3833 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3834 | */ |
| 3835 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3836 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3837 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3838 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3839 | |
| 3840 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3841 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3842 | skl_detach_scalers(crtc); |
| 3843 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3844 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3845 | skylake_pfit_enable(crtc); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3846 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3847 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3848 | ironlake_pfit_enable(crtc); |
| 3849 | else if (old_crtc_state->pch_pfit.enabled) |
| 3850 | ironlake_pfit_disable(crtc, true); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3851 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3852 | } |
| 3853 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3854 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3855 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3856 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3857 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3858 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3859 | i915_reg_t reg; |
| 3860 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3861 | |
| 3862 | /* enable normal train */ |
| 3863 | reg = FDI_TX_CTL(pipe); |
| 3864 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3865 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3866 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3867 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3868 | } else { |
| 3869 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3870 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3871 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3872 | I915_WRITE(reg, temp); |
| 3873 | |
| 3874 | reg = FDI_RX_CTL(pipe); |
| 3875 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3876 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3877 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3878 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3879 | } else { |
| 3880 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3881 | temp |= FDI_LINK_TRAIN_NONE; |
| 3882 | } |
| 3883 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3884 | |
| 3885 | /* wait one idle pattern time */ |
| 3886 | POSTING_READ(reg); |
| 3887 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3888 | |
| 3889 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3890 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3891 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3892 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3893 | } |
| 3894 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3895 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3896 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 3897 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3898 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3899 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3900 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3901 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3902 | i915_reg_t reg; |
| 3903 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3904 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3905 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3906 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3907 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3908 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3909 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3910 | reg = FDI_RX_IMR(pipe); |
| 3911 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3912 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3913 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3914 | I915_WRITE(reg, temp); |
| 3915 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3916 | udelay(150); |
| 3917 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3918 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3919 | reg = FDI_TX_CTL(pipe); |
| 3920 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3921 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3922 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3923 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3924 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3925 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3926 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3927 | reg = FDI_RX_CTL(pipe); |
| 3928 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3929 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3930 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3931 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3932 | |
| 3933 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3934 | udelay(150); |
| 3935 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3936 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3937 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3938 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3939 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3940 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3941 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3942 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3943 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3944 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3945 | |
| 3946 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3947 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3948 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3949 | break; |
| 3950 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3951 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3952 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3953 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3954 | |
| 3955 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3956 | reg = FDI_TX_CTL(pipe); |
| 3957 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3958 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3959 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3960 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3961 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3962 | reg = FDI_RX_CTL(pipe); |
| 3963 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3964 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3965 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3966 | I915_WRITE(reg, temp); |
| 3967 | |
| 3968 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3969 | udelay(150); |
| 3970 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3971 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3972 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3973 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3974 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3975 | |
| 3976 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3977 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3978 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3979 | break; |
| 3980 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3981 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3982 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3983 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3984 | |
| 3985 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3986 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3987 | } |
| 3988 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3989 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3990 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3991 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3992 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3993 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3994 | }; |
| 3995 | |
| 3996 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3997 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
| 3998 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3999 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4000 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4001 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4002 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4003 | i915_reg_t reg; |
| 4004 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4005 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4006 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4007 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4008 | reg = FDI_RX_IMR(pipe); |
| 4009 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4010 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4011 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4012 | I915_WRITE(reg, temp); |
| 4013 | |
| 4014 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4015 | udelay(150); |
| 4016 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4017 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4018 | reg = FDI_TX_CTL(pipe); |
| 4019 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4020 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4021 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4022 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4023 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4024 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4025 | /* SNB-B */ |
| 4026 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4027 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4028 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4029 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4030 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4031 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4032 | reg = FDI_RX_CTL(pipe); |
| 4033 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4034 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4035 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4036 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4037 | } else { |
| 4038 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4039 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4040 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4041 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4042 | |
| 4043 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4044 | udelay(150); |
| 4045 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4046 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4047 | reg = FDI_TX_CTL(pipe); |
| 4048 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4049 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4050 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4051 | I915_WRITE(reg, temp); |
| 4052 | |
| 4053 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4054 | udelay(500); |
| 4055 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4056 | for (retry = 0; retry < 5; retry++) { |
| 4057 | reg = FDI_RX_IIR(pipe); |
| 4058 | temp = I915_READ(reg); |
| 4059 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4060 | if (temp & FDI_RX_BIT_LOCK) { |
| 4061 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4062 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4063 | break; |
| 4064 | } |
| 4065 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4066 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4067 | if (retry < 5) |
| 4068 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4069 | } |
| 4070 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4071 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4072 | |
| 4073 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4074 | reg = FDI_TX_CTL(pipe); |
| 4075 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4076 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4077 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4078 | if (IS_GEN6(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4079 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4080 | /* SNB-B */ |
| 4081 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4082 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4083 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4084 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4085 | reg = FDI_RX_CTL(pipe); |
| 4086 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4087 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4088 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4089 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4090 | } else { |
| 4091 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4092 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4093 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4094 | I915_WRITE(reg, temp); |
| 4095 | |
| 4096 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4097 | udelay(150); |
| 4098 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4099 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4100 | reg = FDI_TX_CTL(pipe); |
| 4101 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4102 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4103 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4104 | I915_WRITE(reg, temp); |
| 4105 | |
| 4106 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4107 | udelay(500); |
| 4108 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4109 | for (retry = 0; retry < 5; retry++) { |
| 4110 | reg = FDI_RX_IIR(pipe); |
| 4111 | temp = I915_READ(reg); |
| 4112 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4113 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4114 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4115 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4116 | break; |
| 4117 | } |
| 4118 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4119 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4120 | if (retry < 5) |
| 4121 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4122 | } |
| 4123 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4124 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4125 | |
| 4126 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4127 | } |
| 4128 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4129 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4130 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4131 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4132 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4133 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4134 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4135 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4136 | i915_reg_t reg; |
| 4137 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4138 | |
| 4139 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4140 | for train result */ |
| 4141 | reg = FDI_RX_IMR(pipe); |
| 4142 | temp = I915_READ(reg); |
| 4143 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4144 | temp &= ~FDI_RX_BIT_LOCK; |
| 4145 | I915_WRITE(reg, temp); |
| 4146 | |
| 4147 | POSTING_READ(reg); |
| 4148 | udelay(150); |
| 4149 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4150 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4151 | I915_READ(FDI_RX_IIR(pipe))); |
| 4152 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4153 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4154 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4155 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4156 | reg = FDI_TX_CTL(pipe); |
| 4157 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4158 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4159 | temp &= ~FDI_TX_ENABLE; |
| 4160 | I915_WRITE(reg, temp); |
| 4161 | |
| 4162 | reg = FDI_RX_CTL(pipe); |
| 4163 | temp = I915_READ(reg); |
| 4164 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4165 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4166 | temp &= ~FDI_RX_ENABLE; |
| 4167 | I915_WRITE(reg, temp); |
| 4168 | |
| 4169 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4170 | reg = FDI_TX_CTL(pipe); |
| 4171 | temp = I915_READ(reg); |
| 4172 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4173 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4174 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4175 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4176 | temp |= snb_b_fdi_train_param[j/2]; |
| 4177 | temp |= FDI_COMPOSITE_SYNC; |
| 4178 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4179 | |
| 4180 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4181 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4182 | |
| 4183 | reg = FDI_RX_CTL(pipe); |
| 4184 | temp = I915_READ(reg); |
| 4185 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4186 | temp |= FDI_COMPOSITE_SYNC; |
| 4187 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4188 | |
| 4189 | POSTING_READ(reg); |
| 4190 | udelay(1); /* should be 0.5us */ |
| 4191 | |
| 4192 | for (i = 0; i < 4; i++) { |
| 4193 | reg = FDI_RX_IIR(pipe); |
| 4194 | temp = I915_READ(reg); |
| 4195 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4196 | |
| 4197 | if (temp & FDI_RX_BIT_LOCK || |
| 4198 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4199 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4200 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4201 | i); |
| 4202 | break; |
| 4203 | } |
| 4204 | udelay(1); /* should be 0.5us */ |
| 4205 | } |
| 4206 | if (i == 4) { |
| 4207 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4208 | continue; |
| 4209 | } |
| 4210 | |
| 4211 | /* Train 2 */ |
| 4212 | reg = FDI_TX_CTL(pipe); |
| 4213 | temp = I915_READ(reg); |
| 4214 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4215 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4216 | I915_WRITE(reg, temp); |
| 4217 | |
| 4218 | reg = FDI_RX_CTL(pipe); |
| 4219 | temp = I915_READ(reg); |
| 4220 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4221 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4222 | I915_WRITE(reg, temp); |
| 4223 | |
| 4224 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4225 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4226 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4227 | for (i = 0; i < 4; i++) { |
| 4228 | reg = FDI_RX_IIR(pipe); |
| 4229 | temp = I915_READ(reg); |
| 4230 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4231 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4232 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4233 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4234 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4235 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4236 | i); |
| 4237 | goto train_done; |
| 4238 | } |
| 4239 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4240 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4241 | if (i == 4) |
| 4242 | 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] | 4243 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4244 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4245 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4246 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4247 | } |
| 4248 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4249 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4250 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4251 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4252 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4253 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4254 | i915_reg_t reg; |
| 4255 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4256 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4257 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4258 | reg = FDI_RX_CTL(pipe); |
| 4259 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4260 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4261 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4262 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4263 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4264 | |
| 4265 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4266 | udelay(200); |
| 4267 | |
| 4268 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4269 | temp = I915_READ(reg); |
| 4270 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4271 | |
| 4272 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4273 | udelay(200); |
| 4274 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4275 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4276 | reg = FDI_TX_CTL(pipe); |
| 4277 | temp = I915_READ(reg); |
| 4278 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4279 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4280 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4281 | POSTING_READ(reg); |
| 4282 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4286 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4287 | { |
| 4288 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4289 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4290 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4291 | i915_reg_t reg; |
| 4292 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4293 | |
| 4294 | /* Switch from PCDclk to Rawclk */ |
| 4295 | reg = FDI_RX_CTL(pipe); |
| 4296 | temp = I915_READ(reg); |
| 4297 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4298 | |
| 4299 | /* Disable CPU FDI TX PLL */ |
| 4300 | reg = FDI_TX_CTL(pipe); |
| 4301 | temp = I915_READ(reg); |
| 4302 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4303 | |
| 4304 | POSTING_READ(reg); |
| 4305 | udelay(100); |
| 4306 | |
| 4307 | reg = FDI_RX_CTL(pipe); |
| 4308 | temp = I915_READ(reg); |
| 4309 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4310 | |
| 4311 | /* Wait for the clocks to turn off. */ |
| 4312 | POSTING_READ(reg); |
| 4313 | udelay(100); |
| 4314 | } |
| 4315 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4316 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4317 | { |
| 4318 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4319 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4320 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4321 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4322 | i915_reg_t reg; |
| 4323 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4324 | |
| 4325 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4326 | reg = FDI_TX_CTL(pipe); |
| 4327 | temp = I915_READ(reg); |
| 4328 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4329 | POSTING_READ(reg); |
| 4330 | |
| 4331 | reg = FDI_RX_CTL(pipe); |
| 4332 | temp = I915_READ(reg); |
| 4333 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4334 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4335 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4336 | |
| 4337 | POSTING_READ(reg); |
| 4338 | udelay(100); |
| 4339 | |
| 4340 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4341 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4342 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4343 | |
| 4344 | /* still set train pattern 1 */ |
| 4345 | reg = FDI_TX_CTL(pipe); |
| 4346 | temp = I915_READ(reg); |
| 4347 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4348 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4349 | I915_WRITE(reg, temp); |
| 4350 | |
| 4351 | reg = FDI_RX_CTL(pipe); |
| 4352 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4353 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4354 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4355 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4356 | } else { |
| 4357 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4358 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4359 | } |
| 4360 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4361 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4362 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4363 | I915_WRITE(reg, temp); |
| 4364 | |
| 4365 | POSTING_READ(reg); |
| 4366 | udelay(100); |
| 4367 | } |
| 4368 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4369 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4370 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4371 | struct drm_crtc *crtc; |
| 4372 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4373 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4374 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4375 | struct drm_crtc_commit *commit; |
| 4376 | spin_lock(&crtc->commit_lock); |
| 4377 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4378 | struct drm_crtc_commit, commit_entry); |
| 4379 | cleanup_done = commit ? |
| 4380 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4381 | spin_unlock(&crtc->commit_lock); |
| 4382 | |
| 4383 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4384 | continue; |
| 4385 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4386 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4387 | |
| 4388 | return true; |
| 4389 | } |
| 4390 | |
| 4391 | return false; |
| 4392 | } |
| 4393 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4394 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4395 | { |
| 4396 | u32 temp; |
| 4397 | |
| 4398 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4399 | |
| 4400 | mutex_lock(&dev_priv->sb_lock); |
| 4401 | |
| 4402 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4403 | temp |= SBI_SSCCTL_DISABLE; |
| 4404 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4405 | |
| 4406 | mutex_unlock(&dev_priv->sb_lock); |
| 4407 | } |
| 4408 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4409 | /* Program iCLKIP clock to the desired frequency */ |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4410 | static void lpt_program_iclkip(struct intel_crtc *crtc) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4411 | { |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4412 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4413 | int clock = crtc->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4414 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4415 | u32 temp; |
| 4416 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4417 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4418 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4419 | /* The iCLK virtual clock root frequency is in MHz, |
| 4420 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4421 | * divisors, it is necessary to divide one by another, so we |
| 4422 | * convert the virtual clock precision to KHz here for higher |
| 4423 | * precision. |
| 4424 | */ |
| 4425 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4426 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4427 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4428 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4429 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4430 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4431 | clock << auxdiv); |
| 4432 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4433 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4434 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4435 | /* |
| 4436 | * Near 20MHz is a corner case which is |
| 4437 | * out of range for the 7-bit divisor |
| 4438 | */ |
| 4439 | if (divsel <= 0x7f) |
| 4440 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | /* This should not happen with any sane values */ |
| 4444 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4445 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4446 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4447 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4448 | |
| 4449 | 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] | 4450 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4451 | auxdiv, |
| 4452 | divsel, |
| 4453 | phasedir, |
| 4454 | phaseinc); |
| 4455 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4456 | mutex_lock(&dev_priv->sb_lock); |
| 4457 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4458 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4459 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4460 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4461 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4462 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4463 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4464 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4465 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4466 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4467 | |
| 4468 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4469 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4470 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4471 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4472 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4473 | |
| 4474 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4475 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4476 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4477 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4478 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4479 | mutex_unlock(&dev_priv->sb_lock); |
| 4480 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4481 | /* Wait for initialization time */ |
| 4482 | udelay(24); |
| 4483 | |
| 4484 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4485 | } |
| 4486 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4487 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4488 | { |
| 4489 | u32 divsel, phaseinc, auxdiv; |
| 4490 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4491 | u32 iclk_pi_range = 64; |
| 4492 | u32 desired_divisor; |
| 4493 | u32 temp; |
| 4494 | |
| 4495 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4496 | return 0; |
| 4497 | |
| 4498 | mutex_lock(&dev_priv->sb_lock); |
| 4499 | |
| 4500 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4501 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4502 | mutex_unlock(&dev_priv->sb_lock); |
| 4503 | return 0; |
| 4504 | } |
| 4505 | |
| 4506 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4507 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4508 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4509 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4510 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4511 | |
| 4512 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4513 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4514 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4515 | |
| 4516 | mutex_unlock(&dev_priv->sb_lock); |
| 4517 | |
| 4518 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4519 | |
| 4520 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4521 | desired_divisor << auxdiv); |
| 4522 | } |
| 4523 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4524 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 4525 | enum pipe pch_transcoder) |
| 4526 | { |
| 4527 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4528 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4529 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4530 | |
| 4531 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4532 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4533 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4534 | I915_READ(HBLANK(cpu_transcoder))); |
| 4535 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4536 | I915_READ(HSYNC(cpu_transcoder))); |
| 4537 | |
| 4538 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4539 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4540 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4541 | I915_READ(VBLANK(cpu_transcoder))); |
| 4542 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4543 | I915_READ(VSYNC(cpu_transcoder))); |
| 4544 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4545 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4546 | } |
| 4547 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4548 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4549 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4550 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4551 | uint32_t temp; |
| 4552 | |
| 4553 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4554 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4555 | return; |
| 4556 | |
| 4557 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4558 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4559 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4560 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4561 | if (enable) |
| 4562 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4563 | |
| 4564 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4565 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4566 | POSTING_READ(SOUTH_CHICKEN1); |
| 4567 | } |
| 4568 | |
| 4569 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4570 | { |
| 4571 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4572 | |
| 4573 | switch (intel_crtc->pipe) { |
| 4574 | case PIPE_A: |
| 4575 | break; |
| 4576 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4577 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4578 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4579 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4580 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4581 | |
| 4582 | break; |
| 4583 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4584 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4585 | |
| 4586 | break; |
| 4587 | default: |
| 4588 | BUG(); |
| 4589 | } |
| 4590 | } |
| 4591 | |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4592 | /* Return which DP Port should be selected for Transcoder DP control */ |
| 4593 | static enum port |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4594 | intel_trans_dp_port_sel(struct intel_crtc *crtc) |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4595 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4596 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4597 | struct intel_encoder *encoder; |
| 4598 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4599 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4600 | if (encoder->type == INTEL_OUTPUT_DP || |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4601 | encoder->type == INTEL_OUTPUT_EDP) |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 4602 | return encoder->port; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4603 | } |
| 4604 | |
| 4605 | return -1; |
| 4606 | } |
| 4607 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4608 | /* |
| 4609 | * Enable PCH resources required for PCH ports: |
| 4610 | * - PCH PLLs |
| 4611 | * - FDI training & RX/TX |
| 4612 | * - update transcoder timings |
| 4613 | * - DP transcoding bits |
| 4614 | * - transcoder |
| 4615 | */ |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4616 | static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4617 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4618 | 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] | 4619 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4620 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4621 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4622 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4623 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4624 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4625 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4626 | if (IS_IVYBRIDGE(dev_priv)) |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4627 | ivybridge_update_fdi_bc_bifurcation(crtc); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4628 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4629 | /* Write the TU size bits before fdi link training, so that error |
| 4630 | * detection works. */ |
| 4631 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4632 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4633 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4634 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4635 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4636 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4637 | /* We need to program the right clock selection before writing the pixel |
| 4638 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4639 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4640 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4641 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4642 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4643 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4644 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4645 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4646 | 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] | 4647 | temp |= sel; |
| 4648 | else |
| 4649 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4650 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4651 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4652 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4653 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4654 | * transcoder, and we actually should do this to not upset any PCH |
| 4655 | * transcoder that already use the clock when we share it. |
| 4656 | * |
| 4657 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4658 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4659 | * the right LVDS enable sequence. */ |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4660 | intel_enable_shared_dpll(crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4661 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4662 | /* set transcoder timing, panel must allow it */ |
| 4663 | assert_panel_unlocked(dev_priv, pipe); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4664 | ironlake_pch_transcoder_set_timings(crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4665 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4666 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4667 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4668 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4669 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4670 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4671 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4672 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4673 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4674 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4675 | temp = I915_READ(reg); |
| 4676 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4677 | TRANS_DP_SYNC_MASK | |
| 4678 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4679 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4680 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4681 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4682 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4683 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4684 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4685 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4686 | |
| 4687 | switch (intel_trans_dp_port_sel(crtc)) { |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4688 | case PORT_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4689 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4690 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4691 | case PORT_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4692 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4693 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4694 | case PORT_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4695 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4696 | break; |
| 4697 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4698 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4701 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4704 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4705 | } |
| 4706 | |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4707 | static void lpt_pch_enable(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4708 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4709 | 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] | 4710 | 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] | 4711 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4712 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4713 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4714 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4715 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4716 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4717 | /* Set transcoder timing. */ |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4718 | ironlake_pch_transcoder_set_timings(crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4719 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4720 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4721 | } |
| 4722 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4723 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4724 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4725 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4726 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4727 | u32 temp; |
| 4728 | |
| 4729 | temp = I915_READ(dslreg); |
| 4730 | udelay(500); |
| 4731 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4732 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4733 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4734 | } |
| 4735 | } |
| 4736 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4737 | static int |
| 4738 | 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] | 4739 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4740 | int src_w, int src_h, int dst_w, int dst_h, |
| 4741 | bool plane_scaler_check, |
| 4742 | uint32_t pixel_format) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4743 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4744 | struct intel_crtc_scaler_state *scaler_state = |
| 4745 | &crtc_state->scaler_state; |
| 4746 | struct intel_crtc *intel_crtc = |
| 4747 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4748 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4749 | const struct drm_display_mode *adjusted_mode = |
| 4750 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4751 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4752 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4753 | /* |
| 4754 | * Src coordinates are already rotated by 270 degrees for |
| 4755 | * the 90/270 degree plane rotation cases (to match the |
| 4756 | * GTT mapping), hence no need to account for rotation here. |
| 4757 | */ |
| 4758 | need_scaling = src_w != dst_w || src_h != dst_h; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4759 | |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4760 | if (plane_scaler_check) |
| 4761 | if (pixel_format == DRM_FORMAT_NV12) |
| 4762 | need_scaling = true; |
| 4763 | |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 4764 | if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX) |
| 4765 | need_scaling = true; |
| 4766 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4767 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4768 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 4769 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 4770 | * Once NV12 is enabled, handle it here while allocating scaler |
| 4771 | * for NV12. |
| 4772 | */ |
| 4773 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
| 4774 | need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 4775 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 4776 | return -EINVAL; |
| 4777 | } |
| 4778 | |
| 4779 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4780 | * if plane is being disabled or scaler is no more required or force detach |
| 4781 | * - free scaler binded to this plane/crtc |
| 4782 | * - in order to do this, update crtc->scaler_usage |
| 4783 | * |
| 4784 | * Here scaler state in crtc_state is set free so that |
| 4785 | * scaler can be assigned to other user. Actual register |
| 4786 | * update to free the scaler is done in plane/panel-fit programming. |
| 4787 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4788 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4789 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4790 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4791 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4792 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4793 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4794 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4795 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4796 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4797 | scaler_state->scaler_users); |
| 4798 | *scaler_id = -1; |
| 4799 | } |
| 4800 | return 0; |
| 4801 | } |
| 4802 | |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4803 | if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 4804 | (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] | 4805 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 4806 | return -EINVAL; |
| 4807 | } |
| 4808 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4809 | /* range checks */ |
| 4810 | 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] | 4811 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4812 | (IS_GEN11(dev_priv) && |
| 4813 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 4814 | dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) || |
| 4815 | (!IS_GEN11(dev_priv) && |
| 4816 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4817 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4818 | 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] | 4819 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4820 | 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] | 4821 | return -EINVAL; |
| 4822 | } |
| 4823 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4824 | /* mark this plane as a scaler user in crtc_state */ |
| 4825 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4826 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4827 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4828 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4829 | scaler_state->scaler_users); |
| 4830 | |
| 4831 | return 0; |
| 4832 | } |
| 4833 | |
| 4834 | /** |
| 4835 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4836 | * |
| 4837 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4838 | * |
| 4839 | * Return |
| 4840 | * 0 - scaler_usage updated successfully |
| 4841 | * error - requested scaling cannot be supported or other error condition |
| 4842 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4843 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4844 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4845 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4846 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4847 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4848 | &state->scaler_state.scaler_id, |
| 4849 | state->pipe_src_w, state->pipe_src_h, |
| 4850 | adjusted_mode->crtc_hdisplay, |
| 4851 | adjusted_mode->crtc_vdisplay, false, 0); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | /** |
| 4855 | * 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] | 4856 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4857 | * @plane_state: atomic plane state to update |
| 4858 | * |
| 4859 | * Return |
| 4860 | * 0 - scaler_usage updated successfully |
| 4861 | * error - requested scaling cannot be supported or other error condition |
| 4862 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4863 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4864 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4865 | { |
| 4866 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4867 | struct intel_plane *intel_plane = |
| 4868 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4869 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4870 | int ret; |
| 4871 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4872 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4873 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4874 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4875 | drm_plane_index(&intel_plane->base), |
| 4876 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4877 | drm_rect_width(&plane_state->base.src) >> 16, |
| 4878 | drm_rect_height(&plane_state->base.src) >> 16, |
| 4879 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4880 | drm_rect_height(&plane_state->base.dst), |
| 4881 | fb ? true : false, fb ? fb->format->format : 0); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4882 | |
| 4883 | if (ret || plane_state->scaler_id < 0) |
| 4884 | return ret; |
| 4885 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4886 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 4887 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4888 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 4889 | intel_plane->base.base.id, |
| 4890 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4891 | return -EINVAL; |
| 4892 | } |
| 4893 | |
| 4894 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4895 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4896 | case DRM_FORMAT_RGB565: |
| 4897 | case DRM_FORMAT_XBGR8888: |
| 4898 | case DRM_FORMAT_XRGB8888: |
| 4899 | case DRM_FORMAT_ABGR8888: |
| 4900 | case DRM_FORMAT_ARGB8888: |
| 4901 | case DRM_FORMAT_XRGB2101010: |
| 4902 | case DRM_FORMAT_XBGR2101010: |
| 4903 | case DRM_FORMAT_YUYV: |
| 4904 | case DRM_FORMAT_YVYU: |
| 4905 | case DRM_FORMAT_UYVY: |
| 4906 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4907 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4908 | break; |
| 4909 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4910 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 4911 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4912 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4913 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4916 | return 0; |
| 4917 | } |
| 4918 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4919 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4920 | { |
| 4921 | int i; |
| 4922 | |
| 4923 | for (i = 0; i < crtc->num_scalers; i++) |
| 4924 | skl_detach_scaler(crtc, i); |
| 4925 | } |
| 4926 | |
| 4927 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4928 | { |
| 4929 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4930 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4931 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4932 | struct intel_crtc_scaler_state *scaler_state = |
| 4933 | &crtc->config->scaler_state; |
| 4934 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4935 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4936 | int id; |
| 4937 | |
Ville Syrjälä | c3f8ad5 | 2017-03-07 22:54:19 +0200 | [diff] [blame] | 4938 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4939 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4940 | |
| 4941 | id = scaler_state->scaler_id; |
| 4942 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4943 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4944 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4945 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4946 | } |
| 4947 | } |
| 4948 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4949 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4950 | { |
| 4951 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4952 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4953 | int pipe = crtc->pipe; |
| 4954 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4955 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4956 | /* Force use of hard-coded filter coefficients |
| 4957 | * as some pre-programmed values are broken, |
| 4958 | * e.g. x201. |
| 4959 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4960 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4961 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4962 | PF_PIPE_SEL_IVB(pipe)); |
| 4963 | else |
| 4964 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4965 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4966 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4967 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4968 | } |
| 4969 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 4970 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4971 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 4972 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4973 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4974 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4975 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 4976 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4977 | return; |
| 4978 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 4979 | /* |
| 4980 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 4981 | * This function is called from post_plane_update, which is run after |
| 4982 | * a vblank wait. |
| 4983 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 4984 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 4985 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 4986 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 4987 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 4988 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 4989 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 4990 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4991 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4992 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4993 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4994 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4995 | */ |
| 4996 | } else { |
| 4997 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4998 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4999 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5000 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5001 | * the HW state readout code will complain that the expected |
| 5002 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5003 | if (intel_wait_for_register(dev_priv, |
| 5004 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5005 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5006 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5007 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5008 | } |
| 5009 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5010 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5011 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5012 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5013 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5014 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5015 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5016 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5017 | return; |
| 5018 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5019 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5020 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5021 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5022 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5023 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5024 | if (intel_wait_for_register(dev_priv, |
| 5025 | IPS_CTL, IPS_ENABLE, 0, |
| 5026 | 42)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5027 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5028 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5029 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5030 | POSTING_READ(IPS_CTL); |
| 5031 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5032 | |
| 5033 | /* 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] | 5034 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5035 | } |
| 5036 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5037 | 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] | 5038 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5039 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5040 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5041 | |
| 5042 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5043 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5044 | mutex_unlock(&dev->struct_mutex); |
| 5045 | } |
| 5046 | |
| 5047 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5048 | * has to recompute where to put it anyway. |
| 5049 | */ |
| 5050 | } |
| 5051 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5052 | /** |
| 5053 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5054 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5055 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5056 | * |
| 5057 | * Performs potentially sleeping operations that must be done after the primary |
| 5058 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5059 | * called due to an explicit primary plane update, or due to an implicit |
| 5060 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5061 | * completely hide the primary plane. |
| 5062 | */ |
| 5063 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5064 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5065 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5066 | { |
| 5067 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5068 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5069 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5070 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5071 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5072 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5073 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5074 | * So don't enable underrun reporting before at least some planes |
| 5075 | * are enabled. |
| 5076 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5077 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5078 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5079 | if (IS_GEN2(dev_priv)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5080 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5081 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5082 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5083 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5084 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5085 | } |
| 5086 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5087 | /* FIXME get rid of this and use pre_plane_update */ |
| 5088 | static void |
| 5089 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5090 | { |
| 5091 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5092 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5093 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5094 | int pipe = intel_crtc->pipe; |
| 5095 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5096 | /* |
| 5097 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5098 | * So disable underrun reporting before all the planes get disabled. |
| 5099 | */ |
| 5100 | if (IS_GEN2(dev_priv)) |
| 5101 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5102 | |
| 5103 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5104 | |
| 5105 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5106 | * Vblank time updates from the shadow to live plane control register |
| 5107 | * are blocked if the memory self-refresh mode is active at that |
| 5108 | * moment. So to make sure the plane gets truly disabled, disable |
| 5109 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5110 | * will be checked/applied by the HW only at the next frame start |
| 5111 | * event which is after the vblank start event, so we need to have a |
| 5112 | * wait-for-vblank between disabling the plane and the pipe. |
| 5113 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5114 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 5115 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5116 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5117 | } |
| 5118 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5119 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5120 | const struct intel_crtc_state *new_crtc_state) |
| 5121 | { |
| 5122 | if (!old_crtc_state->ips_enabled) |
| 5123 | return false; |
| 5124 | |
| 5125 | if (needs_modeset(&new_crtc_state->base)) |
| 5126 | return true; |
| 5127 | |
| 5128 | return !new_crtc_state->ips_enabled; |
| 5129 | } |
| 5130 | |
| 5131 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5132 | const struct intel_crtc_state *new_crtc_state) |
| 5133 | { |
| 5134 | if (!new_crtc_state->ips_enabled) |
| 5135 | return false; |
| 5136 | |
| 5137 | if (needs_modeset(&new_crtc_state->base)) |
| 5138 | return true; |
| 5139 | |
| 5140 | /* |
| 5141 | * We can't read out IPS on broadwell, assume the worst and |
| 5142 | * forcibly enable IPS on the first fastset. |
| 5143 | */ |
| 5144 | if (new_crtc_state->update_pipe && |
| 5145 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5146 | return true; |
| 5147 | |
| 5148 | return !old_crtc_state->ips_enabled; |
| 5149 | } |
| 5150 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5151 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5152 | const struct intel_crtc_state *crtc_state) |
| 5153 | { |
| 5154 | if (!crtc_state->nv12_planes) |
| 5155 | return false; |
| 5156 | |
| 5157 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
| 5158 | return false; |
| 5159 | |
| 5160 | if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) || |
| 5161 | IS_CANNONLAKE(dev_priv)) |
| 5162 | return true; |
| 5163 | |
| 5164 | return false; |
| 5165 | } |
| 5166 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5167 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5168 | { |
| 5169 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5170 | struct drm_device *dev = crtc->base.dev; |
| 5171 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5172 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5173 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5174 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5175 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5176 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5177 | struct drm_plane_state *old_primary_state = |
| 5178 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5179 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5180 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5181 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5182 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5183 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5184 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5185 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5186 | hsw_enable_ips(pipe_config); |
| 5187 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5188 | if (old_primary_state) { |
| 5189 | struct drm_plane_state *new_primary_state = |
| 5190 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5191 | |
| 5192 | intel_fbc_post_update(crtc); |
| 5193 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5194 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5195 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5196 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5197 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5198 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5199 | |
| 5200 | /* Display WA 827 */ |
| 5201 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5202 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5203 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5204 | skl_wa_528(dev_priv, crtc->pipe, false); |
| 5205 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5206 | } |
| 5207 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5208 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5209 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5210 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5211 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5212 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5213 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5214 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5215 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5216 | struct drm_plane_state *old_primary_state = |
| 5217 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5218 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5219 | struct intel_atomic_state *old_intel_state = |
| 5220 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5221 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5222 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5223 | hsw_disable_ips(old_crtc_state); |
| 5224 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5225 | if (old_primary_state) { |
| 5226 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5227 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5228 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5229 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5230 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5231 | /* |
| 5232 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5233 | * So disable underrun reporting before all the planes get disabled. |
| 5234 | */ |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5235 | if (IS_GEN2(dev_priv) && old_primary_state->visible && |
| 5236 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5237 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5238 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5239 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5240 | /* Display WA 827 */ |
| 5241 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5242 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5243 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5244 | skl_wa_528(dev_priv, crtc->pipe, true); |
| 5245 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5246 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5247 | /* |
| 5248 | * Vblank time updates from the shadow to live plane control register |
| 5249 | * are blocked if the memory self-refresh mode is active at that |
| 5250 | * moment. So to make sure the plane gets truly disabled, disable |
| 5251 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5252 | * will be checked/applied by the HW only at the next frame start |
| 5253 | * event which is after the vblank start event, so we need to have a |
| 5254 | * wait-for-vblank between disabling the plane and the pipe. |
| 5255 | */ |
| 5256 | if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active && |
| 5257 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5258 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5259 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5260 | /* |
| 5261 | * IVB workaround: must disable low power watermarks for at least |
| 5262 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5263 | * when scaling is disabled. |
| 5264 | * |
| 5265 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5266 | */ |
Ville Syrjälä | ddd2b79 | 2016-11-28 19:37:04 +0200 | [diff] [blame] | 5267 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5268 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5269 | |
| 5270 | /* |
| 5271 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5272 | * watermark programming here. |
| 5273 | */ |
| 5274 | if (needs_modeset(&pipe_config->base)) |
| 5275 | return; |
| 5276 | |
| 5277 | /* |
| 5278 | * For platforms that support atomic watermarks, program the |
| 5279 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5280 | * will be the intermediate values that are safe for both pre- and |
| 5281 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5282 | * to the final 'target' values and we'll do this again to get the |
| 5283 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5284 | * will be the final target values which will get automatically latched |
| 5285 | * at vblank time; no further programming will be necessary. |
| 5286 | * |
| 5287 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5288 | * we'll continue to update watermarks the old way, if flags tell |
| 5289 | * us to. |
| 5290 | */ |
| 5291 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5292 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5293 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5294 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5295 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5296 | } |
| 5297 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 5298 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5299 | { |
| 5300 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5301 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 5302 | struct drm_plane *p; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5303 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5304 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5305 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5306 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 5307 | drm_for_each_plane_mask(p, dev, plane_mask) |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 5308 | to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5309 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5310 | /* |
| 5311 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 5312 | * to compute the mask of flip planes precisely. For the time being |
| 5313 | * consider this a flip to a NULL plane. |
| 5314 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5315 | intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5316 | } |
| 5317 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5318 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5319 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5320 | struct drm_atomic_state *old_state) |
| 5321 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5322 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5323 | struct drm_connector *conn; |
| 5324 | int i; |
| 5325 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5326 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5327 | struct intel_encoder *encoder = |
| 5328 | to_intel_encoder(conn_state->best_encoder); |
| 5329 | |
| 5330 | if (conn_state->crtc != crtc) |
| 5331 | continue; |
| 5332 | |
| 5333 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5334 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5339 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5340 | struct drm_atomic_state *old_state) |
| 5341 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5342 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5343 | struct drm_connector *conn; |
| 5344 | int i; |
| 5345 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5346 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5347 | struct intel_encoder *encoder = |
| 5348 | to_intel_encoder(conn_state->best_encoder); |
| 5349 | |
| 5350 | if (conn_state->crtc != crtc) |
| 5351 | continue; |
| 5352 | |
| 5353 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5354 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5355 | } |
| 5356 | } |
| 5357 | |
| 5358 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5359 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5360 | struct drm_atomic_state *old_state) |
| 5361 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5362 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5363 | struct drm_connector *conn; |
| 5364 | int i; |
| 5365 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5366 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5367 | struct intel_encoder *encoder = |
| 5368 | to_intel_encoder(conn_state->best_encoder); |
| 5369 | |
| 5370 | if (conn_state->crtc != crtc) |
| 5371 | continue; |
| 5372 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5373 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5374 | intel_opregion_notify_encoder(encoder, true); |
| 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5379 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5380 | struct drm_atomic_state *old_state) |
| 5381 | { |
| 5382 | struct drm_connector_state *old_conn_state; |
| 5383 | struct drm_connector *conn; |
| 5384 | int i; |
| 5385 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5386 | 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] | 5387 | struct intel_encoder *encoder = |
| 5388 | to_intel_encoder(old_conn_state->best_encoder); |
| 5389 | |
| 5390 | if (old_conn_state->crtc != crtc) |
| 5391 | continue; |
| 5392 | |
| 5393 | intel_opregion_notify_encoder(encoder, false); |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5394 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5399 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5400 | struct drm_atomic_state *old_state) |
| 5401 | { |
| 5402 | struct drm_connector_state *old_conn_state; |
| 5403 | struct drm_connector *conn; |
| 5404 | int i; |
| 5405 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5406 | 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] | 5407 | struct intel_encoder *encoder = |
| 5408 | to_intel_encoder(old_conn_state->best_encoder); |
| 5409 | |
| 5410 | if (old_conn_state->crtc != crtc) |
| 5411 | continue; |
| 5412 | |
| 5413 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5414 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5415 | } |
| 5416 | } |
| 5417 | |
| 5418 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5419 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5420 | struct drm_atomic_state *old_state) |
| 5421 | { |
| 5422 | struct drm_connector_state *old_conn_state; |
| 5423 | struct drm_connector *conn; |
| 5424 | int i; |
| 5425 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5426 | 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] | 5427 | struct intel_encoder *encoder = |
| 5428 | to_intel_encoder(old_conn_state->best_encoder); |
| 5429 | |
| 5430 | if (old_conn_state->crtc != crtc) |
| 5431 | continue; |
| 5432 | |
| 5433 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5434 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5435 | } |
| 5436 | } |
| 5437 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5438 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5439 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5440 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5441 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5442 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5443 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5444 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5445 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5446 | struct intel_atomic_state *old_intel_state = |
| 5447 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5448 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5449 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5450 | return; |
| 5451 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5452 | /* |
| 5453 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5454 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5455 | * |
| 5456 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5457 | * between eDP port A enable and vdd enable. Also PCH port |
| 5458 | * enable seems to result in the occasional CPU pipe underrun. |
| 5459 | * |
| 5460 | * Spurious PCH underruns also occur during PCH enabling. |
| 5461 | */ |
| 5462 | if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv)) |
| 5463 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5464 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5465 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5466 | |
| 5467 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5468 | intel_prepare_shared_dpll(intel_crtc); |
| 5469 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 5470 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5471 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5472 | |
| 5473 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 5474 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5475 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5476 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5477 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5478 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | ironlake_set_pipeconf(crtc); |
| 5482 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5483 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5484 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5485 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5486 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5487 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5488 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5489 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5490 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 5491 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5492 | } else { |
| 5493 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5494 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5495 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5496 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5497 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5498 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5499 | /* |
| 5500 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5501 | * clocks enabled |
| 5502 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5503 | intel_color_load_luts(&pipe_config->base); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5504 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5505 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5506 | dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5507 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5508 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5509 | if (intel_crtc->config->has_pch_encoder) |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 5510 | ironlake_pch_enable(pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5511 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5512 | assert_vblank_disabled(crtc); |
| 5513 | drm_crtc_vblank_on(crtc); |
| 5514 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5515 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5516 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5517 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5518 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5519 | |
| 5520 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ |
| 5521 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5522 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5523 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5524 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5527 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5528 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5529 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5530 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5531 | } |
| 5532 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5533 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5534 | enum pipe pipe, bool apply) |
| 5535 | { |
| 5536 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5537 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5538 | |
| 5539 | if (apply) |
| 5540 | val |= mask; |
| 5541 | else |
| 5542 | val &= ~mask; |
| 5543 | |
| 5544 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5545 | } |
| 5546 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5547 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5548 | { |
| 5549 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5550 | enum pipe pipe = crtc->pipe; |
| 5551 | uint32_t val; |
| 5552 | |
| 5553 | val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2); |
| 5554 | |
| 5555 | /* Program B credit equally to all pipes */ |
| 5556 | val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes); |
| 5557 | |
| 5558 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5559 | } |
| 5560 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5561 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5562 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5563 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5564 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5565 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5566 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5567 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5568 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5569 | struct intel_atomic_state *old_intel_state = |
| 5570 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5571 | bool psl_clkgate_wa; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5572 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5573 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5574 | return; |
| 5575 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5576 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5577 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 5578 | if (intel_crtc->config->shared_dpll) |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5579 | intel_enable_shared_dpll(intel_crtc); |
| 5580 | |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5581 | if (INTEL_GEN(dev_priv) >= 11) |
| 5582 | icl_map_plls_to_ports(crtc, pipe_config, old_state); |
| 5583 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame^] | 5584 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5585 | |
| 5586 | if (!transcoder_is_dsi(cpu_transcoder)) |
| 5587 | intel_ddi_enable_pipe_clock(pipe_config); |
| 5588 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 5589 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5590 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5591 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5592 | if (!transcoder_is_dsi(cpu_transcoder)) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5593 | intel_set_pipe_timings(intel_crtc); |
| 5594 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 5595 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5596 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5597 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5598 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5599 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5600 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5603 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5604 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5605 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5606 | } |
| 5607 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5608 | if (!transcoder_is_dsi(cpu_transcoder)) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5609 | haswell_set_pipeconf(crtc); |
| 5610 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 5611 | haswell_set_pipemisc(crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5612 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5613 | intel_color_set_csc(&pipe_config->base); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5614 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5615 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5616 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5617 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5618 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
| 5619 | intel_crtc->config->pch_pfit.enabled; |
| 5620 | if (psl_clkgate_wa) |
| 5621 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5622 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5623 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5624 | skylake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5625 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 5626 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5627 | |
| 5628 | /* |
| 5629 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5630 | * clocks enabled |
| 5631 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5632 | intel_color_load_luts(&pipe_config->base); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5633 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5634 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5635 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5636 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5637 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5638 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5639 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5640 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5641 | if (INTEL_GEN(dev_priv) >= 11) |
| 5642 | icl_pipe_mbus_enable(intel_crtc); |
| 5643 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5644 | /* 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] | 5645 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5646 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5647 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5648 | if (intel_crtc->config->has_pch_encoder) |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 5649 | lpt_pch_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5650 | |
Ville Syrjälä | 0037071 | 2016-11-14 19:44:06 +0200 | [diff] [blame] | 5651 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5652 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5653 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5654 | assert_vblank_disabled(crtc); |
| 5655 | drm_crtc_vblank_on(crtc); |
| 5656 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5657 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5658 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5659 | if (psl_clkgate_wa) { |
| 5660 | intel_wait_for_vblank(dev_priv, pipe); |
| 5661 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5662 | } |
| 5663 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5664 | /* If we change the relative order between pipe/planes enabling, we need |
| 5665 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5666 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5667 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5668 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5669 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5670 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5671 | } |
| 5672 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5673 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5674 | { |
| 5675 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5676 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5677 | int pipe = crtc->pipe; |
| 5678 | |
| 5679 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5680 | * it's in use. The hw state code will make sure we get this right. */ |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5681 | if (force || crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5682 | I915_WRITE(PF_CTL(pipe), 0); |
| 5683 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5684 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5685 | } |
| 5686 | } |
| 5687 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5688 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5689 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5690 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5691 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5692 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5693 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5694 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5695 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5696 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5697 | /* |
| 5698 | * Sometimes spurious CPU pipe underruns happen when the |
| 5699 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 5700 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 5701 | */ |
| 5702 | if (intel_crtc->config->has_pch_encoder) { |
| 5703 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5704 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5705 | } |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5706 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5707 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5708 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5709 | drm_crtc_vblank_off(crtc); |
| 5710 | assert_vblank_disabled(crtc); |
| 5711 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5712 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5713 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5714 | ironlake_pfit_disable(intel_crtc, false); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5715 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5716 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 5717 | ironlake_fdi_disable(crtc); |
| 5718 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5719 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5720 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5721 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5722 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5723 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5724 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5725 | i915_reg_t reg; |
| 5726 | u32 temp; |
| 5727 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5728 | /* disable TRANS_DP_CTL */ |
| 5729 | reg = TRANS_DP_CTL(pipe); |
| 5730 | temp = I915_READ(reg); |
| 5731 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5732 | TRANS_DP_PORT_SEL_MASK); |
| 5733 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5734 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5735 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5736 | /* disable DPLL_SEL */ |
| 5737 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5738 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5739 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5740 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5741 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5742 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5743 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5744 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5745 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5746 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5749 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5750 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5751 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5752 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5753 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5754 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5755 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5756 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5757 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5758 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5759 | drm_crtc_vblank_off(crtc); |
| 5760 | assert_vblank_disabled(crtc); |
| 5761 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5762 | /* 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] | 5763 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5764 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5765 | |
Ville Syrjälä | 0037071 | 2016-11-14 19:44:06 +0200 | [diff] [blame] | 5766 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5767 | intel_ddi_set_vc_payload_alloc(intel_crtc->config, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5768 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5769 | if (!transcoder_is_dsi(cpu_transcoder)) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5770 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5771 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5772 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5773 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5774 | else |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5775 | ironlake_pfit_disable(intel_crtc, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5776 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5777 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5778 | intel_ddi_disable_pipe_clock(intel_crtc->config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5779 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5780 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5781 | |
| 5782 | if (INTEL_GEN(dev_priv) >= 11) |
| 5783 | icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5784 | } |
| 5785 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5786 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5787 | { |
| 5788 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5789 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5790 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5791 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5792 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5793 | return; |
| 5794 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5795 | /* |
| 5796 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5797 | * according to register description and PRM. |
| 5798 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5799 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5800 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5801 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5802 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5803 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5804 | |
| 5805 | /* Border color in case we don't scale up to the full screen. Black by |
| 5806 | * default, change to something else for debugging. */ |
| 5807 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5808 | } |
| 5809 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 5810 | 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] | 5811 | { |
| 5812 | switch (port) { |
| 5813 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5814 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5815 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5816 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5817 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5818 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5819 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5820 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5821 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5822 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 5823 | case PORT_F: |
| 5824 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5825 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5826 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5827 | return POWER_DOMAIN_PORT_OTHER; |
| 5828 | } |
| 5829 | } |
| 5830 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5831 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 5832 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5833 | { |
| 5834 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5835 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5836 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5837 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5838 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5839 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5840 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5841 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5842 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5843 | return 0; |
| 5844 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 5845 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 5846 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5847 | if (crtc_state->pch_pfit.enabled || |
| 5848 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5849 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5850 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5851 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5852 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5853 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 5854 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5855 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5856 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5857 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 5858 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5859 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5860 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5861 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5862 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5863 | return mask; |
| 5864 | } |
| 5865 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 5866 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5867 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5868 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5869 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5870 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5871 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5872 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5873 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5874 | |
| 5875 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5876 | intel_crtc->enabled_power_domains = new_domains = |
| 5877 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5878 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5879 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5880 | |
| 5881 | for_each_power_domain(domain, domains) |
| 5882 | intel_display_power_get(dev_priv, domain); |
| 5883 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5884 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | 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] | 5888 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5889 | { |
| 5890 | enum intel_display_power_domain domain; |
| 5891 | |
| 5892 | for_each_power_domain(domain, domains) |
| 5893 | intel_display_power_put(dev_priv, domain); |
| 5894 | } |
| 5895 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5896 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5897 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5898 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5899 | struct intel_atomic_state *old_intel_state = |
| 5900 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5901 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5902 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5903 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5904 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5905 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5906 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5907 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5908 | return; |
| 5909 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 5910 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5911 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5912 | |
| 5913 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 5914 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5915 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5916 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5917 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 5918 | |
| 5919 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 5920 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 5921 | } |
| 5922 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5923 | i9xx_set_pipeconf(intel_crtc); |
| 5924 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5925 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5926 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5927 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5928 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5929 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5930 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5931 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 5932 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
| 5933 | chv_enable_pll(intel_crtc, intel_crtc->config); |
| 5934 | } else { |
| 5935 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
| 5936 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5937 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5938 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5939 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5940 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5941 | i9xx_pfit_enable(intel_crtc); |
| 5942 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5943 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5944 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 5945 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5946 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5947 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5948 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5949 | assert_vblank_disabled(crtc); |
| 5950 | drm_crtc_vblank_on(crtc); |
| 5951 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5952 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5953 | } |
| 5954 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5955 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 5956 | { |
| 5957 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5958 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5959 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5960 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 5961 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5962 | } |
| 5963 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5964 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5965 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5966 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 5967 | struct intel_atomic_state *old_intel_state = |
| 5968 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5969 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5970 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5971 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5972 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 5973 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5974 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5975 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5976 | return; |
| 5977 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5978 | i9xx_set_pll_dividers(intel_crtc); |
| 5979 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 5980 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5981 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5982 | |
| 5983 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 5984 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5985 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5986 | i9xx_set_pipeconf(intel_crtc); |
| 5987 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5988 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5989 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5990 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5991 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5992 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5993 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 5994 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 5995 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 5996 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5997 | i9xx_pfit_enable(intel_crtc); |
| 5998 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5999 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6000 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6001 | if (dev_priv->display.initial_watermarks != NULL) |
| 6002 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6003 | intel_crtc->config); |
| 6004 | else |
| 6005 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6006 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6007 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6008 | assert_vblank_disabled(crtc); |
| 6009 | drm_crtc_vblank_on(crtc); |
| 6010 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6011 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6012 | } |
| 6013 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6014 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 6015 | { |
| 6016 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6017 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6018 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6019 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6020 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6021 | |
| 6022 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6023 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6024 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6025 | I915_READ(PFIT_CONTROL)); |
| 6026 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6027 | } |
| 6028 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6029 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6030 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6031 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6032 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6033 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6034 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6035 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6036 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6037 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6038 | /* |
| 6039 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6040 | * wait for planes to fully turn off before disabling the pipe. |
| 6041 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6042 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6043 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6044 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6045 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6046 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6047 | drm_crtc_vblank_off(crtc); |
| 6048 | assert_vblank_disabled(crtc); |
| 6049 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6050 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6051 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6052 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6053 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6054 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6055 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 6056 | if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6057 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6058 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6059 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6060 | vlv_disable_pll(dev_priv, pipe); |
| 6061 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6062 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6063 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6064 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6065 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6066 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6067 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6068 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6069 | |
| 6070 | if (!dev_priv->display.initial_watermarks) |
| 6071 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6072 | |
| 6073 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6074 | if (IS_I830(dev_priv)) |
| 6075 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6076 | } |
| 6077 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6078 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6079 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6080 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6081 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6082 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6083 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6084 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6085 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6086 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6087 | struct drm_atomic_state *state; |
| 6088 | struct intel_crtc_state *crtc_state; |
| 6089 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6090 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6091 | if (!intel_crtc->active) |
| 6092 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6093 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6094 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6095 | const struct intel_plane_state *plane_state = |
| 6096 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6097 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6098 | if (plane_state->base.visible) |
| 6099 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6100 | } |
| 6101 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6102 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6103 | if (!state) { |
| 6104 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6105 | crtc->base.id, crtc->name); |
| 6106 | return; |
| 6107 | } |
| 6108 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6109 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6110 | |
| 6111 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6112 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6113 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6114 | |
| 6115 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6116 | |
| 6117 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6118 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6119 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6120 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6121 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6122 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6123 | |
| 6124 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6125 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6126 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6127 | crtc->enabled = false; |
| 6128 | crtc->state->connector_mask = 0; |
| 6129 | crtc->state->encoder_mask = 0; |
| 6130 | |
| 6131 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6132 | encoder->base.crtc = NULL; |
| 6133 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6134 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6135 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 1f7457b | 2015-07-13 11:55:05 +0200 | [diff] [blame] | 6136 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6137 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6138 | domains = intel_crtc->enabled_power_domains; |
| 6139 | for_each_power_domain(domain, domains) |
| 6140 | intel_display_power_put(dev_priv, domain); |
| 6141 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6142 | |
| 6143 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6144 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6145 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6146 | } |
| 6147 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6148 | /* |
| 6149 | * turn all crtc's off, but do not adjust state |
| 6150 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6151 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6152 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6153 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6154 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6155 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6156 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6157 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6158 | state = drm_atomic_helper_suspend(dev); |
| 6159 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6160 | if (ret) |
| 6161 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6162 | else |
| 6163 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6164 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6165 | } |
| 6166 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6167 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6168 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6169 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6170 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6171 | drm_encoder_cleanup(encoder); |
| 6172 | kfree(intel_encoder); |
| 6173 | } |
| 6174 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6175 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6176 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6177 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6178 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6179 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6180 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6181 | |
| 6182 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6183 | connector->base.base.id, |
| 6184 | connector->base.name); |
| 6185 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6186 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6187 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6188 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6189 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6190 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6191 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6192 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6193 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6194 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6195 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6196 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6197 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6198 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6199 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6200 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6201 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6202 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6203 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6204 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6205 | "attached encoder crtc differs from connector crtc\n"); |
| 6206 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6207 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6208 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6209 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6210 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6211 | } |
| 6212 | } |
| 6213 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6214 | int intel_connector_init(struct intel_connector *connector) |
| 6215 | { |
Maarten Lankhorst | 11c1a9e | 2017-05-01 15:37:57 +0200 | [diff] [blame] | 6216 | struct intel_digital_connector_state *conn_state; |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6217 | |
Maarten Lankhorst | 11c1a9e | 2017-05-01 15:37:57 +0200 | [diff] [blame] | 6218 | /* |
| 6219 | * Allocate enough memory to hold intel_digital_connector_state, |
| 6220 | * This might be a few bytes too many, but for connectors that don't |
| 6221 | * need it we'll free the state and allocate a smaller one on the first |
| 6222 | * succesful commit anyway. |
| 6223 | */ |
| 6224 | conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL); |
| 6225 | if (!conn_state) |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6226 | return -ENOMEM; |
| 6227 | |
Maarten Lankhorst | 11c1a9e | 2017-05-01 15:37:57 +0200 | [diff] [blame] | 6228 | __drm_atomic_helper_connector_reset(&connector->base, |
| 6229 | &conn_state->base); |
| 6230 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6231 | return 0; |
| 6232 | } |
| 6233 | |
| 6234 | struct intel_connector *intel_connector_alloc(void) |
| 6235 | { |
| 6236 | struct intel_connector *connector; |
| 6237 | |
| 6238 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6239 | if (!connector) |
| 6240 | return NULL; |
| 6241 | |
| 6242 | if (intel_connector_init(connector) < 0) { |
| 6243 | kfree(connector); |
| 6244 | return NULL; |
| 6245 | } |
| 6246 | |
| 6247 | return connector; |
| 6248 | } |
| 6249 | |
James Ausmus | 091a4f9 | 2017-10-13 11:01:44 -0700 | [diff] [blame] | 6250 | /* |
| 6251 | * Free the bits allocated by intel_connector_alloc. |
| 6252 | * This should only be used after intel_connector_alloc has returned |
| 6253 | * successfully, and before drm_connector_init returns successfully. |
| 6254 | * Otherwise the destroy callbacks for the connector and the state should |
| 6255 | * take care of proper cleanup/free |
| 6256 | */ |
| 6257 | void intel_connector_free(struct intel_connector *connector) |
| 6258 | { |
| 6259 | kfree(to_intel_digital_connector_state(connector->base.state)); |
| 6260 | kfree(connector); |
| 6261 | } |
| 6262 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6263 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6264 | * one connector and no cloning and hence the encoder state determines the state |
| 6265 | * of the connector. */ |
| 6266 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6267 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6268 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6269 | struct intel_encoder *encoder = connector->encoder; |
| 6270 | |
| 6271 | return encoder->get_hw_state(encoder, &pipe); |
| 6272 | } |
| 6273 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6274 | 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] | 6275 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6276 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6277 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6278 | |
| 6279 | return 0; |
| 6280 | } |
| 6281 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6282 | 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] | 6283 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6284 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6285 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6286 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6287 | struct intel_crtc *other_crtc; |
| 6288 | struct intel_crtc_state *other_crtc_state; |
| 6289 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6290 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6291 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6292 | if (pipe_config->fdi_lanes > 4) { |
| 6293 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6294 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6295 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6296 | } |
| 6297 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6298 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6299 | if (pipe_config->fdi_lanes > 2) { |
| 6300 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6301 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6302 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6303 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6304 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6305 | } |
| 6306 | } |
| 6307 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6308 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6309 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6310 | |
| 6311 | /* Ivybridge 3 pipe is really complicated */ |
| 6312 | switch (pipe) { |
| 6313 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6314 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6315 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6316 | if (pipe_config->fdi_lanes <= 2) |
| 6317 | return 0; |
| 6318 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6319 | 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] | 6320 | other_crtc_state = |
| 6321 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6322 | if (IS_ERR(other_crtc_state)) |
| 6323 | return PTR_ERR(other_crtc_state); |
| 6324 | |
| 6325 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6326 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6327 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6328 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6329 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6330 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6331 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6332 | if (pipe_config->fdi_lanes > 2) { |
| 6333 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6334 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6335 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6336 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6337 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6338 | 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] | 6339 | other_crtc_state = |
| 6340 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6341 | if (IS_ERR(other_crtc_state)) |
| 6342 | return PTR_ERR(other_crtc_state); |
| 6343 | |
| 6344 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6345 | 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] | 6346 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6347 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6348 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6349 | default: |
| 6350 | BUG(); |
| 6351 | } |
| 6352 | } |
| 6353 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6354 | #define RETRY 1 |
| 6355 | 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] | 6356 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6357 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6358 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6359 | 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] | 6360 | int lane, link_bw, fdi_dotclock, ret; |
| 6361 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6362 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6363 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6364 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6365 | * each output octet as 10 bits. The actual frequency |
| 6366 | * is stored as a divider into a 100MHz clock, and the |
| 6367 | * mode pixel clock is stored in units of 1KHz. |
| 6368 | * Hence the bw of each lane in terms of the mode signal |
| 6369 | * is: |
| 6370 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6371 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6372 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6373 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6374 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6375 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6376 | pipe_config->pipe_bpp); |
| 6377 | |
| 6378 | pipe_config->fdi_lanes = lane; |
| 6379 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6380 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6381 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6382 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6383 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6384 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6385 | pipe_config->pipe_bpp -= 2*3; |
| 6386 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6387 | pipe_config->pipe_bpp); |
| 6388 | needs_recompute = true; |
| 6389 | pipe_config->bw_constrained = true; |
| 6390 | |
| 6391 | goto retry; |
| 6392 | } |
| 6393 | |
| 6394 | if (needs_recompute) |
| 6395 | return RETRY; |
| 6396 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6397 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6398 | } |
| 6399 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6400 | 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] | 6401 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6402 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6403 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6404 | |
| 6405 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6406 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6407 | return false; |
| 6408 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6409 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6410 | return false; |
| 6411 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6412 | if (crtc_state->pipe_bpp > 24) |
| 6413 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6414 | |
| 6415 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6416 | * We compare against max which means we must take |
| 6417 | * the increased cdclk requirement into account when |
| 6418 | * calculating the new cdclk. |
| 6419 | * |
| 6420 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6421 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6422 | if (IS_BROADWELL(dev_priv) && |
| 6423 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6424 | return false; |
| 6425 | |
| 6426 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6427 | } |
| 6428 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6429 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6430 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6431 | struct drm_i915_private *dev_priv = |
| 6432 | to_i915(crtc_state->base.crtc->dev); |
| 6433 | struct intel_atomic_state *intel_state = |
| 6434 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6435 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6436 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6437 | return false; |
| 6438 | |
| 6439 | if (crtc_state->ips_force_disable) |
| 6440 | return false; |
| 6441 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6442 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6443 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6444 | return false; |
| 6445 | |
| 6446 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6447 | if (IS_BROADWELL(dev_priv) && |
| 6448 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6449 | return false; |
| 6450 | |
| 6451 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6452 | } |
| 6453 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6454 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6455 | { |
| 6456 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6457 | |
| 6458 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6459 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6460 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6461 | } |
| 6462 | |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6463 | static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
| 6464 | { |
| 6465 | uint32_t pixel_rate; |
| 6466 | |
| 6467 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6468 | |
| 6469 | /* |
| 6470 | * We only use IF-ID interlacing. If we ever use |
| 6471 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6472 | */ |
| 6473 | |
| 6474 | if (pipe_config->pch_pfit.enabled) { |
| 6475 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
| 6476 | uint32_t pfit_size = pipe_config->pch_pfit.size; |
| 6477 | |
| 6478 | pipe_w = pipe_config->pipe_src_w; |
| 6479 | pipe_h = pipe_config->pipe_src_h; |
| 6480 | |
| 6481 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6482 | pfit_h = pfit_size & 0xFFFF; |
| 6483 | if (pipe_w < pfit_w) |
| 6484 | pipe_w = pfit_w; |
| 6485 | if (pipe_h < pfit_h) |
| 6486 | pipe_h = pfit_h; |
| 6487 | |
| 6488 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6489 | return pixel_rate; |
| 6490 | |
| 6491 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 6492 | pfit_w * pfit_h); |
| 6493 | } |
| 6494 | |
| 6495 | return pixel_rate; |
| 6496 | } |
| 6497 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6498 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6499 | { |
| 6500 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6501 | |
| 6502 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 6503 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6504 | crtc_state->pixel_rate = |
| 6505 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6506 | else |
| 6507 | crtc_state->pixel_rate = |
| 6508 | ilk_pipe_pixel_rate(crtc_state); |
| 6509 | } |
| 6510 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6511 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6512 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6513 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6514 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6515 | struct drm_i915_private *dev_priv = to_i915(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; |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6517 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6518 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6519 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6520 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6521 | |
| 6522 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6523 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6524 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6525 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6526 | if (intel_crtc_supports_double_wide(crtc) && |
| 6527 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6528 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6529 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6530 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6531 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6532 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6533 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6534 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6535 | adjusted_mode->crtc_clock, clock_limit, |
| 6536 | yesno(pipe_config->double_wide)); |
| 6537 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6538 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6539 | |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6540 | if (pipe_config->ycbcr420 && pipe_config->base.ctm) { |
| 6541 | /* |
| 6542 | * There is only one pipe CSC unit per pipe, and we need that |
| 6543 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6544 | * applied we can't support YCBCR420 output. |
| 6545 | */ |
| 6546 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6547 | return -EINVAL; |
| 6548 | } |
| 6549 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6550 | /* |
| 6551 | * Pipe horizontal size must be even in: |
| 6552 | * - DVO ganged mode |
| 6553 | * - LVDS dual channel mode |
| 6554 | * - Double wide pipe |
| 6555 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6556 | if (pipe_config->pipe_src_w & 1) { |
| 6557 | if (pipe_config->double_wide) { |
| 6558 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6559 | return -EINVAL; |
| 6560 | } |
| 6561 | |
| 6562 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6563 | intel_is_dual_link_lvds(dev)) { |
| 6564 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6565 | return -EINVAL; |
| 6566 | } |
| 6567 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6568 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6569 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6570 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6571 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6572 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6573 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6574 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6575 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6576 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6577 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6578 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6579 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6580 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6581 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6582 | } |
| 6583 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6584 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6585 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6586 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6587 | while (*num > DATA_LINK_M_N_MASK || |
| 6588 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6589 | *num >>= 1; |
| 6590 | *den >>= 1; |
| 6591 | } |
| 6592 | } |
| 6593 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6594 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6595 | uint32_t *ret_m, uint32_t *ret_n, |
| 6596 | bool reduce_m_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6597 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6598 | /* |
| 6599 | * Reduce M/N as much as possible without loss in precision. Several DP |
| 6600 | * dongles in particular seem to be fussy about too large *link* M/N |
| 6601 | * values. The passed in values are more likely to have the least |
| 6602 | * significant bits zero than M after rounding below, so do this first. |
| 6603 | */ |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6604 | if (reduce_m_n) { |
| 6605 | while ((m & 1) == 0 && (n & 1) == 0) { |
| 6606 | m >>= 1; |
| 6607 | n >>= 1; |
| 6608 | } |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6609 | } |
| 6610 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6611 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 6612 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6613 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6614 | } |
| 6615 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6616 | void |
| 6617 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 6618 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6619 | struct intel_link_m_n *m_n, |
| 6620 | bool reduce_m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6621 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6622 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6623 | |
| 6624 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6625 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6626 | &m_n->gmch_m, &m_n->gmch_n, |
| 6627 | reduce_m_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6628 | |
| 6629 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6630 | &m_n->link_m, &m_n->link_n, |
| 6631 | reduce_m_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6632 | } |
| 6633 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6634 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6635 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6636 | if (i915_modparams.panel_use_ssc >= 0) |
| 6637 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6638 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6639 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6640 | } |
| 6641 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6642 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6643 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6644 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6645 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6646 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6647 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6648 | { |
| 6649 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6650 | } |
| 6651 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6652 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6653 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6654 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6655 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6656 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6657 | u32 fp, fp2 = 0; |
| 6658 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6659 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6660 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6661 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6662 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6663 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6664 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6665 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6666 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6667 | } |
| 6668 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6669 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6670 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6671 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6672 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6673 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6674 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6675 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6676 | } |
| 6677 | } |
| 6678 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6679 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6680 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6681 | { |
| 6682 | u32 reg_val; |
| 6683 | |
| 6684 | /* |
| 6685 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6686 | * and set it to a reasonable value instead. |
| 6687 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6688 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6689 | reg_val &= 0xffffff00; |
| 6690 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6691 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6692 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6693 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 6694 | reg_val &= 0x00ffffff; |
| 6695 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6696 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6697 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6698 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6699 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6700 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6701 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6702 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6703 | reg_val &= 0x00ffffff; |
| 6704 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6705 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6706 | } |
| 6707 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6708 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 6709 | struct intel_link_m_n *m_n) |
| 6710 | { |
| 6711 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6712 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6713 | int pipe = crtc->pipe; |
| 6714 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6715 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6716 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6717 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6718 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6722 | struct intel_link_m_n *m_n, |
| 6723 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6724 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6725 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6726 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6727 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6728 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6729 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6730 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6731 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6732 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6733 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6734 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 6735 | * for gen < 8) and if DRRS is supported (to make sure the |
| 6736 | * registers are not unnecessarily accessed). |
| 6737 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6738 | if (m2_n2 && (IS_CHERRYVIEW(dev_priv) || |
| 6739 | INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6740 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6741 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6742 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6743 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6744 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6745 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6746 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6747 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6748 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6749 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6750 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6751 | } |
| 6752 | } |
| 6753 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6754 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6755 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6756 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 6757 | |
| 6758 | if (m_n == M1_N1) { |
| 6759 | dp_m_n = &crtc->config->dp_m_n; |
| 6760 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 6761 | } else if (m_n == M2_N2) { |
| 6762 | |
| 6763 | /* |
| 6764 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6765 | * needs to be programmed into M1_N1. |
| 6766 | */ |
| 6767 | dp_m_n = &crtc->config->dp_m2_n2; |
| 6768 | } else { |
| 6769 | DRM_ERROR("Unsupported divider value\n"); |
| 6770 | return; |
| 6771 | } |
| 6772 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6773 | if (crtc->config->has_pch_encoder) |
| 6774 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6775 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6776 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6777 | } |
| 6778 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 6779 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 6780 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6781 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6782 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6783 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6784 | if (crtc->pipe != PIPE_A) |
| 6785 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6786 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6787 | /* 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] | 6788 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6789 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 6790 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 6791 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6792 | pipe_config->dpll_hw_state.dpll_md = |
| 6793 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 6794 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6795 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6796 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 6797 | struct intel_crtc_state *pipe_config) |
| 6798 | { |
| 6799 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6800 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6801 | if (crtc->pipe != PIPE_A) |
| 6802 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6803 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6804 | /* 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] | 6805 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6806 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 6807 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6808 | pipe_config->dpll_hw_state.dpll_md = |
| 6809 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6810 | } |
| 6811 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6812 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6813 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6814 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6815 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6816 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6817 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6818 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6819 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6820 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6821 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6822 | /* Enable Refclk */ |
| 6823 | I915_WRITE(DPLL(pipe), |
| 6824 | pipe_config->dpll_hw_state.dpll & |
| 6825 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 6826 | |
| 6827 | /* No need to actually set up the DPLL with DSI */ |
| 6828 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 6829 | return; |
| 6830 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6831 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6832 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6833 | bestn = pipe_config->dpll.n; |
| 6834 | bestm1 = pipe_config->dpll.m1; |
| 6835 | bestm2 = pipe_config->dpll.m2; |
| 6836 | bestp1 = pipe_config->dpll.p1; |
| 6837 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6838 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6839 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6840 | |
| 6841 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6842 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6843 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6844 | |
| 6845 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6846 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6847 | |
| 6848 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6849 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6850 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6851 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6852 | |
| 6853 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6854 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6855 | |
| 6856 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6857 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6858 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6859 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6860 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6861 | |
| 6862 | /* |
| 6863 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6864 | * but we don't support that). |
| 6865 | * Note: don't use the DAC post divider as it seems unstable. |
| 6866 | */ |
| 6867 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6868 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6869 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6870 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6871 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6872 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6873 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6874 | if (pipe_config->port_clock == 162000 || |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6875 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) || |
| 6876 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6877 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6878 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6879 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6880 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6881 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6882 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 6883 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6884 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6885 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6886 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6887 | 0x0df40000); |
| 6888 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6889 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6890 | 0x0df70000); |
| 6891 | } else { /* HDMI or VGA */ |
| 6892 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6893 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6894 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6895 | 0x0df70000); |
| 6896 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6897 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6898 | 0x0df40000); |
| 6899 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6900 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6901 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6902 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ville Syrjälä | 2210ce7 | 2016-06-22 21:57:05 +0300 | [diff] [blame] | 6903 | if (intel_crtc_has_dp_encoder(crtc->config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6904 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6905 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6906 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6907 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6908 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6909 | } |
| 6910 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6911 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6912 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6913 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6914 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6915 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6916 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6917 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6918 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6919 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6920 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6921 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6922 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6923 | /* Enable Refclk and SSC */ |
| 6924 | I915_WRITE(DPLL(pipe), |
| 6925 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 6926 | |
| 6927 | /* No need to actually set up the DPLL with DSI */ |
| 6928 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 6929 | return; |
| 6930 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6931 | bestn = pipe_config->dpll.n; |
| 6932 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 6933 | bestm1 = pipe_config->dpll.m1; |
| 6934 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 6935 | bestp1 = pipe_config->dpll.p1; |
| 6936 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6937 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6938 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6939 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6940 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6941 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6942 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6943 | /* p1 and p2 divider */ |
| 6944 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 6945 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 6946 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 6947 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 6948 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 6949 | |
| 6950 | /* Feedback post-divider - m2 */ |
| 6951 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 6952 | |
| 6953 | /* Feedback refclk divider - n and m1 */ |
| 6954 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 6955 | DPIO_CHV_M1_DIV_BY_2 | |
| 6956 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 6957 | |
| 6958 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 6959 | 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] | 6960 | |
| 6961 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6962 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 6963 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 6964 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 6965 | if (bestm2_frac) |
| 6966 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 6967 | 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] | 6968 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 6969 | /* Program digital lock detect threshold */ |
| 6970 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 6971 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 6972 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 6973 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 6974 | if (!bestm2_frac) |
| 6975 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 6976 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 6977 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6978 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6979 | if (vco == 5400000) { |
| 6980 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6981 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6982 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6983 | tribuf_calcntr = 0x9; |
| 6984 | } else if (vco <= 6200000) { |
| 6985 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6986 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 6987 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6988 | tribuf_calcntr = 0x9; |
| 6989 | } else if (vco <= 6480000) { |
| 6990 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6991 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6992 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6993 | tribuf_calcntr = 0x8; |
| 6994 | } else { |
| 6995 | /* Not supported. Apply the same limits as in the max case */ |
| 6996 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6997 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6998 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6999 | tribuf_calcntr = 0; |
| 7000 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7001 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7002 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7003 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7004 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7005 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7006 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7007 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7008 | /* AFC Recal */ |
| 7009 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7010 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7011 | DPIO_AFC_RECAL); |
| 7012 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7013 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7014 | } |
| 7015 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7016 | /** |
| 7017 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7018 | * @dev_priv: i915 private structure |
| 7019 | * @pipe: pipe PLL to enable |
| 7020 | * @dpll: PLL configuration |
| 7021 | * |
| 7022 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7023 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7024 | * be enabled. |
| 7025 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7026 | 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] | 7027 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7028 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7029 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7030 | struct intel_crtc_state *pipe_config; |
| 7031 | |
| 7032 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7033 | if (!pipe_config) |
| 7034 | return -ENOMEM; |
| 7035 | |
| 7036 | pipe_config->base.crtc = &crtc->base; |
| 7037 | pipe_config->pixel_multiplier = 1; |
| 7038 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7039 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7040 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7041 | chv_compute_dpll(crtc, pipe_config); |
| 7042 | chv_prepare_pll(crtc, pipe_config); |
| 7043 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7044 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7045 | vlv_compute_dpll(crtc, pipe_config); |
| 7046 | vlv_prepare_pll(crtc, pipe_config); |
| 7047 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7048 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7049 | |
| 7050 | kfree(pipe_config); |
| 7051 | |
| 7052 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | /** |
| 7056 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7057 | * @dev_priv: i915 private structure |
| 7058 | * @pipe: pipe PLL to disable |
| 7059 | * |
| 7060 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7061 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7062 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7063 | 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] | 7064 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7065 | if (IS_CHERRYVIEW(dev_priv)) |
| 7066 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7067 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7068 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7069 | } |
| 7070 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7071 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7072 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7073 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7074 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7075 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7076 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7077 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7078 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7079 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7080 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7081 | dpll = DPLL_VGA_MODE_DIS; |
| 7082 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7083 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7084 | dpll |= DPLLB_MODE_LVDS; |
| 7085 | else |
| 7086 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7087 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7088 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7089 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7090 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7091 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7092 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7093 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7094 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7095 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7096 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7097 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7098 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7099 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7100 | |
| 7101 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7102 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7103 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7104 | else { |
| 7105 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7106 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7107 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7108 | } |
| 7109 | switch (clock->p2) { |
| 7110 | case 5: |
| 7111 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7112 | break; |
| 7113 | case 7: |
| 7114 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7115 | break; |
| 7116 | case 10: |
| 7117 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7118 | break; |
| 7119 | case 14: |
| 7120 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7121 | break; |
| 7122 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7123 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7124 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7125 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7126 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7127 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7128 | 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] | 7129 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7130 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7131 | else |
| 7132 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7133 | |
| 7134 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7135 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7136 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7137 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7138 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7139 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7140 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7144 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7145 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7146 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7147 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7148 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7149 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7150 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7151 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7152 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7153 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7154 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7155 | dpll = DPLL_VGA_MODE_DIS; |
| 7156 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7157 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7158 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7159 | } else { |
| 7160 | if (clock->p1 == 2) |
| 7161 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7162 | else |
| 7163 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7164 | if (clock->p2 == 4) |
| 7165 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7166 | } |
| 7167 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7168 | if (!IS_I830(dev_priv) && |
| 7169 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7170 | dpll |= DPLL_DVO_2X_MODE; |
| 7171 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7172 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7173 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7174 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7175 | else |
| 7176 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7177 | |
| 7178 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7179 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7180 | } |
| 7181 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7182 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7183 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7184 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7185 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7186 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 7187 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7188 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7189 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7190 | |
| 7191 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7192 | * the hw state checker will get angry at the mismatch. */ |
| 7193 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7194 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7195 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7196 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7197 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7198 | crtc_vtotal -= 1; |
| 7199 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7200 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7201 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7202 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7203 | else |
| 7204 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7205 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7206 | if (vsyncshift < 0) |
| 7207 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7208 | } |
| 7209 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7210 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7211 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7212 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7213 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7214 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7215 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7216 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7217 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7218 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7219 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7220 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7221 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7222 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7223 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7224 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7225 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7226 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7227 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7228 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7229 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7230 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7231 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7232 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7233 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7234 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7235 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7236 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7237 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7238 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7239 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7240 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) |
| 7244 | { |
| 7245 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7246 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7247 | enum pipe pipe = intel_crtc->pipe; |
| 7248 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7249 | /* pipesrc controls the size that is scaled from, which should |
| 7250 | * always be the user's requested size. |
| 7251 | */ |
| 7252 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7253 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 7254 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7255 | } |
| 7256 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7257 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7258 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7259 | { |
| 7260 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7261 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7262 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7263 | uint32_t tmp; |
| 7264 | |
| 7265 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7266 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7267 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7268 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7269 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7270 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7271 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7272 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7273 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7274 | |
| 7275 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7276 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7277 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7278 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7279 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7280 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7281 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7282 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7283 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7284 | |
| 7285 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7286 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7287 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7288 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7289 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7290 | } |
| 7291 | |
| 7292 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7293 | struct intel_crtc_state *pipe_config) |
| 7294 | { |
| 7295 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7296 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7297 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7298 | |
| 7299 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7300 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7301 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7302 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7303 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7304 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7305 | } |
| 7306 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7307 | 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] | 7308 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7309 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7310 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7311 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7312 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7313 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7314 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7315 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7316 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7317 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7318 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7319 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7320 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7321 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7322 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7323 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7324 | |
| 7325 | mode->hsync = drm_mode_hsync(mode); |
| 7326 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7327 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7328 | } |
| 7329 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7330 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 7331 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7332 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7333 | uint32_t pipeconf; |
| 7334 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7335 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7336 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7337 | /* we keep both pipes enabled on 830 */ |
| 7338 | if (IS_I830(dev_priv)) |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 7339 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7340 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7341 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7342 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7343 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7344 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7345 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7346 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7347 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7348 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7349 | pipeconf |= PIPECONF_DITHER_EN | |
| 7350 | PIPECONF_DITHER_TYPE_SP; |
| 7351 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7352 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7353 | case 18: |
| 7354 | pipeconf |= PIPECONF_6BPC; |
| 7355 | break; |
| 7356 | case 24: |
| 7357 | pipeconf |= PIPECONF_8BPC; |
| 7358 | break; |
| 7359 | case 30: |
| 7360 | pipeconf |= PIPECONF_10BPC; |
| 7361 | break; |
| 7362 | default: |
| 7363 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7364 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7365 | } |
| 7366 | } |
| 7367 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7368 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7369 | if (INTEL_GEN(dev_priv) < 4 || |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7370 | intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7371 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7372 | else |
| 7373 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7374 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7375 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7376 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7377 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7378 | intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7379 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7380 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7381 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 7382 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 7383 | } |
| 7384 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7385 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7386 | struct intel_crtc_state *crtc_state) |
| 7387 | { |
| 7388 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7389 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7390 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7391 | int refclk = 48000; |
| 7392 | |
| 7393 | memset(&crtc_state->dpll_hw_state, 0, |
| 7394 | sizeof(crtc_state->dpll_hw_state)); |
| 7395 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7396 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7397 | if (intel_panel_use_ssc(dev_priv)) { |
| 7398 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7399 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7400 | } |
| 7401 | |
| 7402 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7403 | } 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] | 7404 | limit = &intel_limits_i8xx_dvo; |
| 7405 | } else { |
| 7406 | limit = &intel_limits_i8xx_dac; |
| 7407 | } |
| 7408 | |
| 7409 | if (!crtc_state->clock_set && |
| 7410 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7411 | refclk, NULL, &crtc_state->dpll)) { |
| 7412 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7413 | return -EINVAL; |
| 7414 | } |
| 7415 | |
| 7416 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7417 | |
| 7418 | return 0; |
| 7419 | } |
| 7420 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7421 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7422 | struct intel_crtc_state *crtc_state) |
| 7423 | { |
| 7424 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7425 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7426 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7427 | int refclk = 96000; |
| 7428 | |
| 7429 | memset(&crtc_state->dpll_hw_state, 0, |
| 7430 | sizeof(crtc_state->dpll_hw_state)); |
| 7431 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7432 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7433 | if (intel_panel_use_ssc(dev_priv)) { |
| 7434 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7435 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7436 | } |
| 7437 | |
| 7438 | if (intel_is_dual_link_lvds(dev)) |
| 7439 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7440 | else |
| 7441 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7442 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7443 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7444 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7445 | } 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] | 7446 | limit = &intel_limits_g4x_sdvo; |
| 7447 | } else { |
| 7448 | /* The option is for other outputs */ |
| 7449 | limit = &intel_limits_i9xx_sdvo; |
| 7450 | } |
| 7451 | |
| 7452 | if (!crtc_state->clock_set && |
| 7453 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7454 | refclk, NULL, &crtc_state->dpll)) { |
| 7455 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7456 | return -EINVAL; |
| 7457 | } |
| 7458 | |
| 7459 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7460 | |
| 7461 | return 0; |
| 7462 | } |
| 7463 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7464 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7465 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7466 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7467 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7468 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7469 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7470 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7471 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7472 | memset(&crtc_state->dpll_hw_state, 0, |
| 7473 | sizeof(crtc_state->dpll_hw_state)); |
| 7474 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7475 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7476 | if (intel_panel_use_ssc(dev_priv)) { |
| 7477 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7478 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7479 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7480 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7481 | limit = &intel_limits_pineview_lvds; |
| 7482 | } else { |
| 7483 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7484 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7485 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7486 | if (!crtc_state->clock_set && |
| 7487 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7488 | refclk, NULL, &crtc_state->dpll)) { |
| 7489 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7490 | return -EINVAL; |
| 7491 | } |
| 7492 | |
| 7493 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7494 | |
| 7495 | return 0; |
| 7496 | } |
| 7497 | |
| 7498 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7499 | struct intel_crtc_state *crtc_state) |
| 7500 | { |
| 7501 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7502 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7503 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7504 | int refclk = 96000; |
| 7505 | |
| 7506 | memset(&crtc_state->dpll_hw_state, 0, |
| 7507 | sizeof(crtc_state->dpll_hw_state)); |
| 7508 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7509 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7510 | if (intel_panel_use_ssc(dev_priv)) { |
| 7511 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7512 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7513 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7514 | |
| 7515 | limit = &intel_limits_i9xx_lvds; |
| 7516 | } else { |
| 7517 | limit = &intel_limits_i9xx_sdvo; |
| 7518 | } |
| 7519 | |
| 7520 | if (!crtc_state->clock_set && |
| 7521 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7522 | refclk, NULL, &crtc_state->dpll)) { |
| 7523 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7524 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7525 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7526 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7527 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7528 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7529 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7530 | } |
| 7531 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7532 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7533 | struct intel_crtc_state *crtc_state) |
| 7534 | { |
| 7535 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7536 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7537 | |
| 7538 | memset(&crtc_state->dpll_hw_state, 0, |
| 7539 | sizeof(crtc_state->dpll_hw_state)); |
| 7540 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7541 | if (!crtc_state->clock_set && |
| 7542 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7543 | refclk, NULL, &crtc_state->dpll)) { |
| 7544 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7545 | return -EINVAL; |
| 7546 | } |
| 7547 | |
| 7548 | chv_compute_dpll(crtc, crtc_state); |
| 7549 | |
| 7550 | return 0; |
| 7551 | } |
| 7552 | |
| 7553 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7554 | struct intel_crtc_state *crtc_state) |
| 7555 | { |
| 7556 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7557 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7558 | |
| 7559 | memset(&crtc_state->dpll_hw_state, 0, |
| 7560 | sizeof(crtc_state->dpll_hw_state)); |
| 7561 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7562 | if (!crtc_state->clock_set && |
| 7563 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7564 | refclk, NULL, &crtc_state->dpll)) { |
| 7565 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7566 | return -EINVAL; |
| 7567 | } |
| 7568 | |
| 7569 | vlv_compute_dpll(crtc, crtc_state); |
| 7570 | |
| 7571 | return 0; |
| 7572 | } |
| 7573 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7574 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7575 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7576 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7577 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7578 | uint32_t tmp; |
| 7579 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7580 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7581 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7582 | return; |
| 7583 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7584 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7585 | if (!(tmp & PFIT_ENABLE)) |
| 7586 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7587 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7588 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7589 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7590 | if (crtc->pipe != PIPE_B) |
| 7591 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7592 | } else { |
| 7593 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7594 | return; |
| 7595 | } |
| 7596 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7597 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7598 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7599 | } |
| 7600 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7601 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7602 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7603 | { |
| 7604 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7605 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7606 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7607 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7608 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7609 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7610 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7611 | /* In case of DSI, DPLL will not be used */ |
| 7612 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7613 | return; |
| 7614 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7615 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7616 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7617 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7618 | |
| 7619 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7620 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7621 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7622 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7623 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7624 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7625 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7626 | } |
| 7627 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7628 | static void |
| 7629 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7630 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7631 | { |
| 7632 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7633 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7634 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7635 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
| 7636 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7637 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7638 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7639 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7640 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7641 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7642 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7643 | if (!plane->get_hw_state(plane)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7644 | return; |
| 7645 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7646 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7647 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7648 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7649 | return; |
| 7650 | } |
| 7651 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7652 | fb = &intel_fb->base; |
| 7653 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7654 | fb->dev = dev; |
| 7655 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7656 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7657 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7658 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7659 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7660 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7661 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7662 | } |
| 7663 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7664 | |
| 7665 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7666 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 7667 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7668 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 7669 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 7670 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 7671 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 7672 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7673 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7674 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7675 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7676 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 7677 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7678 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7679 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7680 | } |
| 7681 | plane_config->base = base; |
| 7682 | |
| 7683 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7684 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7685 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7686 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7687 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7688 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7689 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 7690 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7691 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7692 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7693 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7694 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7695 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 7696 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7697 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7698 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7699 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7700 | } |
| 7701 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7702 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7703 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7704 | { |
| 7705 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7706 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7707 | int pipe = pipe_config->cpu_transcoder; |
| 7708 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7709 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7710 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7711 | int refclk = 100000; |
| 7712 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7713 | /* In case of DSI, DPLL will not be used */ |
| 7714 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7715 | return; |
| 7716 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7717 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7718 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7719 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7720 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7721 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7722 | 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] | 7723 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7724 | |
| 7725 | 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] | 7726 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 7727 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 7728 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7729 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7730 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7731 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7732 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7733 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7734 | } |
| 7735 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7736 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7737 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7738 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7739 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7740 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7741 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7742 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7743 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7744 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 7745 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7746 | return false; |
| 7747 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7748 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 7749 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7750 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7751 | ret = false; |
| 7752 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7753 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7754 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7755 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7756 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7757 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7758 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7759 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7760 | case PIPECONF_6BPC: |
| 7761 | pipe_config->pipe_bpp = 18; |
| 7762 | break; |
| 7763 | case PIPECONF_8BPC: |
| 7764 | pipe_config->pipe_bpp = 24; |
| 7765 | break; |
| 7766 | case PIPECONF_10BPC: |
| 7767 | pipe_config->pipe_bpp = 30; |
| 7768 | break; |
| 7769 | default: |
| 7770 | break; |
| 7771 | } |
| 7772 | } |
| 7773 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7774 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7775 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7776 | pipe_config->limited_color_range = true; |
| 7777 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7778 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 7779 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 7780 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7781 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7782 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7783 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7784 | i9xx_get_pfit_config(crtc, pipe_config); |
| 7785 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7786 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 7787 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7788 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 7789 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 7790 | else |
| 7791 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7792 | pipe_config->pixel_multiplier = |
| 7793 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 7794 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7795 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7796 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7797 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7798 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 7799 | pipe_config->pixel_multiplier = |
| 7800 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 7801 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 7802 | } else { |
| 7803 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 7804 | * port and will be fixed up in the encoder->get_config |
| 7805 | * function. */ |
| 7806 | pipe_config->pixel_multiplier = 1; |
| 7807 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7808 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7809 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7810 | /* |
| 7811 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 7812 | * on 830. Filter it out here so that we don't |
| 7813 | * report errors due to that. |
| 7814 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7815 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7816 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 7817 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7818 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 7819 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 7820 | } else { |
| 7821 | /* Mask out read-only status bits. */ |
| 7822 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 7823 | DPLL_PORTC_READY_MASK | |
| 7824 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7825 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7826 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7827 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7828 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 7829 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7830 | vlv_crtc_clock_get(crtc, pipe_config); |
| 7831 | else |
| 7832 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7833 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 7834 | /* |
| 7835 | * Normally the dotclock is filled in by the encoder .get_config() |
| 7836 | * but in case the pipe is enabled w/o any ports we need a sane |
| 7837 | * default. |
| 7838 | */ |
| 7839 | pipe_config->base.adjusted_mode.crtc_clock = |
| 7840 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 7841 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7842 | ret = true; |
| 7843 | |
| 7844 | out: |
| 7845 | intel_display_power_put(dev_priv, power_domain); |
| 7846 | |
| 7847 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7848 | } |
| 7849 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 7850 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7851 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7852 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7853 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7854 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7855 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7856 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7857 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7858 | bool has_ck505 = false; |
| 7859 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7860 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7861 | |
| 7862 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 7863 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7864 | switch (encoder->type) { |
| 7865 | case INTEL_OUTPUT_LVDS: |
| 7866 | has_panel = true; |
| 7867 | has_lvds = true; |
| 7868 | break; |
| 7869 | case INTEL_OUTPUT_EDP: |
| 7870 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 7871 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7872 | has_cpu_edp = true; |
| 7873 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7874 | default: |
| 7875 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7876 | } |
| 7877 | } |
| 7878 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7879 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7880 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7881 | can_ssc = has_ck505; |
| 7882 | } else { |
| 7883 | has_ck505 = false; |
| 7884 | can_ssc = true; |
| 7885 | } |
| 7886 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7887 | /* Check if any DPLLs are using the SSC source */ |
| 7888 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 7889 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 7890 | |
| 7891 | if (!(temp & DPLL_VCO_ENABLE)) |
| 7892 | continue; |
| 7893 | |
| 7894 | if ((temp & PLL_REF_INPUT_MASK) == |
| 7895 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 7896 | using_ssc_source = true; |
| 7897 | break; |
| 7898 | } |
| 7899 | } |
| 7900 | |
| 7901 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 7902 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7903 | |
| 7904 | /* Ironlake: try to setup display ref clock before DPLL |
| 7905 | * enabling. This is only under driver's control after |
| 7906 | * PCH B stepping, previous chipset stepping should be |
| 7907 | * ignoring this setting. |
| 7908 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7909 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7910 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7911 | /* As we must carefully and slowly disable/enable each source in turn, |
| 7912 | * compute the final state we want first and check if we need to |
| 7913 | * make any changes at all. |
| 7914 | */ |
| 7915 | final = val; |
| 7916 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7917 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7918 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7919 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7920 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7921 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 7922 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7923 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 7924 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7925 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7926 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7927 | final |= DREF_SSC_SOURCE_ENABLE; |
| 7928 | |
| 7929 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7930 | final |= DREF_SSC1_ENABLE; |
| 7931 | |
| 7932 | if (has_cpu_edp) { |
| 7933 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7934 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 7935 | else |
| 7936 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 7937 | } else |
| 7938 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7939 | } else if (using_ssc_source) { |
| 7940 | final |= DREF_SSC_SOURCE_ENABLE; |
| 7941 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7942 | } |
| 7943 | |
| 7944 | if (final == val) |
| 7945 | return; |
| 7946 | |
| 7947 | /* Always enable nonspread source */ |
| 7948 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 7949 | |
| 7950 | if (has_ck505) |
| 7951 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 7952 | else |
| 7953 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7954 | |
| 7955 | if (has_panel) { |
| 7956 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7957 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7958 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7959 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7960 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7961 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7962 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 7963 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7964 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7965 | |
| 7966 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7967 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7968 | POSTING_READ(PCH_DREF_CONTROL); |
| 7969 | udelay(200); |
| 7970 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7971 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7972 | |
| 7973 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7974 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7975 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7976 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7977 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7978 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7979 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7980 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7981 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7982 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7983 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7984 | POSTING_READ(PCH_DREF_CONTROL); |
| 7985 | udelay(200); |
| 7986 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7987 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7988 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7989 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7990 | |
| 7991 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7992 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7993 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7994 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7995 | POSTING_READ(PCH_DREF_CONTROL); |
| 7996 | udelay(200); |
| 7997 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7998 | if (!using_ssc_source) { |
| 7999 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8000 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8001 | /* Turn off the SSC source */ |
| 8002 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8003 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8004 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8005 | /* Turn off SSC1 */ |
| 8006 | val &= ~DREF_SSC1_ENABLE; |
| 8007 | |
| 8008 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8009 | POSTING_READ(PCH_DREF_CONTROL); |
| 8010 | udelay(200); |
| 8011 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8012 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8013 | |
| 8014 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8015 | } |
| 8016 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8017 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8018 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8019 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8020 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8021 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8022 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8023 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8024 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8025 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8026 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8027 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8028 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8029 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8030 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8031 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8032 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8033 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8034 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8035 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8036 | } |
| 8037 | |
| 8038 | /* WaMPhyProgramming:hsw */ |
| 8039 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8040 | { |
| 8041 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8042 | |
| 8043 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8044 | tmp &= ~(0xFF << 24); |
| 8045 | tmp |= (0x12 << 24); |
| 8046 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8047 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8048 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8049 | tmp |= (1 << 11); |
| 8050 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8051 | |
| 8052 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8053 | tmp |= (1 << 11); |
| 8054 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8055 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8056 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8057 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8058 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8059 | |
| 8060 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8061 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8062 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8063 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8064 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8065 | tmp &= ~(7 << 13); |
| 8066 | tmp |= (5 << 13); |
| 8067 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8068 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8069 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8070 | tmp &= ~(7 << 13); |
| 8071 | tmp |= (5 << 13); |
| 8072 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8073 | |
| 8074 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8075 | tmp &= ~0xFF; |
| 8076 | tmp |= 0x1C; |
| 8077 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8078 | |
| 8079 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8080 | tmp &= ~0xFF; |
| 8081 | tmp |= 0x1C; |
| 8082 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8083 | |
| 8084 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8085 | tmp &= ~(0xFF << 16); |
| 8086 | tmp |= (0x1C << 16); |
| 8087 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8088 | |
| 8089 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8090 | tmp &= ~(0xFF << 16); |
| 8091 | tmp |= (0x1C << 16); |
| 8092 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8093 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8094 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8095 | tmp |= (1 << 27); |
| 8096 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8097 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8098 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8099 | tmp |= (1 << 27); |
| 8100 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8101 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8102 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8103 | tmp &= ~(0xF << 28); |
| 8104 | tmp |= (4 << 28); |
| 8105 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8106 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8107 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8108 | tmp &= ~(0xF << 28); |
| 8109 | tmp |= (4 << 28); |
| 8110 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8111 | } |
| 8112 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8113 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8114 | * Programming" based on the parameters passed: |
| 8115 | * - Sequence to enable CLKOUT_DP |
| 8116 | * - Sequence to enable CLKOUT_DP without spread |
| 8117 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8118 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8119 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8120 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8121 | { |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8122 | uint32_t reg, tmp; |
| 8123 | |
| 8124 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8125 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8126 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8127 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8128 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8129 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8130 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8131 | |
| 8132 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8133 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8134 | tmp |= SBI_SSCCTL_PATHALT; |
| 8135 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8136 | |
| 8137 | udelay(24); |
| 8138 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8139 | if (with_spread) { |
| 8140 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8141 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8142 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8143 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8144 | if (with_fdi) { |
| 8145 | lpt_reset_fdi_mphy(dev_priv); |
| 8146 | lpt_program_fdi_mphy(dev_priv); |
| 8147 | } |
| 8148 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8149 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8150 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8151 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8152 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8153 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8154 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8155 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8156 | } |
| 8157 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8158 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8159 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8160 | { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8161 | uint32_t reg, tmp; |
| 8162 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8163 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8164 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8165 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8166 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8167 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8168 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8169 | |
| 8170 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8171 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8172 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8173 | tmp |= SBI_SSCCTL_PATHALT; |
| 8174 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8175 | udelay(32); |
| 8176 | } |
| 8177 | tmp |= SBI_SSCCTL_DISABLE; |
| 8178 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8179 | } |
| 8180 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8181 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8182 | } |
| 8183 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8184 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8185 | |
| 8186 | static const uint16_t sscdivintphase[] = { |
| 8187 | [BEND_IDX( 50)] = 0x3B23, |
| 8188 | [BEND_IDX( 45)] = 0x3B23, |
| 8189 | [BEND_IDX( 40)] = 0x3C23, |
| 8190 | [BEND_IDX( 35)] = 0x3C23, |
| 8191 | [BEND_IDX( 30)] = 0x3D23, |
| 8192 | [BEND_IDX( 25)] = 0x3D23, |
| 8193 | [BEND_IDX( 20)] = 0x3E23, |
| 8194 | [BEND_IDX( 15)] = 0x3E23, |
| 8195 | [BEND_IDX( 10)] = 0x3F23, |
| 8196 | [BEND_IDX( 5)] = 0x3F23, |
| 8197 | [BEND_IDX( 0)] = 0x0025, |
| 8198 | [BEND_IDX( -5)] = 0x0025, |
| 8199 | [BEND_IDX(-10)] = 0x0125, |
| 8200 | [BEND_IDX(-15)] = 0x0125, |
| 8201 | [BEND_IDX(-20)] = 0x0225, |
| 8202 | [BEND_IDX(-25)] = 0x0225, |
| 8203 | [BEND_IDX(-30)] = 0x0325, |
| 8204 | [BEND_IDX(-35)] = 0x0325, |
| 8205 | [BEND_IDX(-40)] = 0x0425, |
| 8206 | [BEND_IDX(-45)] = 0x0425, |
| 8207 | [BEND_IDX(-50)] = 0x0525, |
| 8208 | }; |
| 8209 | |
| 8210 | /* |
| 8211 | * Bend CLKOUT_DP |
| 8212 | * steps -50 to 50 inclusive, in steps of 5 |
| 8213 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8214 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8215 | */ |
| 8216 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8217 | { |
| 8218 | uint32_t tmp; |
| 8219 | int idx = BEND_IDX(steps); |
| 8220 | |
| 8221 | if (WARN_ON(steps % 5 != 0)) |
| 8222 | return; |
| 8223 | |
| 8224 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8225 | return; |
| 8226 | |
| 8227 | mutex_lock(&dev_priv->sb_lock); |
| 8228 | |
| 8229 | if (steps % 10 != 0) |
| 8230 | tmp = 0xAAAAAAAB; |
| 8231 | else |
| 8232 | tmp = 0x00000000; |
| 8233 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8234 | |
| 8235 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8236 | tmp &= 0xffff0000; |
| 8237 | tmp |= sscdivintphase[idx]; |
| 8238 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8239 | |
| 8240 | mutex_unlock(&dev_priv->sb_lock); |
| 8241 | } |
| 8242 | |
| 8243 | #undef BEND_IDX |
| 8244 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8245 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8246 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8247 | struct intel_encoder *encoder; |
| 8248 | bool has_vga = false; |
| 8249 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8250 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8251 | switch (encoder->type) { |
| 8252 | case INTEL_OUTPUT_ANALOG: |
| 8253 | has_vga = true; |
| 8254 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8255 | default: |
| 8256 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8257 | } |
| 8258 | } |
| 8259 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8260 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8261 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8262 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8263 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8264 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8265 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8266 | } |
| 8267 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8268 | /* |
| 8269 | * Initialize reference clocks when the driver loads |
| 8270 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8271 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8272 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8273 | 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] | 8274 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8275 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8276 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8277 | } |
| 8278 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8279 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8280 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8281 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8282 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8283 | int pipe = intel_crtc->pipe; |
| 8284 | uint32_t val; |
| 8285 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8286 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8287 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8288 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8289 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8290 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8291 | break; |
| 8292 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8293 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8294 | break; |
| 8295 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8296 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8297 | break; |
| 8298 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8299 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8300 | break; |
| 8301 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8302 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8303 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8304 | } |
| 8305 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8306 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8307 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8308 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8309 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8310 | val |= PIPECONF_INTERLACED_ILK; |
| 8311 | else |
| 8312 | val |= PIPECONF_PROGRESSIVE; |
| 8313 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8314 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8315 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8316 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8317 | I915_WRITE(PIPECONF(pipe), val); |
| 8318 | POSTING_READ(PIPECONF(pipe)); |
| 8319 | } |
| 8320 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8321 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8322 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8323 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8324 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8325 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8326 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8327 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8328 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8329 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8330 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8331 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8332 | val |= PIPECONF_INTERLACED_ILK; |
| 8333 | else |
| 8334 | val |= PIPECONF_PROGRESSIVE; |
| 8335 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8336 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8337 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8338 | } |
| 8339 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8340 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
| 8341 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8342 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8343 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8344 | struct intel_crtc_state *config = intel_crtc->config; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8345 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8346 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8347 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8348 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8349 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8350 | case 18: |
| 8351 | val |= PIPEMISC_DITHER_6_BPC; |
| 8352 | break; |
| 8353 | case 24: |
| 8354 | val |= PIPEMISC_DITHER_8_BPC; |
| 8355 | break; |
| 8356 | case 30: |
| 8357 | val |= PIPEMISC_DITHER_10_BPC; |
| 8358 | break; |
| 8359 | case 36: |
| 8360 | val |= PIPEMISC_DITHER_12_BPC; |
| 8361 | break; |
| 8362 | default: |
| 8363 | /* Case prevented by pipe_config_set_bpp. */ |
| 8364 | BUG(); |
| 8365 | } |
| 8366 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8367 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8368 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8369 | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8370 | if (config->ycbcr420) { |
| 8371 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV | |
| 8372 | PIPEMISC_YUV420_ENABLE | |
| 8373 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 8374 | } |
| 8375 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8376 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8377 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8378 | } |
| 8379 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8380 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8381 | { |
| 8382 | /* |
| 8383 | * Account for spread spectrum to avoid |
| 8384 | * oversubscribing the link. Max center spread |
| 8385 | * is 2.5%; use 5% for safety's sake. |
| 8386 | */ |
| 8387 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8388 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8389 | } |
| 8390 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8391 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8392 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8393 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8394 | } |
| 8395 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8396 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8397 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8398 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8399 | { |
| 8400 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8401 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8402 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8403 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8404 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8405 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8406 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8407 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8408 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8409 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8410 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8411 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8412 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8413 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8414 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8415 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8416 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8417 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8418 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8419 | fp |= FP_CB_TUNE; |
| 8420 | |
| 8421 | if (reduced_clock) { |
| 8422 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8423 | |
| 8424 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8425 | fp2 |= FP_CB_TUNE; |
| 8426 | } else { |
| 8427 | fp2 = fp; |
| 8428 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8429 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8430 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8431 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8432 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8433 | dpll |= DPLLB_MODE_LVDS; |
| 8434 | else |
| 8435 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8436 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8437 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8438 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8439 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8440 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8441 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8442 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8443 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8444 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8445 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8446 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8447 | /* |
| 8448 | * The high speed IO clock is only really required for |
| 8449 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8450 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8451 | * the clock needlessly does no real harm, except use up a |
| 8452 | * bit of power potentially. |
| 8453 | * |
| 8454 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8455 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8456 | * driving PCH ports at the same time. On SNB we could do this, |
| 8457 | * and potentially avoid enabling the second DPLL, but it's not |
| 8458 | * clear if it''s a win or loss power wise. No point in doing |
| 8459 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8460 | */ |
| 8461 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8462 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8463 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8464 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8465 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8466 | 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] | 8467 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8468 | 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] | 8469 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8470 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8471 | case 5: |
| 8472 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8473 | break; |
| 8474 | case 7: |
| 8475 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8476 | break; |
| 8477 | case 10: |
| 8478 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8479 | break; |
| 8480 | case 14: |
| 8481 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8482 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8483 | } |
| 8484 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8485 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8486 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8487 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8488 | else |
| 8489 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8490 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8491 | dpll |= DPLL_VCO_ENABLE; |
| 8492 | |
| 8493 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8494 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8495 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8496 | } |
| 8497 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8498 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8499 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8500 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8501 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8502 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8503 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8504 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8505 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8506 | memset(&crtc_state->dpll_hw_state, 0, |
| 8507 | sizeof(crtc_state->dpll_hw_state)); |
| 8508 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8509 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8510 | if (!crtc_state->has_pch_encoder) |
| 8511 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8512 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8513 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8514 | if (intel_panel_use_ssc(dev_priv)) { |
| 8515 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8516 | dev_priv->vbt.lvds_ssc_freq); |
| 8517 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8518 | } |
| 8519 | |
| 8520 | if (intel_is_dual_link_lvds(dev)) { |
| 8521 | if (refclk == 100000) |
| 8522 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8523 | else |
| 8524 | limit = &intel_limits_ironlake_dual_lvds; |
| 8525 | } else { |
| 8526 | if (refclk == 100000) |
| 8527 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8528 | else |
| 8529 | limit = &intel_limits_ironlake_single_lvds; |
| 8530 | } |
| 8531 | } else { |
| 8532 | limit = &intel_limits_ironlake_dac; |
| 8533 | } |
| 8534 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8535 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8536 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8537 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8538 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8539 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8540 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8541 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8542 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8543 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8544 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8545 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 8546 | pipe_name(crtc->pipe)); |
| 8547 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8548 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8549 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8550 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8551 | } |
| 8552 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8553 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8554 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8555 | { |
| 8556 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8557 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8558 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8559 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8560 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8561 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8562 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8563 | & ~TU_SIZE_MASK; |
| 8564 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8565 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8566 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8567 | } |
| 8568 | |
| 8569 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8570 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8571 | struct intel_link_m_n *m_n, |
| 8572 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8573 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8574 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8575 | enum pipe pipe = crtc->pipe; |
| 8576 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8577 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8578 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8579 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8580 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8581 | & ~TU_SIZE_MASK; |
| 8582 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8583 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8584 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8585 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8586 | * gen < 8) and if DRRS is supported (to make sure the |
| 8587 | * registers are not unnecessarily read). |
| 8588 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8589 | if (m2_n2 && INTEL_GEN(dev_priv) < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8590 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8591 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8592 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8593 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8594 | & ~TU_SIZE_MASK; |
| 8595 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8596 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8597 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8598 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8599 | } else { |
| 8600 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8601 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8602 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8603 | & ~TU_SIZE_MASK; |
| 8604 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8605 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8606 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8607 | } |
| 8608 | } |
| 8609 | |
| 8610 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8611 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8612 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8613 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8614 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8615 | else |
| 8616 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8617 | &pipe_config->dp_m_n, |
| 8618 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8619 | } |
| 8620 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8621 | 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] | 8622 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8623 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8624 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8625 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8626 | } |
| 8627 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8628 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8629 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8630 | { |
| 8631 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8632 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8633 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8634 | uint32_t ps_ctrl = 0; |
| 8635 | int id = -1; |
| 8636 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8637 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8638 | /* find scaler attached to this pipe */ |
| 8639 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8640 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8641 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8642 | id = i; |
| 8643 | pipe_config->pch_pfit.enabled = true; |
| 8644 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8645 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8646 | break; |
| 8647 | } |
| 8648 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8649 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8650 | scaler_state->scaler_id = id; |
| 8651 | if (id >= 0) { |
| 8652 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8653 | } else { |
| 8654 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8655 | } |
| 8656 | } |
| 8657 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8658 | static void |
| 8659 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8660 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8661 | { |
| 8662 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8663 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8664 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 8665 | enum plane_id plane_id = plane->id; |
| 8666 | enum pipe pipe = crtc->pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8667 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8668 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8669 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8670 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8671 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8672 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 8673 | if (!plane->get_hw_state(plane)) |
| 8674 | return; |
| 8675 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8676 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8677 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8678 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8679 | return; |
| 8680 | } |
| 8681 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8682 | fb = &intel_fb->base; |
| 8683 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 8684 | fb->dev = dev; |
| 8685 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8686 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8687 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 8688 | if (INTEL_GEN(dev_priv) >= 11) |
| 8689 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 8690 | else |
| 8691 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8692 | |
| 8693 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8694 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8695 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 8696 | } else { |
| 8697 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 8698 | } |
| 8699 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8700 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8701 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 8702 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8703 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8704 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8705 | switch (tiling) { |
| 8706 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 8707 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8708 | break; |
| 8709 | case PLANE_CTL_TILED_X: |
| 8710 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8711 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8712 | break; |
| 8713 | case PLANE_CTL_TILED_Y: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8714 | if (val & PLANE_CTL_DECOMPRESSION_ENABLE) |
| 8715 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 8716 | else |
| 8717 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8718 | break; |
| 8719 | case PLANE_CTL_TILED_YF: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8720 | if (val & PLANE_CTL_DECOMPRESSION_ENABLE) |
| 8721 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 8722 | else |
| 8723 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8724 | break; |
| 8725 | default: |
| 8726 | MISSING_CASE(tiling); |
| 8727 | goto error; |
| 8728 | } |
| 8729 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8730 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8731 | plane_config->base = base; |
| 8732 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8733 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8734 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8735 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8736 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8737 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8738 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8739 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8740 | stride_mult = intel_fb_stride_alignment(fb, 0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8741 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8742 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8743 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8744 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8745 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8746 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8747 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8748 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 8749 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8750 | plane_config->size); |
| 8751 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8752 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8753 | return; |
| 8754 | |
| 8755 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 8756 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8757 | } |
| 8758 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8759 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8760 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8761 | { |
| 8762 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8763 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8764 | uint32_t tmp; |
| 8765 | |
| 8766 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 8767 | |
| 8768 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 8769 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8770 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 8771 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8772 | |
| 8773 | /* We currently do not free assignements of panel fitters on |
| 8774 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 8775 | * differentiates them) so just WARN about this case for now. */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8776 | if (IS_GEN7(dev_priv)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8777 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 8778 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 8779 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8780 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8781 | } |
| 8782 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8783 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8784 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [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); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8788 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8789 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8790 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8791 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8792 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8793 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8794 | return false; |
| 8795 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8796 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8797 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8798 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8799 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8800 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8801 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8802 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8803 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8804 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8805 | case PIPECONF_6BPC: |
| 8806 | pipe_config->pipe_bpp = 18; |
| 8807 | break; |
| 8808 | case PIPECONF_8BPC: |
| 8809 | pipe_config->pipe_bpp = 24; |
| 8810 | break; |
| 8811 | case PIPECONF_10BPC: |
| 8812 | pipe_config->pipe_bpp = 30; |
| 8813 | break; |
| 8814 | case PIPECONF_12BPC: |
| 8815 | pipe_config->pipe_bpp = 36; |
| 8816 | break; |
| 8817 | default: |
| 8818 | break; |
| 8819 | } |
| 8820 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8821 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8822 | pipe_config->limited_color_range = true; |
| 8823 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8824 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8825 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8826 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8827 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8828 | pipe_config->has_pch_encoder = true; |
| 8829 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8830 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8831 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8832 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8833 | |
| 8834 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8835 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8836 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 8837 | /* |
| 8838 | * The pipe->pch transcoder and pch transcoder->pll |
| 8839 | * mapping is fixed. |
| 8840 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8841 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8842 | } else { |
| 8843 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8844 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8845 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8846 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8847 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8848 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8849 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8850 | pipe_config->shared_dpll = |
| 8851 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 8852 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8853 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 8854 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 8855 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8856 | |
| 8857 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8858 | pipe_config->pixel_multiplier = |
| 8859 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8860 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8861 | |
| 8862 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8863 | } else { |
| 8864 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8865 | } |
| 8866 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8867 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8868 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8869 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8870 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8871 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8872 | ret = true; |
| 8873 | |
| 8874 | out: |
| 8875 | intel_display_power_put(dev_priv, power_domain); |
| 8876 | |
| 8877 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8878 | } |
| 8879 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8880 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 8881 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 8882 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8883 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8884 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 8885 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8886 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8887 | pipe_name(crtc->pipe)); |
| 8888 | |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 8889 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)), |
| 8890 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8891 | 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] | 8892 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 8893 | 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] | 8894 | 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] | 8895 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8896 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 8897 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8898 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8899 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8900 | 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] | 8901 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8902 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8903 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8904 | 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] | 8905 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 8906 | /* |
| 8907 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 8908 | * interrupts remain enabled. We used to check for that, but since it's |
| 8909 | * gen-specific and since we only disable LCPLL after we fully disable |
| 8910 | * the interrupts, the check below should be enough. |
| 8911 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8912 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8913 | } |
| 8914 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8915 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 8916 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 8917 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8918 | return I915_READ(D_COMP_HSW); |
| 8919 | else |
| 8920 | return I915_READ(D_COMP_BDW); |
| 8921 | } |
| 8922 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8923 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 8924 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 8925 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8926 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8927 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 8928 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 8929 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 8930 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8931 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8932 | I915_WRITE(D_COMP_BDW, val); |
| 8933 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8934 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8935 | } |
| 8936 | |
| 8937 | /* |
| 8938 | * This function implements pieces of two sequences from BSpec: |
| 8939 | * - Sequence for display software to disable LCPLL |
| 8940 | * - Sequence for display software to allow package C8+ |
| 8941 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 8942 | * register. Callers should take care of disabling all the display engine |
| 8943 | * functions, doing the mode unset, fixing interrupts, etc. |
| 8944 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8945 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 8946 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8947 | { |
| 8948 | uint32_t val; |
| 8949 | |
| 8950 | assert_can_disable_lcpll(dev_priv); |
| 8951 | |
| 8952 | val = I915_READ(LCPLL_CTL); |
| 8953 | |
| 8954 | if (switch_to_fclk) { |
| 8955 | val |= LCPLL_CD_SOURCE_FCLK; |
| 8956 | I915_WRITE(LCPLL_CTL, val); |
| 8957 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 8958 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 8959 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8960 | DRM_ERROR("Switching to FCLK failed\n"); |
| 8961 | |
| 8962 | val = I915_READ(LCPLL_CTL); |
| 8963 | } |
| 8964 | |
| 8965 | val |= LCPLL_PLL_DISABLE; |
| 8966 | I915_WRITE(LCPLL_CTL, val); |
| 8967 | POSTING_READ(LCPLL_CTL); |
| 8968 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 8969 | 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] | 8970 | DRM_ERROR("LCPLL still locked\n"); |
| 8971 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8972 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8973 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8974 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8975 | ndelay(100); |
| 8976 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8977 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 8978 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8979 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 8980 | |
| 8981 | if (allow_power_down) { |
| 8982 | val = I915_READ(LCPLL_CTL); |
| 8983 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 8984 | I915_WRITE(LCPLL_CTL, val); |
| 8985 | POSTING_READ(LCPLL_CTL); |
| 8986 | } |
| 8987 | } |
| 8988 | |
| 8989 | /* |
| 8990 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 8991 | * source. |
| 8992 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8993 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8994 | { |
| 8995 | uint32_t val; |
| 8996 | |
| 8997 | val = I915_READ(LCPLL_CTL); |
| 8998 | |
| 8999 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9000 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9001 | return; |
| 9002 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9003 | /* |
| 9004 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9005 | * 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] | 9006 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9007 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9008 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9009 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9010 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9011 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9012 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9013 | } |
| 9014 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9015 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9016 | val |= D_COMP_COMP_FORCE; |
| 9017 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9018 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9019 | |
| 9020 | val = I915_READ(LCPLL_CTL); |
| 9021 | val &= ~LCPLL_PLL_DISABLE; |
| 9022 | I915_WRITE(LCPLL_CTL, val); |
| 9023 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9024 | if (intel_wait_for_register(dev_priv, |
| 9025 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9026 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9027 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9028 | |
| 9029 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9030 | val = I915_READ(LCPLL_CTL); |
| 9031 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9032 | I915_WRITE(LCPLL_CTL, val); |
| 9033 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9034 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9035 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9036 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9037 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9038 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9039 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9040 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9041 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9042 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9043 | } |
| 9044 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9045 | /* |
| 9046 | * Package states C8 and deeper are really deep PC states that can only be |
| 9047 | * reached when all the devices on the system allow it, so even if the graphics |
| 9048 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9049 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9050 | * |
| 9051 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9052 | * well is disabled and most interrupts are disabled, and these are also |
| 9053 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9054 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9055 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9056 | * hang the machine. |
| 9057 | * |
| 9058 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9059 | * the state of some registers, so when we come back from PC8+ we need to |
| 9060 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9061 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9062 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9063 | * because of the runtime PM support). |
| 9064 | * |
| 9065 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9066 | * documentation. |
| 9067 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9068 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9069 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9070 | uint32_t val; |
| 9071 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9072 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9073 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9074 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9075 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9076 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9077 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9078 | } |
| 9079 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9080 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9081 | hsw_disable_lcpll(dev_priv, true, true); |
| 9082 | } |
| 9083 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9084 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9085 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9086 | uint32_t val; |
| 9087 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9088 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9089 | |
| 9090 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9091 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9092 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9093 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9094 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9095 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9096 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9097 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9098 | } |
| 9099 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9100 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9101 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9102 | { |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9103 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9104 | struct intel_encoder *encoder = |
| 9105 | intel_ddi_get_crtc_new_encoder(crtc_state); |
| 9106 | |
| 9107 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
| 9108 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 9109 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9110 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9111 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9112 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9113 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9114 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9115 | } |
| 9116 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9117 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9118 | enum port port, |
| 9119 | struct intel_crtc_state *pipe_config) |
| 9120 | { |
| 9121 | enum intel_dpll_id id; |
| 9122 | u32 temp; |
| 9123 | |
| 9124 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9125 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9126 | |
| 9127 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9128 | return; |
| 9129 | |
| 9130 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9131 | } |
| 9132 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9133 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9134 | enum port port, |
| 9135 | struct intel_crtc_state *pipe_config) |
| 9136 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9137 | enum intel_dpll_id id; |
| 9138 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9139 | switch (port) { |
| 9140 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9141 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9142 | break; |
| 9143 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9144 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9145 | break; |
| 9146 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9147 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9148 | break; |
| 9149 | default: |
| 9150 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9151 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9152 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9153 | |
| 9154 | 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] | 9155 | } |
| 9156 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9157 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9158 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9159 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9160 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9161 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9162 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9163 | |
| 9164 | 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] | 9165 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9166 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9167 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9168 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9169 | |
| 9170 | 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] | 9171 | } |
| 9172 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9173 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9174 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9175 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9176 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9177 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9178 | 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] | 9179 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9180 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9181 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9182 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9183 | break; |
| 9184 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9185 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9186 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9187 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9188 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9189 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9190 | case PORT_CLK_SEL_LCPLL_810: |
| 9191 | id = DPLL_ID_LCPLL_810; |
| 9192 | break; |
| 9193 | case PORT_CLK_SEL_LCPLL_1350: |
| 9194 | id = DPLL_ID_LCPLL_1350; |
| 9195 | break; |
| 9196 | case PORT_CLK_SEL_LCPLL_2700: |
| 9197 | id = DPLL_ID_LCPLL_2700; |
| 9198 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9199 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9200 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9201 | /* fall through */ |
| 9202 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9203 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9204 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9205 | |
| 9206 | 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] | 9207 | } |
| 9208 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9209 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9210 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9211 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9212 | { |
| 9213 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9214 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9215 | enum intel_display_power_domain power_domain; |
| 9216 | u32 tmp; |
| 9217 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9218 | /* |
| 9219 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
| 9220 | * transcoder handled below. |
| 9221 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9222 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9223 | |
| 9224 | /* |
| 9225 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9226 | * consistency and less surprising code; it's in always on power). |
| 9227 | */ |
| 9228 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9229 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9230 | enum pipe trans_edp_pipe; |
| 9231 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9232 | default: |
| 9233 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 9234 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9235 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9236 | trans_edp_pipe = PIPE_A; |
| 9237 | break; |
| 9238 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9239 | trans_edp_pipe = PIPE_B; |
| 9240 | break; |
| 9241 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9242 | trans_edp_pipe = PIPE_C; |
| 9243 | break; |
| 9244 | } |
| 9245 | |
| 9246 | if (trans_edp_pipe == crtc->pipe) |
| 9247 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9248 | } |
| 9249 | |
| 9250 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9251 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9252 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9253 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9254 | |
| 9255 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9256 | |
| 9257 | return tmp & PIPECONF_ENABLE; |
| 9258 | } |
| 9259 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9260 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9261 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9262 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9263 | { |
| 9264 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9265 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9266 | enum intel_display_power_domain power_domain; |
| 9267 | enum port port; |
| 9268 | enum transcoder cpu_transcoder; |
| 9269 | u32 tmp; |
| 9270 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9271 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9272 | if (port == PORT_A) |
| 9273 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9274 | else |
| 9275 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9276 | |
| 9277 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9278 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9279 | continue; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9280 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9281 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9282 | /* |
| 9283 | * The PLL needs to be enabled with a valid divider |
| 9284 | * configuration, otherwise accessing DSI registers will hang |
| 9285 | * the machine. See BSpec North Display Engine |
| 9286 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9287 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9288 | */ |
| 9289 | if (!intel_dsi_pll_is_enabled(dev_priv)) |
| 9290 | break; |
| 9291 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9292 | /* XXX: this works for video mode only */ |
| 9293 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9294 | if (!(tmp & DPI_ENABLE)) |
| 9295 | continue; |
| 9296 | |
| 9297 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9298 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9299 | continue; |
| 9300 | |
| 9301 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9302 | break; |
| 9303 | } |
| 9304 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9305 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9306 | } |
| 9307 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9308 | 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] | 9309 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9310 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9311 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9312 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9313 | enum port port; |
| 9314 | uint32_t tmp; |
| 9315 | |
| 9316 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9317 | |
| 9318 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9319 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9320 | if (IS_CANNONLAKE(dev_priv)) |
| 9321 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9322 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9323 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9324 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9325 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9326 | else |
| 9327 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9328 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9329 | pll = pipe_config->shared_dpll; |
| 9330 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9331 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9332 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9333 | } |
| 9334 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9335 | /* |
| 9336 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9337 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9338 | * the PCH transcoder is on. |
| 9339 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9340 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9341 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9342 | pipe_config->has_pch_encoder = true; |
| 9343 | |
| 9344 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9345 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9346 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9347 | |
| 9348 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9349 | } |
| 9350 | } |
| 9351 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9352 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9353 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9354 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9355 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9356 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9357 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9358 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9359 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9360 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9361 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9362 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9363 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9364 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9365 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9366 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9367 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9368 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9369 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9370 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9371 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9372 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9373 | WARN_ON(active); |
| 9374 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9375 | } |
| 9376 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9377 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9378 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9379 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9380 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9381 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9382 | intel_get_pipe_timings(crtc, pipe_config); |
| 9383 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9384 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9385 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9386 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9387 | pipe_config->gamma_mode = |
| 9388 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9389 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 9390 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 9391 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 9392 | bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV; |
| 9393 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 9394 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 9395 | bool blend_mode_420 = tmp & |
| 9396 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 9397 | |
| 9398 | pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE; |
| 9399 | if (pipe_config->ycbcr420 != clrspace_yuv || |
| 9400 | pipe_config->ycbcr420 != blend_mode_420) |
| 9401 | DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp); |
| 9402 | } else if (clrspace_yuv) { |
| 9403 | DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n"); |
| 9404 | } |
| 9405 | } |
| 9406 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9407 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9408 | 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] | 9409 | power_domain_mask |= BIT_ULL(power_domain); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9410 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9411 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9412 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9413 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9414 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9415 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9416 | if (hsw_crtc_supports_ips(crtc)) { |
| 9417 | if (IS_HASWELL(dev_priv)) |
| 9418 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9419 | else { |
| 9420 | /* |
| 9421 | * We cannot readout IPS state on broadwell, set to |
| 9422 | * true so we can set it to a defined state on first |
| 9423 | * commit. |
| 9424 | */ |
| 9425 | pipe_config->ips_enabled = true; |
| 9426 | } |
| 9427 | } |
| 9428 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9429 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9430 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9431 | pipe_config->pixel_multiplier = |
| 9432 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9433 | } else { |
| 9434 | pipe_config->pixel_multiplier = 1; |
| 9435 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9436 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9437 | out: |
| 9438 | for_each_power_domain(power_domain, power_domain_mask) |
| 9439 | intel_display_power_put(dev_priv, power_domain); |
| 9440 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9441 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9442 | } |
| 9443 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9444 | 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] | 9445 | { |
| 9446 | struct drm_i915_private *dev_priv = |
| 9447 | to_i915(plane_state->base.plane->dev); |
| 9448 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9449 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9450 | u32 base; |
| 9451 | |
| 9452 | if (INTEL_INFO(dev_priv)->cursor_needs_physical) |
| 9453 | base = obj->phys_handle->busaddr; |
| 9454 | else |
| 9455 | base = intel_plane_ggtt_offset(plane_state); |
| 9456 | |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9457 | base += plane_state->main.offset; |
| 9458 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9459 | /* ILK+ do this automagically */ |
| 9460 | if (HAS_GMCH_DISPLAY(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9461 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9462 | base += (plane_state->base.crtc_h * |
| 9463 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9464 | |
| 9465 | return base; |
| 9466 | } |
| 9467 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9468 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9469 | { |
| 9470 | int x = plane_state->base.crtc_x; |
| 9471 | int y = plane_state->base.crtc_y; |
| 9472 | u32 pos = 0; |
| 9473 | |
| 9474 | if (x < 0) { |
| 9475 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9476 | x = -x; |
| 9477 | } |
| 9478 | pos |= x << CURSOR_X_SHIFT; |
| 9479 | |
| 9480 | if (y < 0) { |
| 9481 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9482 | y = -y; |
| 9483 | } |
| 9484 | pos |= y << CURSOR_Y_SHIFT; |
| 9485 | |
| 9486 | return pos; |
| 9487 | } |
| 9488 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9489 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9490 | { |
| 9491 | const struct drm_mode_config *config = |
| 9492 | &plane_state->base.plane->dev->mode_config; |
| 9493 | int width = plane_state->base.crtc_w; |
| 9494 | int height = plane_state->base.crtc_h; |
| 9495 | |
| 9496 | return width > 0 && width <= config->cursor_width && |
| 9497 | height > 0 && height <= config->cursor_height; |
| 9498 | } |
| 9499 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9500 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 9501 | struct intel_plane_state *plane_state) |
| 9502 | { |
| 9503 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9504 | int src_x, src_y; |
| 9505 | u32 offset; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9506 | int ret; |
| 9507 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9508 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 9509 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9510 | DRM_PLANE_HELPER_NO_SCALING, |
| 9511 | DRM_PLANE_HELPER_NO_SCALING, |
| 9512 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9513 | if (ret) |
| 9514 | return ret; |
| 9515 | |
| 9516 | if (!fb) |
| 9517 | return 0; |
| 9518 | |
| 9519 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 9520 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 9521 | return -EINVAL; |
| 9522 | } |
| 9523 | |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9524 | src_x = plane_state->base.src_x >> 16; |
| 9525 | src_y = plane_state->base.src_y >> 16; |
| 9526 | |
| 9527 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 9528 | offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0); |
| 9529 | |
| 9530 | if (src_x != 0 || src_y != 0) { |
| 9531 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 9532 | return -EINVAL; |
| 9533 | } |
| 9534 | |
| 9535 | plane_state->main.offset = offset; |
| 9536 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9537 | return 0; |
| 9538 | } |
| 9539 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9540 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9541 | const struct intel_plane_state *plane_state) |
| 9542 | { |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9543 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9544 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9545 | return CURSOR_ENABLE | |
| 9546 | CURSOR_GAMMA_ENABLE | |
| 9547 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9548 | CURSOR_STRIDE(fb->pitches[0]); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9549 | } |
| 9550 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9551 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9552 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9553 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9554 | |
| 9555 | /* |
| 9556 | * 845g/865g are only limited by the width of their cursors, |
| 9557 | * the height is arbitrary up to the precision of the register. |
| 9558 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9559 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9560 | } |
| 9561 | |
| 9562 | static int i845_check_cursor(struct intel_plane *plane, |
| 9563 | struct intel_crtc_state *crtc_state, |
| 9564 | struct intel_plane_state *plane_state) |
| 9565 | { |
| 9566 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9567 | int ret; |
| 9568 | |
| 9569 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9570 | if (ret) |
| 9571 | return ret; |
| 9572 | |
| 9573 | /* 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] | 9574 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9575 | return 0; |
| 9576 | |
| 9577 | /* Check for which cursor types we support */ |
| 9578 | if (!i845_cursor_size_ok(plane_state)) { |
| 9579 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9580 | plane_state->base.crtc_w, |
| 9581 | plane_state->base.crtc_h); |
| 9582 | return -EINVAL; |
| 9583 | } |
| 9584 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9585 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9586 | case 256: |
| 9587 | case 512: |
| 9588 | case 1024: |
| 9589 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9590 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9591 | default: |
| 9592 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 9593 | fb->pitches[0]); |
| 9594 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9595 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9596 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9597 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 9598 | |
| 9599 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9600 | } |
| 9601 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9602 | static void i845_update_cursor(struct intel_plane *plane, |
| 9603 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9604 | const struct intel_plane_state *plane_state) |
| 9605 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9606 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9607 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 9608 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9609 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 9610 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9611 | unsigned int width = plane_state->base.crtc_w; |
| 9612 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9613 | |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 9614 | cntl = plane_state->ctl; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9615 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9616 | |
| 9617 | base = intel_cursor_base(plane_state); |
| 9618 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9619 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9620 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9621 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 9622 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9623 | /* On these chipsets we can only modify the base/size/stride |
| 9624 | * whilst the cursor is disabled. |
| 9625 | */ |
| 9626 | if (plane->cursor.base != base || |
| 9627 | plane->cursor.size != size || |
| 9628 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9629 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9630 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9631 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9632 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9633 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9634 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9635 | plane->cursor.base = base; |
| 9636 | plane->cursor.size = size; |
| 9637 | plane->cursor.cntl = cntl; |
| 9638 | } else { |
| 9639 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9640 | } |
| 9641 | |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9642 | POSTING_READ_FW(CURCNTR(PIPE_A)); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9643 | |
| 9644 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 9645 | } |
| 9646 | |
| 9647 | static void i845_disable_cursor(struct intel_plane *plane, |
| 9648 | struct intel_crtc *crtc) |
| 9649 | { |
| 9650 | i845_update_cursor(plane, NULL, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9651 | } |
| 9652 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9653 | static bool i845_cursor_get_hw_state(struct intel_plane *plane) |
| 9654 | { |
| 9655 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9656 | enum intel_display_power_domain power_domain; |
| 9657 | bool ret; |
| 9658 | |
| 9659 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
| 9660 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9661 | return false; |
| 9662 | |
| 9663 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 9664 | |
| 9665 | intel_display_power_put(dev_priv, power_domain); |
| 9666 | |
| 9667 | return ret; |
| 9668 | } |
| 9669 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9670 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9671 | const struct intel_plane_state *plane_state) |
| 9672 | { |
| 9673 | struct drm_i915_private *dev_priv = |
| 9674 | to_i915(plane_state->base.plane->dev); |
| 9675 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9676 | u32 cntl; |
| 9677 | |
| 9678 | cntl = MCURSOR_GAMMA_ENABLE; |
| 9679 | |
| 9680 | if (HAS_DDI(dev_priv)) |
| 9681 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
| 9682 | |
Ville Syrjälä | 32ea06b | 2018-01-30 22:38:01 +0200 | [diff] [blame] | 9683 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 9684 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9685 | |
| 9686 | switch (plane_state->base.crtc_w) { |
| 9687 | case 64: |
| 9688 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 9689 | break; |
| 9690 | case 128: |
| 9691 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 9692 | break; |
| 9693 | case 256: |
| 9694 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 9695 | break; |
| 9696 | default: |
| 9697 | MISSING_CASE(plane_state->base.crtc_w); |
| 9698 | return 0; |
| 9699 | } |
| 9700 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 9701 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9702 | cntl |= CURSOR_ROTATE_180; |
| 9703 | |
| 9704 | return cntl; |
| 9705 | } |
| 9706 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9707 | 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] | 9708 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9709 | struct drm_i915_private *dev_priv = |
| 9710 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9711 | int width = plane_state->base.crtc_w; |
| 9712 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9713 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9714 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9715 | return false; |
| 9716 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9717 | /* Cursor width is limited to a few power-of-two sizes */ |
| 9718 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9719 | case 256: |
| 9720 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9721 | case 64: |
| 9722 | break; |
| 9723 | default: |
| 9724 | return false; |
| 9725 | } |
| 9726 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9727 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9728 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 9729 | * height from 8 lines up to the cursor width, when the |
| 9730 | * cursor is not rotated. Everything else requires square |
| 9731 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9732 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9733 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9734 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9735 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9736 | return false; |
| 9737 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9738 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9739 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9740 | } |
| 9741 | |
| 9742 | return true; |
| 9743 | } |
| 9744 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9745 | static int i9xx_check_cursor(struct intel_plane *plane, |
| 9746 | struct intel_crtc_state *crtc_state, |
| 9747 | struct intel_plane_state *plane_state) |
| 9748 | { |
| 9749 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9750 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9751 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9752 | int ret; |
| 9753 | |
| 9754 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9755 | if (ret) |
| 9756 | return ret; |
| 9757 | |
| 9758 | /* 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] | 9759 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9760 | return 0; |
| 9761 | |
| 9762 | /* Check for which cursor types we support */ |
| 9763 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 9764 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9765 | plane_state->base.crtc_w, |
| 9766 | plane_state->base.crtc_h); |
| 9767 | return -EINVAL; |
| 9768 | } |
| 9769 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9770 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 9771 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 9772 | fb->pitches[0], plane_state->base.crtc_w); |
| 9773 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9774 | } |
| 9775 | |
| 9776 | /* |
| 9777 | * There's something wrong with the cursor on CHV pipe C. |
| 9778 | * If it straddles the left edge of the screen then |
| 9779 | * moving it away from the edge or disabling it often |
| 9780 | * results in a pipe underrun, and often that can lead to |
| 9781 | * dead pipe (constant underrun reported, and it scans |
| 9782 | * out just a solid color). To recover from that, the |
| 9783 | * display power well must be turned off and on again. |
| 9784 | * Refuse the put the cursor into that compromised position. |
| 9785 | */ |
| 9786 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 9787 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 9788 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 9789 | return -EINVAL; |
| 9790 | } |
| 9791 | |
| 9792 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 9793 | |
| 9794 | return 0; |
| 9795 | } |
| 9796 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9797 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 9798 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9799 | const struct intel_plane_state *plane_state) |
| 9800 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9801 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9802 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9803 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9804 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9805 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9806 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 9807 | cntl = plane_state->ctl; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9808 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9809 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 9810 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 9811 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9812 | base = intel_cursor_base(plane_state); |
| 9813 | pos = intel_cursor_position(plane_state); |
| 9814 | } |
| 9815 | |
| 9816 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 9817 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9818 | /* |
| 9819 | * On some platforms writing CURCNTR first will also |
| 9820 | * cause CURPOS to be armed by the CURBASE write. |
| 9821 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 9822 | * arm itself. Thus we always start the full update |
| 9823 | * with a CURCNTR write. |
| 9824 | * |
| 9825 | * On other platforms CURPOS always requires the |
| 9826 | * CURBASE write to arm the update. Additonally |
| 9827 | * a write to any of the cursor register will cancel |
| 9828 | * an already armed cursor update. Thus leaving out |
| 9829 | * the CURBASE write after CURPOS could lead to a |
| 9830 | * cursor that doesn't appear to move, or even change |
| 9831 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9832 | * |
| 9833 | * CURCNTR and CUR_FBC_CTL are always |
| 9834 | * armed by the CURBASE write only. |
| 9835 | */ |
| 9836 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9837 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9838 | plane->cursor.cntl != cntl) { |
| 9839 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
| 9840 | if (HAS_CUR_FBC(dev_priv)) |
| 9841 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
| 9842 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9843 | I915_WRITE_FW(CURBASE(pipe), base); |
| 9844 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9845 | plane->cursor.base = base; |
| 9846 | plane->cursor.size = fbc_ctl; |
| 9847 | plane->cursor.cntl = cntl; |
| 9848 | } else { |
| 9849 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 9850 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9851 | } |
| 9852 | |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9853 | POSTING_READ_FW(CURBASE(pipe)); |
| 9854 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9855 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 9856 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 9857 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9858 | static void i9xx_disable_cursor(struct intel_plane *plane, |
| 9859 | struct intel_crtc *crtc) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9860 | { |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9861 | i9xx_update_cursor(plane, NULL, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9862 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 9863 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9864 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane) |
| 9865 | { |
| 9866 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9867 | enum intel_display_power_domain power_domain; |
| 9868 | enum pipe pipe = plane->pipe; |
| 9869 | bool ret; |
| 9870 | |
| 9871 | /* |
| 9872 | * Not 100% correct for planes that can move between pipes, |
| 9873 | * but that's only the case for gen2-3 which don't have any |
| 9874 | * display power wells. |
| 9875 | */ |
| 9876 | power_domain = POWER_DOMAIN_PIPE(pipe); |
| 9877 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9878 | return false; |
| 9879 | |
| 9880 | ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
| 9881 | |
| 9882 | intel_display_power_put(dev_priv, power_domain); |
| 9883 | |
| 9884 | return ret; |
| 9885 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 9886 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9887 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 9888 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9889 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 9890 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 9891 | }; |
| 9892 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 9893 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 9894 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 9895 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9896 | { |
| 9897 | struct intel_framebuffer *intel_fb; |
| 9898 | int ret; |
| 9899 | |
| 9900 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 9901 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9902 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9903 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 9904 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9905 | if (ret) |
| 9906 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9907 | |
| 9908 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9909 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 9910 | err: |
| 9911 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9912 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9913 | } |
| 9914 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 9915 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 9916 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9917 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 9918 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9919 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 9920 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9921 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 9922 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9923 | if (ret) |
| 9924 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 9925 | |
| 9926 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 9927 | if (plane_state->crtc != crtc) |
| 9928 | continue; |
| 9929 | |
| 9930 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 9931 | if (ret) |
| 9932 | return ret; |
| 9933 | |
| 9934 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 9935 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 9936 | |
| 9937 | return 0; |
| 9938 | } |
| 9939 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 9940 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 9941 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 9942 | struct intel_load_detect_pipe *old, |
| 9943 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9944 | { |
| 9945 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9946 | struct intel_encoder *intel_encoder = |
| 9947 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9948 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9949 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9950 | struct drm_crtc *crtc = NULL; |
| 9951 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 9952 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9953 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 9954 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9955 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 9956 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9957 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9958 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9959 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9960 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 9961 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9962 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 9963 | old->restore_state = NULL; |
| 9964 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 9965 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 9966 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9967 | /* |
| 9968 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 9969 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9970 | * - if the connector already has an assigned crtc, use it (but make |
| 9971 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 9972 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9973 | * - try to find the first unused crtc that can drive this connector, |
| 9974 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9975 | */ |
| 9976 | |
| 9977 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 9978 | if (connector->state->crtc) { |
| 9979 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9980 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9981 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 9982 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 9983 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9984 | |
| 9985 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 9986 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9987 | } |
| 9988 | |
| 9989 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9990 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9991 | i++; |
| 9992 | if (!(encoder->possible_crtcs & (1 << i))) |
| 9993 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 9994 | |
| 9995 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 9996 | if (ret) |
| 9997 | goto fail; |
| 9998 | |
| 9999 | if (possible_crtc->state->enable) { |
| 10000 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10001 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10002 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10003 | |
| 10004 | crtc = possible_crtc; |
| 10005 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10006 | } |
| 10007 | |
| 10008 | /* |
| 10009 | * If we didn't find an unused CRTC, don't use any. |
| 10010 | */ |
| 10011 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10012 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10013 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10014 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10015 | } |
| 10016 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10017 | found: |
| 10018 | intel_crtc = to_intel_crtc(crtc); |
| 10019 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10020 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10021 | restore_state = drm_atomic_state_alloc(dev); |
| 10022 | if (!state || !restore_state) { |
| 10023 | ret = -ENOMEM; |
| 10024 | goto fail; |
| 10025 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10026 | |
| 10027 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10028 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10029 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10030 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10031 | if (IS_ERR(connector_state)) { |
| 10032 | ret = PTR_ERR(connector_state); |
| 10033 | goto fail; |
| 10034 | } |
| 10035 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10036 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10037 | if (ret) |
| 10038 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10039 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10040 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10041 | if (IS_ERR(crtc_state)) { |
| 10042 | ret = PTR_ERR(crtc_state); |
| 10043 | goto fail; |
| 10044 | } |
| 10045 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10046 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10047 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10048 | if (!mode) |
| 10049 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10050 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10051 | 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] | 10052 | if (ret) |
| 10053 | goto fail; |
| 10054 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10055 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10056 | if (ret) |
| 10057 | goto fail; |
| 10058 | |
| 10059 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10060 | if (!ret) |
| 10061 | 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] | 10062 | if (!ret) |
| 10063 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10064 | if (ret) { |
| 10065 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10066 | goto fail; |
| 10067 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10068 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10069 | ret = drm_atomic_commit(state); |
| 10070 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10071 | 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] | 10072 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10073 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10074 | |
| 10075 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10076 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10077 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10078 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10079 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10080 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10081 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10082 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10083 | if (state) { |
| 10084 | drm_atomic_state_put(state); |
| 10085 | state = NULL; |
| 10086 | } |
| 10087 | if (restore_state) { |
| 10088 | drm_atomic_state_put(restore_state); |
| 10089 | restore_state = NULL; |
| 10090 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10091 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10092 | if (ret == -EDEADLK) |
| 10093 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10094 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10095 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10096 | } |
| 10097 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10098 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10099 | struct intel_load_detect_pipe *old, |
| 10100 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10101 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10102 | struct intel_encoder *intel_encoder = |
| 10103 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10104 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10105 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10106 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10107 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10108 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10109 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10110 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10111 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10112 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10113 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10114 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10115 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10116 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10117 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10118 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10119 | } |
| 10120 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10121 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10122 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10123 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10124 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10125 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10126 | |
| 10127 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10128 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10129 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10130 | return 120000; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 10131 | else if (!IS_GEN2(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10132 | return 96000; |
| 10133 | else |
| 10134 | return 48000; |
| 10135 | } |
| 10136 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10137 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10138 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10139 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10140 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10141 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10142 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10143 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10144 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10145 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10146 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10147 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10148 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10149 | |
| 10150 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10151 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10152 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10153 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10154 | |
| 10155 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10156 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10157 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10158 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10159 | } else { |
| 10160 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10161 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10162 | } |
| 10163 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 10164 | if (!IS_GEN2(dev_priv)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10165 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10166 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10167 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10168 | else |
| 10169 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10170 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10171 | |
| 10172 | switch (dpll & DPLL_MODE_MASK) { |
| 10173 | case DPLLB_MODE_DAC_SERIAL: |
| 10174 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10175 | 5 : 10; |
| 10176 | break; |
| 10177 | case DPLLB_MODE_LVDS: |
| 10178 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10179 | 7 : 14; |
| 10180 | break; |
| 10181 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10182 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10183 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10184 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10185 | } |
| 10186 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10187 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10188 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10189 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10190 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10191 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10192 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10193 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10194 | |
| 10195 | if (is_lvds) { |
| 10196 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10197 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10198 | |
| 10199 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10200 | clock.p2 = 7; |
| 10201 | else |
| 10202 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10203 | } else { |
| 10204 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10205 | clock.p1 = 2; |
| 10206 | else { |
| 10207 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10208 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10209 | } |
| 10210 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10211 | clock.p2 = 4; |
| 10212 | else |
| 10213 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10214 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10215 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10216 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10217 | } |
| 10218 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10219 | /* |
| 10220 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10221 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10222 | * encoder's get_config() function. |
| 10223 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10224 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10225 | } |
| 10226 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10227 | int intel_dotclock_calculate(int link_freq, |
| 10228 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10229 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10230 | /* |
| 10231 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10232 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10233 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10234 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10235 | * |
| 10236 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10237 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10238 | */ |
| 10239 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10240 | if (!m_n->link_n) |
| 10241 | return 0; |
| 10242 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10243 | 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] | 10244 | } |
| 10245 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10246 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10247 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10248 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10249 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10250 | |
| 10251 | /* read out port_clock from the DPLL */ |
| 10252 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10253 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10254 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10255 | * In case there is an active pipe without active ports, |
| 10256 | * we may need some idea for the dotclock anyway. |
| 10257 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10258 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10259 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10260 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10261 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10262 | } |
| 10263 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10264 | /* Returns the currently programmed mode of the given encoder. */ |
| 10265 | struct drm_display_mode * |
| 10266 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10267 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10268 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10269 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10270 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10271 | struct intel_crtc *crtc; |
| 10272 | enum pipe pipe; |
| 10273 | |
| 10274 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10275 | return NULL; |
| 10276 | |
| 10277 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10278 | |
| 10279 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10280 | if (!mode) |
| 10281 | return NULL; |
| 10282 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10283 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10284 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10285 | kfree(mode); |
| 10286 | return NULL; |
| 10287 | } |
| 10288 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10289 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10290 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10291 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10292 | kfree(crtc_state); |
| 10293 | kfree(mode); |
| 10294 | return NULL; |
| 10295 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10296 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10297 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10298 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10299 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10300 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10301 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10302 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10303 | return mode; |
| 10304 | } |
| 10305 | |
| 10306 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10307 | { |
| 10308 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10309 | |
| 10310 | drm_crtc_cleanup(crtc); |
| 10311 | kfree(intel_crtc); |
| 10312 | } |
| 10313 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10314 | /** |
| 10315 | * intel_wm_need_update - Check whether watermarks need updating |
| 10316 | * @plane: drm plane |
| 10317 | * @state: new plane state |
| 10318 | * |
| 10319 | * Check current plane state versus the new one to determine whether |
| 10320 | * watermarks need to be recalculated. |
| 10321 | * |
| 10322 | * Returns true or false. |
| 10323 | */ |
| 10324 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 10325 | struct drm_plane_state *state) |
| 10326 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10327 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 10328 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 10329 | |
| 10330 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10331 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10332 | return true; |
| 10333 | |
| 10334 | if (!cur->base.fb || !new->base.fb) |
| 10335 | return false; |
| 10336 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10337 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10338 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10339 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10340 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10341 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10342 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10343 | return true; |
| 10344 | |
| 10345 | return false; |
| 10346 | } |
| 10347 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10348 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10349 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10350 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10351 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10352 | int dst_w = drm_rect_width(&state->base.dst); |
| 10353 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10354 | |
| 10355 | return (src_w != dst_w || src_h != dst_h); |
| 10356 | } |
| 10357 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10358 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10359 | struct drm_crtc_state *crtc_state, |
| 10360 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10361 | struct drm_plane_state *plane_state) |
| 10362 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10363 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10364 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10365 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10366 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10367 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10368 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10369 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10370 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10371 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10372 | bool turn_off, turn_on, visible, was_visible; |
| 10373 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10374 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10375 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10376 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10377 | ret = skl_update_scaler_plane( |
| 10378 | to_intel_crtc_state(crtc_state), |
| 10379 | to_intel_plane_state(plane_state)); |
| 10380 | if (ret) |
| 10381 | return ret; |
| 10382 | } |
| 10383 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10384 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10385 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10386 | |
| 10387 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10388 | was_visible = false; |
| 10389 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10390 | /* |
| 10391 | * Visibility is calculated as if the crtc was on, but |
| 10392 | * after scaler setup everything depends on it being off |
| 10393 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10394 | * |
| 10395 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10396 | * be computed as if the pipe would be active. Perhaps move |
| 10397 | * per-plane wm computation to the .check_plane() hook, and |
| 10398 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10399 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10400 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10401 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10402 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10403 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10404 | |
| 10405 | if (!was_visible && !visible) |
| 10406 | return 0; |
| 10407 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10408 | if (fb != old_plane_state->base.fb) |
| 10409 | pipe_config->fb_changed = true; |
| 10410 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10411 | turn_off = was_visible && (!visible || mode_changed); |
| 10412 | turn_on = visible && (!was_visible || mode_changed); |
| 10413 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10414 | 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] | 10415 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 10416 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10417 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10418 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10419 | 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] | 10420 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10421 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10422 | turn_off, turn_on, mode_changed); |
| 10423 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10424 | if (turn_on) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10425 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10426 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10427 | |
| 10428 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10429 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10430 | pipe_config->disable_cxsr = true; |
| 10431 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10432 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10433 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10434 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10435 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10436 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10437 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10438 | } else if (intel_wm_need_update(&plane->base, plane_state)) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10439 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10440 | /* FIXME bollocks */ |
| 10441 | pipe_config->update_wm_pre = true; |
| 10442 | pipe_config->update_wm_post = true; |
| 10443 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10444 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10445 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 10446 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10447 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10448 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10449 | /* |
| 10450 | * WaCxSRDisabledForSpriteScaling:ivb |
| 10451 | * |
| 10452 | * cstate->update_wm was already set above, so this flag will |
| 10453 | * take effect when we commit and program watermarks. |
| 10454 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10455 | if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) && |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10456 | needs_scaling(to_intel_plane_state(plane_state)) && |
| 10457 | !needs_scaling(old_plane_state)) |
| 10458 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10459 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10460 | return 0; |
| 10461 | } |
| 10462 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10463 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10464 | const struct intel_encoder *b) |
| 10465 | { |
| 10466 | /* masks could be asymmetric, so check both ways */ |
| 10467 | return a == b || (a->cloneable & (1 << b->type) && |
| 10468 | b->cloneable & (1 << a->type)); |
| 10469 | } |
| 10470 | |
| 10471 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 10472 | struct intel_crtc *crtc, |
| 10473 | struct intel_encoder *encoder) |
| 10474 | { |
| 10475 | struct intel_encoder *source_encoder; |
| 10476 | struct drm_connector *connector; |
| 10477 | struct drm_connector_state *connector_state; |
| 10478 | int i; |
| 10479 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10480 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10481 | if (connector_state->crtc != &crtc->base) |
| 10482 | continue; |
| 10483 | |
| 10484 | source_encoder = |
| 10485 | to_intel_encoder(connector_state->best_encoder); |
| 10486 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10487 | return false; |
| 10488 | } |
| 10489 | |
| 10490 | return true; |
| 10491 | } |
| 10492 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10493 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 10494 | struct drm_crtc_state *crtc_state) |
| 10495 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10496 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10497 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10498 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10499 | struct intel_crtc_state *pipe_config = |
| 10500 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10501 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 10502 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10503 | bool mode_changed = needs_modeset(crtc_state); |
| 10504 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10505 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10506 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 10507 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10508 | if (mode_changed && crtc_state->enable && |
| 10509 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10510 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10511 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 10512 | pipe_config); |
| 10513 | if (ret) |
| 10514 | return ret; |
| 10515 | } |
| 10516 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10517 | if (crtc_state->color_mgmt_changed) { |
| 10518 | ret = intel_color_check(crtc, crtc_state); |
| 10519 | if (ret) |
| 10520 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 10521 | |
| 10522 | /* |
| 10523 | * Changing color management on Intel hardware is |
| 10524 | * handled as part of planes update. |
| 10525 | */ |
| 10526 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10527 | } |
| 10528 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10529 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10530 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 10531 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10532 | if (ret) { |
| 10533 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10534 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10535 | } |
| 10536 | } |
| 10537 | |
| 10538 | if (dev_priv->display.compute_intermediate_wm && |
| 10539 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 10540 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 10541 | return 0; |
| 10542 | |
| 10543 | /* |
| 10544 | * Calculate 'intermediate' watermarks that satisfy both the |
| 10545 | * old state and the new state. We can program these |
| 10546 | * immediately. |
| 10547 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10548 | ret = dev_priv->display.compute_intermediate_wm(dev, |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10549 | intel_crtc, |
| 10550 | pipe_config); |
| 10551 | if (ret) { |
| 10552 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 10553 | return ret; |
| 10554 | } |
Ville Syrjälä | e3d5457 | 2016-05-13 10:10:42 -0700 | [diff] [blame] | 10555 | } else if (dev_priv->display.compute_intermediate_wm) { |
| 10556 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) |
| 10557 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10558 | } |
| 10559 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10560 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10561 | if (mode_changed) |
| 10562 | ret = skl_update_scaler_crtc(pipe_config); |
| 10563 | |
| 10564 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 10565 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 10566 | pipe_config); |
| 10567 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 10568 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10569 | pipe_config); |
| 10570 | } |
| 10571 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 10572 | if (HAS_IPS(dev_priv)) |
| 10573 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 10574 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10575 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10576 | } |
| 10577 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 10578 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 10579 | .atomic_begin = intel_begin_crtc_commit, |
| 10580 | .atomic_flush = intel_finish_crtc_commit, |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10581 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10582 | }; |
| 10583 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10584 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 10585 | { |
| 10586 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10587 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10588 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10589 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 10590 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10591 | if (connector->base.state->crtc) |
| 10592 | drm_connector_unreference(&connector->base); |
| 10593 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10594 | if (connector->base.encoder) { |
| 10595 | connector->base.state->best_encoder = |
| 10596 | connector->base.encoder; |
| 10597 | connector->base.state->crtc = |
| 10598 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10599 | |
| 10600 | drm_connector_reference(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10601 | } else { |
| 10602 | connector->base.state->best_encoder = NULL; |
| 10603 | connector->base.state->crtc = NULL; |
| 10604 | } |
| 10605 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10606 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10607 | } |
| 10608 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10609 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10610 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10611 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10612 | { |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10613 | const struct drm_display_info *info = &connector->base.display_info; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10614 | int bpp = pipe_config->pipe_bpp; |
| 10615 | |
| 10616 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10617 | connector->base.base.id, |
| 10618 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10619 | |
| 10620 | /* Don't use an invalid EDID bpc value */ |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10621 | if (info->bpc != 0 && info->bpc * 3 < bpp) { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10622 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10623 | bpp, info->bpc * 3); |
| 10624 | pipe_config->pipe_bpp = info->bpc * 3; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10625 | } |
| 10626 | |
Mario Kleiner | 196f954 | 2016-07-06 12:05:45 +0200 | [diff] [blame] | 10627 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10628 | if (info->bpc == 0 && bpp > 24) { |
Mario Kleiner | 196f954 | 2016-07-06 12:05:45 +0200 | [diff] [blame] | 10629 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 10630 | bpp); |
| 10631 | pipe_config->pipe_bpp = 24; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10632 | } |
| 10633 | } |
| 10634 | |
| 10635 | static int |
| 10636 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10637 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10638 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10639 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10640 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10641 | struct drm_connector *connector; |
| 10642 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10643 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10644 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10645 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 10646 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10647 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10648 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 10649 | bpp = 12*3; |
| 10650 | else |
| 10651 | bpp = 8*3; |
| 10652 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10653 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10654 | pipe_config->pipe_bpp = bpp; |
| 10655 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10656 | state = pipe_config->base.state; |
| 10657 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10658 | /* Clamp display bpp to EDID value */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10659 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10660 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10661 | continue; |
| 10662 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10663 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 10664 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10665 | } |
| 10666 | |
| 10667 | return bpp; |
| 10668 | } |
| 10669 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10670 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10671 | { |
| 10672 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10673 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10674 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10675 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10676 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10677 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10678 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10679 | } |
| 10680 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10681 | static inline void |
| 10682 | 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] | 10683 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10684 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 10685 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10686 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10687 | m_n->gmch_m, m_n->gmch_n, |
| 10688 | m_n->link_m, m_n->link_n, m_n->tu); |
| 10689 | } |
| 10690 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10691 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 10692 | |
| 10693 | static const char * const output_type_str[] = { |
| 10694 | OUTPUT_TYPE(UNUSED), |
| 10695 | OUTPUT_TYPE(ANALOG), |
| 10696 | OUTPUT_TYPE(DVO), |
| 10697 | OUTPUT_TYPE(SDVO), |
| 10698 | OUTPUT_TYPE(LVDS), |
| 10699 | OUTPUT_TYPE(TVOUT), |
| 10700 | OUTPUT_TYPE(HDMI), |
| 10701 | OUTPUT_TYPE(DP), |
| 10702 | OUTPUT_TYPE(EDP), |
| 10703 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 10704 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10705 | OUTPUT_TYPE(DP_MST), |
| 10706 | }; |
| 10707 | |
| 10708 | #undef OUTPUT_TYPE |
| 10709 | |
| 10710 | static void snprintf_output_types(char *buf, size_t len, |
| 10711 | unsigned int output_types) |
| 10712 | { |
| 10713 | char *str = buf; |
| 10714 | int i; |
| 10715 | |
| 10716 | str[0] = '\0'; |
| 10717 | |
| 10718 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 10719 | int r; |
| 10720 | |
| 10721 | if ((output_types & BIT(i)) == 0) |
| 10722 | continue; |
| 10723 | |
| 10724 | r = snprintf(str, len, "%s%s", |
| 10725 | str != buf ? "," : "", output_type_str[i]); |
| 10726 | if (r >= len) |
| 10727 | break; |
| 10728 | str += r; |
| 10729 | len -= r; |
| 10730 | |
| 10731 | output_types &= ~BIT(i); |
| 10732 | } |
| 10733 | |
| 10734 | WARN_ON_ONCE(output_types != 0); |
| 10735 | } |
| 10736 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10737 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10738 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10739 | const char *context) |
| 10740 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10741 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 10742 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10743 | struct drm_plane *plane; |
| 10744 | struct intel_plane *intel_plane; |
| 10745 | struct intel_plane_state *state; |
| 10746 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10747 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10748 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 10749 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 10750 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10751 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10752 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 10753 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 10754 | buf, pipe_config->output_types); |
| 10755 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 10756 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 10757 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10758 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 10759 | |
| 10760 | if (pipe_config->has_pch_encoder) |
| 10761 | intel_dump_m_n_config(pipe_config, "fdi", |
| 10762 | pipe_config->fdi_lanes, |
| 10763 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10764 | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 10765 | if (pipe_config->ycbcr420) |
| 10766 | DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n"); |
| 10767 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10768 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 10769 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 10770 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 10771 | if (pipe_config->has_drrs) |
| 10772 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 10773 | pipe_config->lane_count, |
| 10774 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10775 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10776 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 10777 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 10778 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 10779 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10780 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10781 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10782 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10783 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 10784 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 10785 | 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] | 10786 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 10787 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 10788 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 10789 | |
| 10790 | if (INTEL_GEN(dev_priv) >= 9) |
| 10791 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 10792 | crtc->num_scalers, |
| 10793 | pipe_config->scaler_state.scaler_users, |
| 10794 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 10795 | |
| 10796 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 10797 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 10798 | pipe_config->gmch_pfit.control, |
| 10799 | pipe_config->gmch_pfit.pgm_ratios, |
| 10800 | pipe_config->gmch_pfit.lvds_border_bits); |
| 10801 | else |
| 10802 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 10803 | pipe_config->pch_pfit.pos, |
| 10804 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 10805 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 10806 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 10807 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 10808 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10809 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 10810 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 10811 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10812 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 10813 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 10814 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10815 | intel_plane = to_intel_plane(plane); |
| 10816 | if (intel_plane->pipe != crtc->pipe) |
| 10817 | continue; |
| 10818 | |
| 10819 | state = to_intel_plane_state(plane->state); |
| 10820 | fb = state->base.fb; |
| 10821 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 10822 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 10823 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10824 | continue; |
| 10825 | } |
| 10826 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 10827 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 10828 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 10829 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 10830 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 10831 | if (INTEL_GEN(dev_priv) >= 9) |
| 10832 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 10833 | state->scaler_id, |
| 10834 | state->base.src.x1 >> 16, |
| 10835 | state->base.src.y1 >> 16, |
| 10836 | drm_rect_width(&state->base.src) >> 16, |
| 10837 | drm_rect_height(&state->base.src) >> 16, |
| 10838 | state->base.dst.x1, state->base.dst.y1, |
| 10839 | drm_rect_width(&state->base.dst), |
| 10840 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10841 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10842 | } |
| 10843 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10844 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10845 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10846 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10847 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 10848 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10849 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 10850 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 10851 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10852 | |
| 10853 | /* |
| 10854 | * Walk the connector list instead of the encoder |
| 10855 | * list to detect the problem on ddi platforms |
| 10856 | * where there's just one encoder per digital port. |
| 10857 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 10858 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 10859 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 10860 | struct drm_connector_state *connector_state; |
| 10861 | struct intel_encoder *encoder; |
| 10862 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 10863 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 10864 | if (!connector_state) |
| 10865 | connector_state = connector->state; |
| 10866 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10867 | if (!connector_state->best_encoder) |
| 10868 | continue; |
| 10869 | |
| 10870 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 10871 | |
| 10872 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10873 | |
| 10874 | switch (encoder->type) { |
| 10875 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 10876 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 10877 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10878 | break; |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 10879 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10880 | case INTEL_OUTPUT_HDMI: |
| 10881 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 10882 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10883 | |
| 10884 | /* the same port mustn't appear more than once */ |
| 10885 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 10886 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10887 | |
| 10888 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 10889 | break; |
| 10890 | case INTEL_OUTPUT_DP_MST: |
| 10891 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 10892 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 10893 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10894 | default: |
| 10895 | break; |
| 10896 | } |
| 10897 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 10898 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10899 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 10900 | /* can't mix MST and SST/HDMI on the same port */ |
| 10901 | if (used_ports & used_mst_ports) |
| 10902 | return false; |
| 10903 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 10904 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10905 | } |
| 10906 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10907 | static void |
| 10908 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 10909 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 10910 | struct drm_i915_private *dev_priv = |
| 10911 | to_i915(crtc_state->base.crtc->dev); |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 10912 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 10913 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10914 | struct intel_shared_dpll *shared_dpll; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 10915 | struct intel_crtc_wm_state wm_state; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 10916 | bool force_thru, ips_force_disable; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10917 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 10918 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 10919 | * kzalloc'd. Code that depends on any field being zero should be |
| 10920 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 10921 | * only fields that are know to not cause problems are preserved. */ |
| 10922 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 10923 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 10924 | shared_dpll = crtc_state->shared_dpll; |
| 10925 | dpll_hw_state = crtc_state->dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 10926 | force_thru = crtc_state->pch_pfit.force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 10927 | ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10928 | if (IS_G4X(dev_priv) || |
| 10929 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 10930 | wm_state = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 10931 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 10932 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 10933 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
| 10934 | memset(&crtc_state->base + 1, 0, |
| 10935 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 10936 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 10937 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 10938 | crtc_state->shared_dpll = shared_dpll; |
| 10939 | crtc_state->dpll_hw_state = dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 10940 | crtc_state->pch_pfit.force_thru = force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 10941 | crtc_state->ips_force_disable = ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10942 | if (IS_G4X(dev_priv) || |
| 10943 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 10944 | crtc_state->wm = wm_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10945 | } |
| 10946 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 10947 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10948 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 10949 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10950 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 10951 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10952 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10953 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10954 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 10955 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10956 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10957 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10958 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10959 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10960 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 10961 | pipe_config->cpu_transcoder = |
| 10962 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10963 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10964 | /* |
| 10965 | * Sanitize sync polarity flags based on requested ones. If neither |
| 10966 | * positive or negative polarity is requested, treat this as meaning |
| 10967 | * negative polarity. |
| 10968 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10969 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10970 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10971 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10972 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10973 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10974 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10975 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10976 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 10977 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 10978 | pipe_config); |
| 10979 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10980 | goto fail; |
| 10981 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10982 | /* |
| 10983 | * Determine the real pipe dimensions. Note that stereo modes can |
| 10984 | * increase the actual pipe size due to the frame doubling and |
| 10985 | * insertion of additional space for blanks between the frame. This |
| 10986 | * is stored in the crtc timings. We use the requested mode to do this |
| 10987 | * computation to clearly distinguish it from the adjusted mode, which |
| 10988 | * can be changed by the connectors in the below retry loop. |
| 10989 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 10990 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 10991 | &pipe_config->pipe_src_w, |
| 10992 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10993 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10994 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 10995 | if (connector_state->crtc != crtc) |
| 10996 | continue; |
| 10997 | |
| 10998 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 10999 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11000 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11001 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 11002 | goto fail; |
| 11003 | } |
| 11004 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11005 | /* |
| 11006 | * Determine output_types before calling the .compute_config() |
| 11007 | * hooks so that the hooks can use this information safely. |
| 11008 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11009 | if (encoder->compute_output_type) |
| 11010 | pipe_config->output_types |= |
| 11011 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11012 | connector_state)); |
| 11013 | else |
| 11014 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11015 | } |
| 11016 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11017 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11018 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11019 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11020 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11021 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11022 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11023 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11024 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11025 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11026 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11027 | * adjust it according to limitations or connector properties, and also |
| 11028 | * a chance to reject the mode entirely. |
| 11029 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11030 | 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] | 11031 | if (connector_state->crtc != crtc) |
| 11032 | continue; |
| 11033 | |
| 11034 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11035 | |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 11036 | if (!(encoder->compute_config(encoder, pipe_config, connector_state))) { |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 11037 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11038 | goto fail; |
| 11039 | } |
| 11040 | } |
| 11041 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11042 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11043 | * done afterwards in case the encoder adjusts the mode. */ |
| 11044 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11045 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11046 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11047 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11048 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11049 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11050 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 11051 | goto fail; |
| 11052 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11053 | |
| 11054 | if (ret == RETRY) { |
| 11055 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 11056 | ret = -EINVAL; |
| 11057 | goto fail; |
| 11058 | } |
| 11059 | |
| 11060 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11061 | retry = false; |
| 11062 | goto encoder_retry; |
| 11063 | } |
| 11064 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11065 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11066 | * only enable it on 6bpc panels and when its not a compliance |
| 11067 | * test requesting 6bpc video pattern. |
| 11068 | */ |
| 11069 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11070 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11071 | 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] | 11072 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11073 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11074 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11075 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11076 | } |
| 11077 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11078 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11079 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11080 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11081 | |
| 11082 | if (clock1 == clock2) |
| 11083 | return true; |
| 11084 | |
| 11085 | if (!clock1 || !clock2) |
| 11086 | return false; |
| 11087 | |
| 11088 | diff = abs(clock1 - clock2); |
| 11089 | |
| 11090 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11091 | return true; |
| 11092 | |
| 11093 | return false; |
| 11094 | } |
| 11095 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11096 | static bool |
| 11097 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11098 | unsigned int m2, unsigned int n2, |
| 11099 | bool exact) |
| 11100 | { |
| 11101 | if (m == m2 && n == n2) |
| 11102 | return true; |
| 11103 | |
| 11104 | if (exact || !m || !n || !m2 || !n2) |
| 11105 | return false; |
| 11106 | |
| 11107 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11108 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11109 | if (n > n2) { |
| 11110 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11111 | m2 <<= 1; |
| 11112 | n2 <<= 1; |
| 11113 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11114 | } else if (n < n2) { |
| 11115 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11116 | m <<= 1; |
| 11117 | n <<= 1; |
| 11118 | } |
| 11119 | } |
| 11120 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11121 | if (n != n2) |
| 11122 | return false; |
| 11123 | |
| 11124 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11125 | } |
| 11126 | |
| 11127 | static bool |
| 11128 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11129 | struct intel_link_m_n *m2_n2, |
| 11130 | bool adjust) |
| 11131 | { |
| 11132 | if (m_n->tu == m2_n2->tu && |
| 11133 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11134 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11135 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11136 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11137 | if (adjust) |
| 11138 | *m2_n2 = *m_n; |
| 11139 | |
| 11140 | return true; |
| 11141 | } |
| 11142 | |
| 11143 | return false; |
| 11144 | } |
| 11145 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11146 | static void __printf(3, 4) |
| 11147 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11148 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11149 | struct va_format vaf; |
| 11150 | va_list args; |
| 11151 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11152 | va_start(args, format); |
| 11153 | vaf.fmt = format; |
| 11154 | vaf.va = &args; |
| 11155 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11156 | if (adjust) |
| 11157 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11158 | else |
| 11159 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11160 | |
| 11161 | va_end(args); |
| 11162 | } |
| 11163 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11164 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11165 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11166 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11167 | struct intel_crtc_state *pipe_config, |
| 11168 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11169 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11170 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11171 | bool fixup_inherited = adjust && |
| 11172 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11173 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11174 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11175 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11176 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11177 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11178 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11179 | current_config->name, \ |
| 11180 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11181 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11182 | } \ |
| 11183 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11184 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11185 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11186 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11187 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11188 | "(expected %i, found %i)\n", \ |
| 11189 | current_config->name, \ |
| 11190 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11191 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11192 | } \ |
| 11193 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11194 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11195 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11196 | if (current_config->name != pipe_config->name) { \ |
| 11197 | pipe_config_err(adjust, __stringify(name), \ |
| 11198 | "(expected %s, found %s)\n", \ |
| 11199 | yesno(current_config->name), \ |
| 11200 | yesno(pipe_config->name)); \ |
| 11201 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11202 | } \ |
| 11203 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11204 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11205 | /* |
| 11206 | * Checks state where we only read out the enabling, but not the entire |
| 11207 | * state itself (like full infoframes or ELD for audio). These states |
| 11208 | * require a full modeset on bootup to fix up. |
| 11209 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11210 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11211 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11212 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11213 | } else { \ |
| 11214 | pipe_config_err(adjust, __stringify(name), \ |
| 11215 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11216 | yesno(current_config->name), \ |
| 11217 | yesno(pipe_config->name)); \ |
| 11218 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11219 | } \ |
| 11220 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11221 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11222 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11223 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11224 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11225 | "(expected %p, found %p)\n", \ |
| 11226 | current_config->name, \ |
| 11227 | pipe_config->name); \ |
| 11228 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11229 | } \ |
| 11230 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11231 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11232 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11233 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11234 | &pipe_config->name,\ |
| 11235 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11236 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11237 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11238 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11239 | current_config->name.tu, \ |
| 11240 | current_config->name.gmch_m, \ |
| 11241 | current_config->name.gmch_n, \ |
| 11242 | current_config->name.link_m, \ |
| 11243 | current_config->name.link_n, \ |
| 11244 | pipe_config->name.tu, \ |
| 11245 | pipe_config->name.gmch_m, \ |
| 11246 | pipe_config->name.gmch_n, \ |
| 11247 | pipe_config->name.link_m, \ |
| 11248 | pipe_config->name.link_n); \ |
| 11249 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11250 | } \ |
| 11251 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11252 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 11253 | /* This is required for BDW+ where there is only one set of registers for |
| 11254 | * switching between high and low RR. |
| 11255 | * This macro can be used whenever a comparison has to be made between one |
| 11256 | * hw state and multiple sw state variables. |
| 11257 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11258 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11259 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11260 | &pipe_config->name, adjust) && \ |
| 11261 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 11262 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11263 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11264 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11265 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 11266 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11267 | current_config->name.tu, \ |
| 11268 | current_config->name.gmch_m, \ |
| 11269 | current_config->name.gmch_n, \ |
| 11270 | current_config->name.link_m, \ |
| 11271 | current_config->name.link_n, \ |
| 11272 | current_config->alt_name.tu, \ |
| 11273 | current_config->alt_name.gmch_m, \ |
| 11274 | current_config->alt_name.gmch_n, \ |
| 11275 | current_config->alt_name.link_m, \ |
| 11276 | current_config->alt_name.link_n, \ |
| 11277 | pipe_config->name.tu, \ |
| 11278 | pipe_config->name.gmch_m, \ |
| 11279 | pipe_config->name.gmch_n, \ |
| 11280 | pipe_config->name.link_m, \ |
| 11281 | pipe_config->name.link_n); \ |
| 11282 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11283 | } \ |
| 11284 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11285 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11286 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11287 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11288 | pipe_config_err(adjust, __stringify(name), \ |
| 11289 | "(%x) (expected %i, found %i)\n", \ |
| 11290 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11291 | current_config->name & (mask), \ |
| 11292 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11293 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11294 | } \ |
| 11295 | } while (0) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11296 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11297 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11298 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11299 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11300 | "(expected %i, found %i)\n", \ |
| 11301 | current_config->name, \ |
| 11302 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11303 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11304 | } \ |
| 11305 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11306 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11307 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11308 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11309 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11310 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11311 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11312 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11313 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11314 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11315 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11316 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 11317 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11318 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11319 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11320 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11321 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11322 | if (current_config->has_drrs) |
| 11323 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 11324 | } else |
| 11325 | 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] | 11326 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11327 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 11328 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11329 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11330 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11331 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11332 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11333 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11334 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11335 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11336 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11337 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11338 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11339 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11340 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11341 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11342 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11343 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11344 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 11345 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 11346 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11347 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 11348 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11349 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 11350 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11351 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11352 | PIPE_CONF_CHECK_BOOL(ycbcr420); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11353 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11354 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11355 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11356 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11357 | DRM_MODE_FLAG_INTERLACE); |
| 11358 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11359 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11360 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11361 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11362 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11363 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11364 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11365 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11366 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11367 | DRM_MODE_FLAG_NVSYNC); |
| 11368 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11369 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11370 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 11371 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11372 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 11373 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11374 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11375 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11376 | if (!adjust) { |
| 11377 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11378 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 11379 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11380 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11381 | if (current_config->pch_pfit.enabled) { |
| 11382 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 11383 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 11384 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11385 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11386 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11387 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11388 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 11389 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11390 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11391 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11392 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11393 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11394 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11395 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11396 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11397 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 11398 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11399 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11400 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11401 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 11402 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 11403 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 11404 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 11405 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 11406 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 11407 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 11408 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 11409 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 11410 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 11411 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 11412 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 11413 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 11414 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 11415 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 11416 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 11417 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 11418 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 11419 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 11420 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 11421 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 11422 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 11423 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11424 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 11425 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 11426 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 11427 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11428 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11429 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11430 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11431 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11432 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11433 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 11434 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 11435 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11436 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11437 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11438 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11439 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11440 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11441 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11442 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11443 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11444 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11445 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11446 | } |
| 11447 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11448 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 11449 | const struct intel_crtc_state *pipe_config) |
| 11450 | { |
| 11451 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 11452 | 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] | 11453 | &pipe_config->fdi_m_n); |
| 11454 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 11455 | |
| 11456 | /* |
| 11457 | * FDI already provided one idea for the dotclock. |
| 11458 | * Yell if the encoder disagrees. |
| 11459 | */ |
| 11460 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 11461 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 11462 | fdi_dotclock, dotclock); |
| 11463 | } |
| 11464 | } |
| 11465 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11466 | static void verify_wm_state(struct drm_crtc *crtc, |
| 11467 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11468 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11469 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11470 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11471 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 11472 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 11473 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11474 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11475 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11476 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11477 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11478 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11479 | return; |
| 11480 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11481 | skl_pipe_wm_get_hw_state(crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 11482 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11483 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11484 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11485 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11486 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 11487 | if (INTEL_GEN(dev_priv) >= 11) |
| 11488 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 11489 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 11490 | sw_ddb->enabled_slices, |
| 11491 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11492 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 11493 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11494 | hw_plane_wm = &hw_wm.planes[plane]; |
| 11495 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11496 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11497 | /* Watermarks */ |
| 11498 | for (level = 0; level <= max_level; level++) { |
| 11499 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 11500 | &sw_plane_wm->wm[level])) |
| 11501 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11502 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11503 | 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", |
| 11504 | pipe_name(pipe), plane + 1, level, |
| 11505 | sw_plane_wm->wm[level].plane_en, |
| 11506 | sw_plane_wm->wm[level].plane_res_b, |
| 11507 | sw_plane_wm->wm[level].plane_res_l, |
| 11508 | hw_plane_wm->wm[level].plane_en, |
| 11509 | hw_plane_wm->wm[level].plane_res_b, |
| 11510 | hw_plane_wm->wm[level].plane_res_l); |
| 11511 | } |
| 11512 | |
| 11513 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 11514 | &sw_plane_wm->trans_wm)) { |
| 11515 | 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", |
| 11516 | pipe_name(pipe), plane + 1, |
| 11517 | sw_plane_wm->trans_wm.plane_en, |
| 11518 | sw_plane_wm->trans_wm.plane_res_b, |
| 11519 | sw_plane_wm->trans_wm.plane_res_l, |
| 11520 | hw_plane_wm->trans_wm.plane_en, |
| 11521 | hw_plane_wm->trans_wm.plane_res_b, |
| 11522 | hw_plane_wm->trans_wm.plane_res_l); |
| 11523 | } |
| 11524 | |
| 11525 | /* DDB */ |
| 11526 | hw_ddb_entry = &hw_ddb.plane[pipe][plane]; |
| 11527 | sw_ddb_entry = &sw_ddb->plane[pipe][plane]; |
| 11528 | |
| 11529 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 11530 | 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] | 11531 | pipe_name(pipe), plane + 1, |
| 11532 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 11533 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 11534 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11535 | } |
| 11536 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 11537 | /* |
| 11538 | * cursor |
| 11539 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 11540 | * allocation. In that case since the ddb allocation will be updated |
| 11541 | * once the plane becomes visible, we can skip this check |
| 11542 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 11543 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11544 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 11545 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11546 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11547 | /* Watermarks */ |
| 11548 | for (level = 0; level <= max_level; level++) { |
| 11549 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 11550 | &sw_plane_wm->wm[level])) |
| 11551 | continue; |
| 11552 | |
| 11553 | 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", |
| 11554 | pipe_name(pipe), level, |
| 11555 | sw_plane_wm->wm[level].plane_en, |
| 11556 | sw_plane_wm->wm[level].plane_res_b, |
| 11557 | sw_plane_wm->wm[level].plane_res_l, |
| 11558 | hw_plane_wm->wm[level].plane_en, |
| 11559 | hw_plane_wm->wm[level].plane_res_b, |
| 11560 | hw_plane_wm->wm[level].plane_res_l); |
| 11561 | } |
| 11562 | |
| 11563 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 11564 | &sw_plane_wm->trans_wm)) { |
| 11565 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 11566 | pipe_name(pipe), |
| 11567 | sw_plane_wm->trans_wm.plane_en, |
| 11568 | sw_plane_wm->trans_wm.plane_res_b, |
| 11569 | sw_plane_wm->trans_wm.plane_res_l, |
| 11570 | hw_plane_wm->trans_wm.plane_en, |
| 11571 | hw_plane_wm->trans_wm.plane_res_b, |
| 11572 | hw_plane_wm->trans_wm.plane_res_l); |
| 11573 | } |
| 11574 | |
| 11575 | /* DDB */ |
| 11576 | hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 11577 | sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
| 11578 | |
| 11579 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 11580 | 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] | 11581 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11582 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 11583 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 11584 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11585 | } |
| 11586 | } |
| 11587 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11588 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11589 | verify_connector_state(struct drm_device *dev, |
| 11590 | struct drm_atomic_state *state, |
| 11591 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11592 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11593 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11594 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11595 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11596 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11597 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11598 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11599 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11600 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11601 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11602 | continue; |
| 11603 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11604 | if (crtc) |
| 11605 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 11606 | |
| 11607 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11608 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11609 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11610 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11611 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11612 | } |
| 11613 | |
| 11614 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11615 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11616 | { |
| 11617 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11618 | struct drm_connector *connector; |
| 11619 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 11620 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11621 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11622 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11623 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11624 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11625 | |
| 11626 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 11627 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11628 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11629 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11630 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 11631 | new_conn_state, i) { |
| 11632 | if (old_conn_state->best_encoder == &encoder->base) |
| 11633 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11634 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11635 | if (new_conn_state->best_encoder != &encoder->base) |
| 11636 | continue; |
| 11637 | found = enabled = true; |
| 11638 | |
| 11639 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11640 | encoder->base.crtc, |
| 11641 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11642 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11643 | |
| 11644 | if (!found) |
| 11645 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11646 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11647 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11648 | "encoder's enabled state mismatch " |
| 11649 | "(expected %i, found %i)\n", |
| 11650 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11651 | |
| 11652 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11653 | bool active; |
| 11654 | |
| 11655 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11656 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11657 | "encoder detached but still enabled on pipe %c.\n", |
| 11658 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11659 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11660 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11661 | } |
| 11662 | |
| 11663 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11664 | verify_crtc_state(struct drm_crtc *crtc, |
| 11665 | struct drm_crtc_state *old_crtc_state, |
| 11666 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11667 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11668 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11669 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11670 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11671 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11672 | struct intel_crtc_state *pipe_config, *sw_config; |
| 11673 | struct drm_atomic_state *old_state; |
| 11674 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11675 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11676 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 11677 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11678 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 11679 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 11680 | pipe_config->base.crtc = crtc; |
| 11681 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11682 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 11683 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11684 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11685 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11686 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 11687 | /* we keep both pipes enabled on 830 */ |
| 11688 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11689 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11690 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11691 | I915_STATE_WARN(new_crtc_state->active != active, |
| 11692 | "crtc active state doesn't match with hw state " |
| 11693 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11694 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11695 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 11696 | "transitional active state does not match atomic hw state " |
| 11697 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11698 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11699 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 11700 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11701 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11702 | active = encoder->get_hw_state(encoder, &pipe); |
| 11703 | I915_STATE_WARN(active != new_crtc_state->active, |
| 11704 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 11705 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11706 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11707 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 11708 | "Encoder connected to wrong pipe %c\n", |
| 11709 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11710 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 11711 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11712 | encoder->get_config(encoder, pipe_config); |
| 11713 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11714 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11715 | intel_crtc_compute_pixel_rate(pipe_config); |
| 11716 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11717 | if (!new_crtc_state->active) |
| 11718 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11719 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11720 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11721 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11722 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11723 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11724 | pipe_config, false)) { |
| 11725 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 11726 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 11727 | "[hw state]"); |
| 11728 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 11729 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11730 | } |
| 11731 | } |
| 11732 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11733 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 11734 | intel_verify_planes(struct intel_atomic_state *state) |
| 11735 | { |
| 11736 | struct intel_plane *plane; |
| 11737 | const struct intel_plane_state *plane_state; |
| 11738 | int i; |
| 11739 | |
| 11740 | for_each_new_intel_plane_in_state(state, plane, |
| 11741 | plane_state, i) |
| 11742 | assert_plane(plane, plane_state->base.visible); |
| 11743 | } |
| 11744 | |
| 11745 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11746 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 11747 | struct intel_shared_dpll *pll, |
| 11748 | struct drm_crtc *crtc, |
| 11749 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11750 | { |
| 11751 | struct intel_dpll_hw_state dpll_hw_state; |
| 11752 | unsigned crtc_mask; |
| 11753 | bool active; |
| 11754 | |
| 11755 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 11756 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 11757 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11758 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 11759 | 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] | 11760 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 11761 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11762 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 11763 | "pll in active use but not on in sw tracking\n"); |
| 11764 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 11765 | "pll is on but not used by any active crtc\n"); |
| 11766 | I915_STATE_WARN(pll->on != active, |
| 11767 | "pll on state mismatch (expected %i, found %i)\n", |
| 11768 | pll->on, active); |
| 11769 | } |
| 11770 | |
| 11771 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 11772 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11773 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 11774 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11775 | |
| 11776 | return; |
| 11777 | } |
| 11778 | |
| 11779 | crtc_mask = 1 << drm_crtc_index(crtc); |
| 11780 | |
| 11781 | if (new_state->active) |
| 11782 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 11783 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 11784 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 11785 | else |
| 11786 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 11787 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 11788 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 11789 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 11790 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11791 | "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] | 11792 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11793 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 11794 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11795 | &dpll_hw_state, |
| 11796 | sizeof(dpll_hw_state)), |
| 11797 | "pll hw state mismatch\n"); |
| 11798 | } |
| 11799 | |
| 11800 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11801 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 11802 | struct drm_crtc_state *old_crtc_state, |
| 11803 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11804 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11805 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11806 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 11807 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 11808 | |
| 11809 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11810 | 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] | 11811 | |
| 11812 | if (old_state->shared_dpll && |
| 11813 | old_state->shared_dpll != new_state->shared_dpll) { |
| 11814 | unsigned crtc_mask = 1 << drm_crtc_index(crtc); |
| 11815 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 11816 | |
| 11817 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 11818 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 11819 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 11820 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11821 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 11822 | pipe_name(drm_crtc_index(crtc))); |
| 11823 | } |
| 11824 | } |
| 11825 | |
| 11826 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11827 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11828 | struct drm_atomic_state *state, |
| 11829 | struct drm_crtc_state *old_state, |
| 11830 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11831 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11832 | if (!needs_modeset(new_state) && |
| 11833 | !to_intel_crtc_state(new_state)->update_pipe) |
| 11834 | return; |
| 11835 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11836 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11837 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11838 | verify_crtc_state(crtc, old_state, new_state); |
| 11839 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11840 | } |
| 11841 | |
| 11842 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11843 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11844 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11845 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11846 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11847 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11848 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11849 | 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] | 11850 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11851 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11852 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11853 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 11854 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11855 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11856 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11857 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11858 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11859 | } |
| 11860 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11861 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 11862 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11863 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11864 | |
| 11865 | /* |
| 11866 | * The scanline counter increments at the leading edge of hsync. |
| 11867 | * |
| 11868 | * On most platforms it starts counting from vtotal-1 on the |
| 11869 | * first active line. That means the scanline counter value is |
| 11870 | * always one less than what we would expect. Ie. just after |
| 11871 | * start of vblank, which also occurs at start of hsync (on the |
| 11872 | * last active line), the scanline counter will read vblank_start-1. |
| 11873 | * |
| 11874 | * On gen2 the scanline counter starts counting from 1 instead |
| 11875 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 11876 | * to keep the value positive), instead of adding one. |
| 11877 | * |
| 11878 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 11879 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 11880 | * there's an extra 1 line difference. So we need to add two instead of |
| 11881 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 11882 | * |
| 11883 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 11884 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 11885 | * that means we can't tell whether we're in vblank or not while |
| 11886 | * we're on that particular line. We must still set scanline_offset |
| 11887 | * to 1 so that the vblank timestamps come out correct when we query |
| 11888 | * the scanline counter from within the vblank interrupt handler. |
| 11889 | * However if queried just before the start of vblank we'll get an |
| 11890 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11891 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11892 | if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 11893 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11894 | int vtotal; |
| 11895 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 11896 | vtotal = adjusted_mode->crtc_vtotal; |
| 11897 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11898 | vtotal /= 2; |
| 11899 | |
| 11900 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11901 | } else if (HAS_DDI(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 11902 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11903 | crtc->scanline_offset = 2; |
| 11904 | } else |
| 11905 | crtc->scanline_offset = 1; |
| 11906 | } |
| 11907 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11908 | 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] | 11909 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11910 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11911 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11912 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11913 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11914 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11915 | |
| 11916 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11917 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11918 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11919 | 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] | 11920 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11921 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11922 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11923 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11924 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11925 | continue; |
| 11926 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11927 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 11928 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11929 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 11930 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 11931 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 11932 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11933 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11934 | } |
| 11935 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 11936 | /* |
| 11937 | * This implements the workaround described in the "notes" section of the mode |
| 11938 | * set sequence documentation. When going from no pipes or single pipe to |
| 11939 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 11940 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 11941 | */ |
| 11942 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 11943 | { |
| 11944 | struct drm_crtc_state *crtc_state; |
| 11945 | struct intel_crtc *intel_crtc; |
| 11946 | struct drm_crtc *crtc; |
| 11947 | struct intel_crtc_state *first_crtc_state = NULL; |
| 11948 | struct intel_crtc_state *other_crtc_state = NULL; |
| 11949 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 11950 | int i; |
| 11951 | |
| 11952 | /* 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] | 11953 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 11954 | intel_crtc = to_intel_crtc(crtc); |
| 11955 | |
| 11956 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 11957 | continue; |
| 11958 | |
| 11959 | if (first_crtc_state) { |
| 11960 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 11961 | break; |
| 11962 | } else { |
| 11963 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 11964 | first_pipe = intel_crtc->pipe; |
| 11965 | } |
| 11966 | } |
| 11967 | |
| 11968 | /* No workaround needed? */ |
| 11969 | if (!first_crtc_state) |
| 11970 | return 0; |
| 11971 | |
| 11972 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 11973 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 11974 | struct intel_crtc_state *pipe_config; |
| 11975 | |
| 11976 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 11977 | if (IS_ERR(pipe_config)) |
| 11978 | return PTR_ERR(pipe_config); |
| 11979 | |
| 11980 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 11981 | |
| 11982 | if (!pipe_config->base.active || |
| 11983 | needs_modeset(&pipe_config->base)) |
| 11984 | continue; |
| 11985 | |
| 11986 | /* 2 or more enabled crtcs means no need for w/a */ |
| 11987 | if (enabled_pipe != INVALID_PIPE) |
| 11988 | return 0; |
| 11989 | |
| 11990 | enabled_pipe = intel_crtc->pipe; |
| 11991 | } |
| 11992 | |
| 11993 | if (enabled_pipe != INVALID_PIPE) |
| 11994 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 11995 | else if (other_crtc_state) |
| 11996 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 11997 | |
| 11998 | return 0; |
| 11999 | } |
| 12000 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12001 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12002 | { |
| 12003 | struct drm_crtc *crtc; |
| 12004 | |
| 12005 | /* Add all pipes to the state */ |
| 12006 | for_each_crtc(state->dev, crtc) { |
| 12007 | struct drm_crtc_state *crtc_state; |
| 12008 | |
| 12009 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12010 | if (IS_ERR(crtc_state)) |
| 12011 | return PTR_ERR(crtc_state); |
| 12012 | } |
| 12013 | |
| 12014 | return 0; |
| 12015 | } |
| 12016 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12017 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12018 | { |
| 12019 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12020 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12021 | /* |
| 12022 | * Add all pipes to the state, and force |
| 12023 | * a modeset on all the active ones. |
| 12024 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12025 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12026 | struct drm_crtc_state *crtc_state; |
| 12027 | int ret; |
| 12028 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12029 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12030 | if (IS_ERR(crtc_state)) |
| 12031 | return PTR_ERR(crtc_state); |
| 12032 | |
| 12033 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12034 | continue; |
| 12035 | |
| 12036 | crtc_state->mode_changed = true; |
| 12037 | |
| 12038 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12039 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12040 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12041 | |
| 12042 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12043 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12044 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12045 | } |
| 12046 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12047 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12048 | } |
| 12049 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12050 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12051 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12052 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12053 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12054 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12055 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12056 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12057 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12058 | if (!check_digital_port_conflicts(state)) { |
| 12059 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12060 | return -EINVAL; |
| 12061 | } |
| 12062 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12063 | intel_state->modeset = true; |
| 12064 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12065 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12066 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12067 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12068 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12069 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12070 | intel_state->active_crtcs |= 1 << i; |
| 12071 | else |
| 12072 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12073 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12074 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12075 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12076 | } |
| 12077 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12078 | /* |
| 12079 | * See if the config requires any additional preparation, e.g. |
| 12080 | * to adjust global state with pipes off. We need to do this |
| 12081 | * here so we can get the modeset_pipe updated config for the new |
| 12082 | * mode set on this crtc. For other crtcs we need to use the |
| 12083 | * adjusted_mode bits in the crtc directly. |
| 12084 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12085 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12086 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12087 | if (ret < 0) |
| 12088 | return ret; |
| 12089 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12090 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12091 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12092 | * holding all the crtc locks, even if we don't end up |
| 12093 | * touching the hardware |
| 12094 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12095 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12096 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12097 | ret = intel_lock_all_pipes(state); |
| 12098 | if (ret < 0) |
| 12099 | return ret; |
| 12100 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12101 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12102 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12103 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12104 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12105 | ret = intel_modeset_all_pipes(state); |
| 12106 | if (ret < 0) |
| 12107 | return ret; |
| 12108 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12109 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12110 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12111 | intel_state->cdclk.logical.cdclk, |
| 12112 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12113 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12114 | intel_state->cdclk.logical.voltage_level, |
| 12115 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12116 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12117 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12118 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12119 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12120 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12121 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12122 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12123 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12124 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12125 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12126 | } |
| 12127 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12128 | /* |
| 12129 | * Handle calculation of various watermark data at the end of the atomic check |
| 12130 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12131 | * handlers to ensure that all derived state has been updated. |
| 12132 | */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12133 | static int calc_watermark_data(struct drm_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12134 | { |
| 12135 | struct drm_device *dev = state->dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12136 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12137 | |
| 12138 | /* Is there platform-specific watermark information to calculate? */ |
| 12139 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12140 | return dev_priv->display.compute_global_watermarks(state); |
| 12141 | |
| 12142 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12143 | } |
| 12144 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12145 | /** |
| 12146 | * intel_atomic_check - validate state object |
| 12147 | * @dev: drm device |
| 12148 | * @state: state to validate |
| 12149 | */ |
| 12150 | static int intel_atomic_check(struct drm_device *dev, |
| 12151 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12152 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12153 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12154 | 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] | 12155 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12156 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12157 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12158 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12159 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12160 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12161 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12162 | crtc_state, i) { |
| 12163 | if (crtc_state->mode.private_flags != |
| 12164 | old_crtc_state->mode.private_flags) |
| 12165 | crtc_state->mode_changed = true; |
| 12166 | } |
| 12167 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12168 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12169 | if (ret) |
| 12170 | return ret; |
| 12171 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12172 | 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] | 12173 | struct intel_crtc_state *pipe_config = |
| 12174 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12175 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12176 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12177 | continue; |
| 12178 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12179 | if (!crtc_state->enable) { |
| 12180 | any_ms = true; |
| 12181 | continue; |
| 12182 | } |
| 12183 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12184 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12185 | if (ret) { |
| 12186 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12187 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12188 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12189 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12190 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 12191 | if (i915_modparams.fastboot && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12192 | intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12193 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12194 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12195 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12196 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12197 | } |
| 12198 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12199 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12200 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12201 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12202 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12203 | needs_modeset(crtc_state) ? |
| 12204 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12205 | } |
| 12206 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12207 | if (any_ms) { |
| 12208 | ret = intel_modeset_checks(state); |
| 12209 | |
| 12210 | if (ret) |
| 12211 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12212 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12213 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12214 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12215 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12216 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12217 | if (ret) |
| 12218 | return ret; |
| 12219 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12220 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12221 | return calc_watermark_data(state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12222 | } |
| 12223 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12224 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12225 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12226 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12227 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12228 | } |
| 12229 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12230 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12231 | { |
| 12232 | struct drm_device *dev = crtc->base.dev; |
| 12233 | |
| 12234 | if (!dev->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 12235 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12236 | |
| 12237 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 12238 | } |
| 12239 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12240 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 12241 | struct drm_atomic_state *state, |
| 12242 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12243 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12244 | { |
| 12245 | struct drm_device *dev = crtc->dev; |
| 12246 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 12247 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12248 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 12249 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12250 | struct intel_plane_state *new_plane_state = |
| 12251 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 12252 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12253 | |
| 12254 | if (modeset) { |
| 12255 | update_scanline_offset(intel_crtc); |
| 12256 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12257 | |
| 12258 | /* vblanks work again, re-enable pipe CRC. */ |
| 12259 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12260 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12261 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12262 | pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12263 | } |
| 12264 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12265 | if (new_plane_state) |
| 12266 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12267 | |
| 12268 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12269 | } |
| 12270 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12271 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12272 | { |
| 12273 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12274 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12275 | int i; |
| 12276 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12277 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12278 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12279 | continue; |
| 12280 | |
| 12281 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12282 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12283 | } |
| 12284 | } |
| 12285 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12286 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12287 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12288 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12289 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 12290 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12291 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12292 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12293 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12294 | unsigned int updated = 0; |
| 12295 | bool progress; |
| 12296 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12297 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12298 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 12299 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12300 | |
| 12301 | const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {}; |
| 12302 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12303 | 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] | 12304 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12305 | if (new_crtc_state->active) |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12306 | entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12307 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12308 | /* If 2nd DBuf slice required, enable it here */ |
| 12309 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 12310 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 12311 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12312 | /* |
| 12313 | * Whenever the number of active pipes changes, we need to make sure we |
| 12314 | * update the pipes in the right order so that their ddb allocations |
| 12315 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 12316 | * cause pipe underruns and other bad stuff. |
| 12317 | */ |
| 12318 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12319 | progress = false; |
| 12320 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12321 | 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] | 12322 | bool vbl_wait = false; |
| 12323 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12324 | |
| 12325 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12326 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12327 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12328 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12329 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12330 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12331 | |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 12332 | if (skl_ddb_allocation_overlaps(dev_priv, |
| 12333 | entries, |
| 12334 | &cstate->wm.skl.ddb, |
| 12335 | i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12336 | continue; |
| 12337 | |
| 12338 | updated |= cmask; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12339 | entries[i] = &cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12340 | |
| 12341 | /* |
| 12342 | * If this is an already active pipe, it's DDB changed, |
| 12343 | * and this isn't the last pipe that needs updating |
| 12344 | * then we need to wait for a vblank to pass for the |
| 12345 | * new ddb allocation to take effect. |
| 12346 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12347 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 12348 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12349 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12350 | intel_state->wm_results.dirty_pipes != updated) |
| 12351 | vbl_wait = true; |
| 12352 | |
| 12353 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12354 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12355 | |
| 12356 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12357 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12358 | |
| 12359 | progress = true; |
| 12360 | } |
| 12361 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12362 | |
| 12363 | /* If 2nd DBuf slice is no more required disable it */ |
| 12364 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 12365 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12366 | } |
| 12367 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 12368 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 12369 | { |
| 12370 | struct intel_atomic_state *state, *next; |
| 12371 | struct llist_node *freed; |
| 12372 | |
| 12373 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 12374 | llist_for_each_entry_safe(state, next, freed, freed) |
| 12375 | drm_atomic_state_put(&state->base); |
| 12376 | } |
| 12377 | |
| 12378 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 12379 | { |
| 12380 | struct drm_i915_private *dev_priv = |
| 12381 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 12382 | |
| 12383 | intel_atomic_helper_free_state(dev_priv); |
| 12384 | } |
| 12385 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12386 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 12387 | { |
| 12388 | struct wait_queue_entry wait_fence, wait_reset; |
| 12389 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 12390 | |
| 12391 | init_wait_entry(&wait_fence, 0); |
| 12392 | init_wait_entry(&wait_reset, 0); |
| 12393 | for (;;) { |
| 12394 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 12395 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 12396 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 12397 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 12398 | |
| 12399 | |
| 12400 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 12401 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 12402 | break; |
| 12403 | |
| 12404 | schedule(); |
| 12405 | } |
| 12406 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 12407 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 12408 | } |
| 12409 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12410 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12411 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12412 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12413 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12414 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12415 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 12416 | struct drm_crtc *crtc; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12417 | struct intel_crtc_state *intel_cstate; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 12418 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 12419 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12420 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12421 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12422 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 12423 | drm_atomic_helper_wait_for_dependencies(state); |
| 12424 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12425 | if (intel_state->modeset) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12426 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12427 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12428 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12429 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12430 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12431 | if (needs_modeset(new_crtc_state) || |
| 12432 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12433 | |
| 12434 | put_domains[to_intel_crtc(crtc)->pipe] = |
| 12435 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12436 | to_intel_crtc_state(new_crtc_state)); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12437 | } |
| 12438 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12439 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12440 | continue; |
| 12441 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12442 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12443 | to_intel_crtc_state(new_crtc_state)); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 12444 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 12445 | if (old_crtc_state->active) { |
| 12446 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12447 | |
| 12448 | /* |
| 12449 | * We need to disable pipe CRC before disabling the pipe, |
| 12450 | * or we race against vblank off. |
| 12451 | */ |
| 12452 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 12453 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 12454 | dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12455 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 12456 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12457 | intel_disable_shared_dpll(intel_crtc); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 12458 | |
| 12459 | /* |
| 12460 | * Underruns don't always raise |
| 12461 | * interrupts, so check manually. |
| 12462 | */ |
| 12463 | intel_check_cpu_fifo_underruns(dev_priv); |
| 12464 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 12465 | |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12466 | if (!new_crtc_state->active) { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12467 | /* |
| 12468 | * Make sure we don't call initial_watermarks |
| 12469 | * for ILK-style watermark updates. |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 12470 | * |
| 12471 | * No clue what this is supposed to achieve. |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12472 | */ |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 12473 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12474 | dev_priv->display.initial_watermarks(intel_state, |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12475 | to_intel_crtc_state(new_crtc_state)); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12476 | } |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12477 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12478 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12479 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 12480 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 12481 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 12482 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12483 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12484 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12485 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 12486 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 12487 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 12488 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12489 | /* |
| 12490 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 12491 | * have more then one pipe enabled |
| 12492 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 12493 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 12494 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12495 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12496 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12497 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 12498 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12499 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12500 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 12501 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12502 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12503 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12504 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12505 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12506 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12507 | spin_unlock_irq(&dev->event_lock); |
| 12508 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12509 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12510 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12511 | } |
| 12512 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12513 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12514 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12515 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12516 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 12517 | * already, but still need the state for the delayed optimization. To |
| 12518 | * fix this: |
| 12519 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 12520 | * - schedule that vblank worker _before_ calling hw_done |
| 12521 | * - at the start of commit_tail, cancel it _synchrously |
| 12522 | * - switch over to the vblank wait helper in the core after that since |
| 12523 | * we don't need out special handling any more. |
| 12524 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12525 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12526 | |
| 12527 | /* |
| 12528 | * Now that the vblank has passed, we can go ahead and program the |
| 12529 | * optimal watermarks on platforms that need two-step watermark |
| 12530 | * programming. |
| 12531 | * |
| 12532 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 12533 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12534 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 12535 | intel_cstate = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12536 | |
| 12537 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 12538 | dev_priv->display.optimize_watermarks(intel_state, |
| 12539 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12540 | } |
| 12541 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12542 | 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] | 12543 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 12544 | |
| 12545 | if (put_domains[i]) |
| 12546 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 12547 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12548 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12549 | } |
| 12550 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12551 | if (intel_state->modeset) |
| 12552 | intel_verify_planes(intel_state); |
| 12553 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 12554 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 12555 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12556 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12557 | drm_atomic_helper_commit_hw_done(state); |
| 12558 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 12559 | if (intel_state->modeset) { |
| 12560 | /* As one of the primary mmio accessors, KMS has a high |
| 12561 | * likelihood of triggering bugs in unclaimed access. After we |
| 12562 | * finish modesetting, see if an error has been flagged, and if |
| 12563 | * so enable debugging for the next modeset - and hope we catch |
| 12564 | * the culprit. |
| 12565 | */ |
| 12566 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12567 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 12568 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12569 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12570 | drm_atomic_helper_cleanup_planes(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12571 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 12572 | drm_atomic_helper_commit_cleanup_done(state); |
| 12573 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 12574 | drm_atomic_state_put(state); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 12575 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 12576 | intel_atomic_helper_free_state(dev_priv); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12577 | } |
| 12578 | |
| 12579 | static void intel_atomic_commit_work(struct work_struct *work) |
| 12580 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12581 | struct drm_atomic_state *state = |
| 12582 | container_of(work, struct drm_atomic_state, commit_work); |
| 12583 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12584 | intel_atomic_commit_tail(state); |
| 12585 | } |
| 12586 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12587 | static int __i915_sw_fence_call |
| 12588 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 12589 | enum i915_sw_fence_notify notify) |
| 12590 | { |
| 12591 | struct intel_atomic_state *state = |
| 12592 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 12593 | |
| 12594 | switch (notify) { |
| 12595 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12596 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12597 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12598 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 12599 | { |
| 12600 | struct intel_atomic_helper *helper = |
| 12601 | &to_i915(state->base.dev)->atomic_helper; |
| 12602 | |
| 12603 | if (llist_add(&state->freed, &helper->free_list)) |
| 12604 | schedule_work(&helper->free_work); |
| 12605 | break; |
| 12606 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12607 | } |
| 12608 | |
| 12609 | return NOTIFY_DONE; |
| 12610 | } |
| 12611 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12612 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 12613 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12614 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12615 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12616 | int i; |
| 12617 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12618 | 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] | 12619 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12620 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 12621 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12622 | } |
| 12623 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12624 | /** |
| 12625 | * intel_atomic_commit - commit validated state object |
| 12626 | * @dev: DRM device |
| 12627 | * @state: the top-level driver state object |
| 12628 | * @nonblock: nonblocking commit |
| 12629 | * |
| 12630 | * This function commits a top-level state object that has been validated |
| 12631 | * with drm_atomic_helper_check(). |
| 12632 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12633 | * RETURNS |
| 12634 | * Zero for success or -errno. |
| 12635 | */ |
| 12636 | static int intel_atomic_commit(struct drm_device *dev, |
| 12637 | struct drm_atomic_state *state, |
| 12638 | bool nonblock) |
| 12639 | { |
| 12640 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12641 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12642 | int ret = 0; |
| 12643 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12644 | drm_atomic_state_get(state); |
| 12645 | i915_sw_fence_init(&intel_state->commit_ready, |
| 12646 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12647 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 12648 | /* |
| 12649 | * The intel_legacy_cursor_update() fast path takes care |
| 12650 | * of avoiding the vblank waits for simple cursor |
| 12651 | * movement and flips. For cursor on/off and size changes, |
| 12652 | * we want to perform the vblank waits so that watermark |
| 12653 | * updates happen during the correct frames. Gen9+ have |
| 12654 | * double buffered watermarks and so shouldn't need this. |
| 12655 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 12656 | * Unset state->legacy_cursor_update before the call to |
| 12657 | * drm_atomic_helper_setup_commit() because otherwise |
| 12658 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 12659 | * we get FIFO underruns because we didn't wait |
| 12660 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 12661 | * |
| 12662 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 12663 | * (assuming we had any) would solve these problems. |
| 12664 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 12665 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 12666 | struct intel_crtc_state *new_crtc_state; |
| 12667 | struct intel_crtc *crtc; |
| 12668 | int i; |
| 12669 | |
| 12670 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 12671 | if (new_crtc_state->wm.need_postvbl_update || |
| 12672 | new_crtc_state->update_wm_post) |
| 12673 | state->legacy_cursor_update = false; |
| 12674 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 12675 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 12676 | ret = intel_atomic_prepare_commit(dev, state); |
| 12677 | if (ret) { |
| 12678 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 12679 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 12680 | return ret; |
| 12681 | } |
| 12682 | |
| 12683 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 12684 | if (!ret) |
| 12685 | ret = drm_atomic_helper_swap_state(state, true); |
| 12686 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 12687 | if (ret) { |
| 12688 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 12689 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 12690 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 12691 | return ret; |
| 12692 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12693 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 12694 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12695 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12696 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12697 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 12698 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 12699 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12700 | memcpy(dev_priv->min_voltage_level, |
| 12701 | intel_state->min_voltage_level, |
| 12702 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12703 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12704 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 12705 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12706 | } |
| 12707 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 12708 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12709 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12710 | |
| 12711 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 12712 | if (nonblock && intel_state->modeset) { |
| 12713 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 12714 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12715 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 12716 | } else { |
| 12717 | if (intel_state->modeset) |
| 12718 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12719 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 12720 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 12721 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12722 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 12723 | } |
| 12724 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12725 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 12726 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12727 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12728 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 12729 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 12730 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 12731 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 12732 | .set_crc_source = intel_crtc_set_crc_source, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12733 | }; |
| 12734 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 12735 | struct wait_rps_boost { |
| 12736 | struct wait_queue_entry wait; |
| 12737 | |
| 12738 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 12739 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 12740 | }; |
| 12741 | |
| 12742 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 12743 | unsigned mode, int sync, void *key) |
| 12744 | { |
| 12745 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 12746 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 12747 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 12748 | /* |
| 12749 | * If we missed the vblank, but the request is already running it |
| 12750 | * is reasonable to assume that it will complete before the next |
| 12751 | * vblank without our intervention, so leave RPS alone. |
| 12752 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 12753 | if (!i915_request_started(rq)) |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 12754 | gen6_rps_boost(rq, NULL); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 12755 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 12756 | |
| 12757 | drm_crtc_vblank_put(wait->crtc); |
| 12758 | |
| 12759 | list_del(&wait->wait.entry); |
| 12760 | kfree(wait); |
| 12761 | return 1; |
| 12762 | } |
| 12763 | |
| 12764 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 12765 | struct dma_fence *fence) |
| 12766 | { |
| 12767 | struct wait_rps_boost *wait; |
| 12768 | |
| 12769 | if (!dma_fence_is_i915(fence)) |
| 12770 | return; |
| 12771 | |
| 12772 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 12773 | return; |
| 12774 | |
| 12775 | if (drm_crtc_vblank_get(crtc)) |
| 12776 | return; |
| 12777 | |
| 12778 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 12779 | if (!wait) { |
| 12780 | drm_crtc_vblank_put(crtc); |
| 12781 | return; |
| 12782 | } |
| 12783 | |
| 12784 | wait->request = to_request(dma_fence_get(fence)); |
| 12785 | wait->crtc = crtc; |
| 12786 | |
| 12787 | wait->wait.func = do_rps_boost; |
| 12788 | wait->wait.flags = 0; |
| 12789 | |
| 12790 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 12791 | } |
| 12792 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 12793 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 12794 | { |
| 12795 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 12796 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 12797 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 12798 | struct i915_vma *vma; |
| 12799 | |
| 12800 | if (plane->id == PLANE_CURSOR && |
| 12801 | INTEL_INFO(dev_priv)->cursor_needs_physical) { |
| 12802 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12803 | const int align = intel_cursor_alignment(dev_priv); |
| 12804 | |
| 12805 | return i915_gem_object_attach_phys(obj, align); |
| 12806 | } |
| 12807 | |
| 12808 | vma = intel_pin_and_fence_fb_obj(fb, |
| 12809 | plane_state->base.rotation, |
| 12810 | intel_plane_uses_fence(plane_state), |
| 12811 | &plane_state->flags); |
| 12812 | if (IS_ERR(vma)) |
| 12813 | return PTR_ERR(vma); |
| 12814 | |
| 12815 | plane_state->vma = vma; |
| 12816 | |
| 12817 | return 0; |
| 12818 | } |
| 12819 | |
| 12820 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 12821 | { |
| 12822 | struct i915_vma *vma; |
| 12823 | |
| 12824 | vma = fetch_and_zero(&old_plane_state->vma); |
| 12825 | if (vma) |
| 12826 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 12827 | } |
| 12828 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 12829 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 12830 | { |
| 12831 | struct i915_sched_attr attr = { |
| 12832 | .priority = I915_PRIORITY_DISPLAY, |
| 12833 | }; |
| 12834 | |
| 12835 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 12836 | } |
| 12837 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12838 | /** |
| 12839 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 12840 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 12841 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12842 | * |
| 12843 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 12844 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 12845 | * bits. Some older platforms need special physical address handling for |
| 12846 | * cursor planes. |
| 12847 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12848 | * Must be called with struct_mutex held. |
| 12849 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12850 | * Returns 0 on success, negative error code on failure. |
| 12851 | */ |
| 12852 | int |
| 12853 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 12854 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12855 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12856 | struct intel_atomic_state *intel_state = |
| 12857 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 12858 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 12859 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12860 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 12861 | 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] | 12862 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12863 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12864 | if (old_obj) { |
| 12865 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12866 | drm_atomic_get_new_crtc_state(new_state->state, |
| 12867 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12868 | |
| 12869 | /* Big Hammer, we also need to ensure that any pending |
| 12870 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 12871 | * current scanout is retired before unpinning the old |
| 12872 | * framebuffer. Note that we rely on userspace rendering |
| 12873 | * into the buffer attached to the pipe they are waiting |
| 12874 | * on. If not, userspace generates a GPU hang with IPEHR |
| 12875 | * point to the MI_WAIT_FOR_EVENT. |
| 12876 | * |
| 12877 | * This should only fail upon a hung GPU, in which case we |
| 12878 | * can safely continue. |
| 12879 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12880 | if (needs_modeset(crtc_state)) { |
| 12881 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 12882 | old_obj->resv, NULL, |
| 12883 | false, 0, |
| 12884 | GFP_KERNEL); |
| 12885 | if (ret < 0) |
| 12886 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 12887 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12888 | } |
| 12889 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12890 | if (new_state->fence) { /* explicit fencing */ |
| 12891 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 12892 | new_state->fence, |
| 12893 | I915_FENCE_TIMEOUT, |
| 12894 | GFP_KERNEL); |
| 12895 | if (ret < 0) |
| 12896 | return ret; |
| 12897 | } |
| 12898 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 12899 | if (!obj) |
| 12900 | return 0; |
| 12901 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 12902 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12903 | if (ret) |
| 12904 | return ret; |
| 12905 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 12906 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 12907 | if (ret) { |
| 12908 | i915_gem_object_unpin_pages(obj); |
| 12909 | return ret; |
| 12910 | } |
| 12911 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 12912 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12913 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 12914 | fb_obj_bump_render_priority(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12915 | |
| 12916 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 12917 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12918 | if (ret) |
| 12919 | return ret; |
| 12920 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 12921 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 12922 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12923 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 12924 | struct dma_fence *fence; |
| 12925 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12926 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 12927 | obj->resv, NULL, |
| 12928 | false, I915_FENCE_TIMEOUT, |
| 12929 | GFP_KERNEL); |
| 12930 | if (ret < 0) |
| 12931 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 12932 | |
| 12933 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 12934 | if (fence) { |
| 12935 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 12936 | dma_fence_put(fence); |
| 12937 | } |
| 12938 | } else { |
| 12939 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12940 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12941 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12942 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12943 | } |
| 12944 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12945 | /** |
| 12946 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 12947 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 12948 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12949 | * |
| 12950 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12951 | * |
| 12952 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12953 | */ |
| 12954 | void |
| 12955 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 12956 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12957 | { |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 12958 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12959 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 12960 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 12961 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 12962 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 12963 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12964 | } |
| 12965 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12966 | int |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 12967 | skl_max_scale(struct intel_crtc *intel_crtc, |
| 12968 | struct intel_crtc_state *crtc_state, |
| 12969 | uint32_t pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12970 | { |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 12971 | struct drm_i915_private *dev_priv; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 12972 | int max_scale, mult; |
| 12973 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12974 | |
Maarten Lankhorst | bf8a0af | 2015-11-24 11:29:02 +0100 | [diff] [blame] | 12975 | if (!intel_crtc || !crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12976 | return DRM_PLANE_HELPER_NO_SCALING; |
| 12977 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 12978 | dev_priv = to_i915(intel_crtc->base.dev); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12979 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 12980 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 12981 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 12982 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 12983 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 12984 | max_dotclk *= 2; |
| 12985 | |
| 12986 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12987 | return DRM_PLANE_HELPER_NO_SCALING; |
| 12988 | |
| 12989 | /* |
| 12990 | * skl max scale is lower of: |
| 12991 | * close to 3 but not 3, -1 is for that purpose |
| 12992 | * or |
| 12993 | * cdclk/crtc_clock |
| 12994 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 12995 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 12996 | tmpclk1 = (1 << 16) * mult - 1; |
| 12997 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 12998 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 12999 | |
| 13000 | return max_scale; |
| 13001 | } |
| 13002 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13003 | static int |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 13004 | intel_check_primary_plane(struct intel_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13005 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13006 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13007 | { |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 13008 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13009 | struct drm_crtc *crtc = state->base.crtc; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13010 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13011 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 13012 | bool can_position = false; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13013 | int ret; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13014 | uint32_t pixel_format = 0; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13015 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13016 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 13017 | /* use scaler when colorkey is not required */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 13018 | if (!state->ckey.flags) { |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 13019 | min_scale = 1; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13020 | if (state->base.fb) |
| 13021 | pixel_format = state->base.fb->format->format; |
| 13022 | max_scale = skl_max_scale(to_intel_crtc(crtc), |
| 13023 | crtc_state, pixel_format); |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 13024 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13025 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13026 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13027 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 13028 | ret = drm_atomic_helper_check_plane_state(&state->base, |
| 13029 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 13030 | min_scale, max_scale, |
| 13031 | can_position, true); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13032 | if (ret) |
| 13033 | return ret; |
| 13034 | |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 13035 | if (!state->base.fb) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13036 | return 0; |
| 13037 | |
| 13038 | if (INTEL_GEN(dev_priv) >= 9) { |
Imre Deak | c322c64 | 2018-01-16 13:24:14 +0200 | [diff] [blame] | 13039 | ret = skl_check_plane_surface(crtc_state, state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13040 | if (ret) |
| 13041 | return ret; |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 13042 | |
| 13043 | state->ctl = skl_plane_ctl(crtc_state, state); |
| 13044 | } else { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 13045 | ret = i9xx_check_plane_surface(state); |
| 13046 | if (ret) |
| 13047 | return ret; |
| 13048 | |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 13049 | state->ctl = i9xx_plane_ctl(crtc_state, state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13050 | } |
| 13051 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 13052 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 13053 | state->color_ctl = glk_plane_color_ctl(crtc_state, state); |
| 13054 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 13055 | return 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13056 | } |
| 13057 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13058 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13059 | struct drm_crtc_state *old_crtc_state) |
| 13060 | { |
| 13061 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13062 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13063 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13064 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13065 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13066 | struct intel_atomic_state *old_intel_state = |
| 13067 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13068 | struct intel_crtc_state *intel_cstate = |
| 13069 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13070 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13071 | |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13072 | if (!modeset && |
| 13073 | (intel_cstate->base.color_mgmt_changed || |
| 13074 | intel_cstate->update_pipe)) { |
Ville Syrjälä | 5c857e6 | 2017-08-23 18:22:20 +0300 | [diff] [blame] | 13075 | intel_color_set_csc(&intel_cstate->base); |
| 13076 | intel_color_load_luts(&intel_cstate->base); |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13077 | } |
| 13078 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13079 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13080 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13081 | |
| 13082 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13083 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13084 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13085 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13086 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13087 | else if (INTEL_GEN(dev_priv) >= 9) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13088 | skl_detach_scalers(intel_crtc); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13089 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13090 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13091 | if (dev_priv->display.atomic_update_watermarks) |
| 13092 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13093 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13094 | } |
| 13095 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13096 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13097 | struct intel_crtc_state *crtc_state) |
| 13098 | { |
| 13099 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13100 | |
| 13101 | if (!IS_GEN2(dev_priv)) |
| 13102 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13103 | |
| 13104 | if (crtc_state->has_pch_encoder) { |
| 13105 | enum pipe pch_transcoder = |
| 13106 | intel_crtc_pch_transcoder(crtc); |
| 13107 | |
| 13108 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13109 | } |
| 13110 | } |
| 13111 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13112 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13113 | struct drm_crtc_state *old_crtc_state) |
| 13114 | { |
| 13115 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13116 | struct intel_atomic_state *old_intel_state = |
| 13117 | to_intel_atomic_state(old_crtc_state->state); |
| 13118 | struct intel_crtc_state *new_crtc_state = |
| 13119 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13120 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13121 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13122 | |
| 13123 | if (new_crtc_state->update_pipe && |
| 13124 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13125 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13126 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13127 | } |
| 13128 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13129 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13130 | * intel_plane_destroy - destroy a plane |
| 13131 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13132 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13133 | * Common destruction function for all types of planes (primary, cursor, |
| 13134 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13135 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13136 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13137 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13138 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13139 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13140 | } |
| 13141 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13142 | static bool i8xx_mod_supported(uint32_t format, uint64_t modifier) |
| 13143 | { |
| 13144 | switch (format) { |
| 13145 | case DRM_FORMAT_C8: |
| 13146 | case DRM_FORMAT_RGB565: |
| 13147 | case DRM_FORMAT_XRGB1555: |
| 13148 | case DRM_FORMAT_XRGB8888: |
| 13149 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13150 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13151 | default: |
| 13152 | return false; |
| 13153 | } |
| 13154 | } |
| 13155 | |
| 13156 | static bool i965_mod_supported(uint32_t format, uint64_t modifier) |
| 13157 | { |
| 13158 | switch (format) { |
| 13159 | case DRM_FORMAT_C8: |
| 13160 | case DRM_FORMAT_RGB565: |
| 13161 | case DRM_FORMAT_XRGB8888: |
| 13162 | case DRM_FORMAT_XBGR8888: |
| 13163 | case DRM_FORMAT_XRGB2101010: |
| 13164 | case DRM_FORMAT_XBGR2101010: |
| 13165 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13166 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13167 | default: |
| 13168 | return false; |
| 13169 | } |
| 13170 | } |
| 13171 | |
| 13172 | static bool skl_mod_supported(uint32_t format, uint64_t modifier) |
| 13173 | { |
| 13174 | switch (format) { |
| 13175 | case DRM_FORMAT_XRGB8888: |
| 13176 | case DRM_FORMAT_XBGR8888: |
| 13177 | case DRM_FORMAT_ARGB8888: |
| 13178 | case DRM_FORMAT_ABGR8888: |
| 13179 | if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS || |
| 13180 | modifier == I915_FORMAT_MOD_Y_TILED_CCS) |
| 13181 | return true; |
| 13182 | /* fall through */ |
| 13183 | case DRM_FORMAT_RGB565: |
| 13184 | case DRM_FORMAT_XRGB2101010: |
| 13185 | case DRM_FORMAT_XBGR2101010: |
| 13186 | case DRM_FORMAT_YUYV: |
| 13187 | case DRM_FORMAT_YVYU: |
| 13188 | case DRM_FORMAT_UYVY: |
| 13189 | case DRM_FORMAT_VYUY: |
Chandra Konduru | c0b56ab | 2018-05-12 03:03:16 +0530 | [diff] [blame] | 13190 | case DRM_FORMAT_NV12: |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13191 | if (modifier == I915_FORMAT_MOD_Yf_TILED) |
| 13192 | return true; |
| 13193 | /* fall through */ |
| 13194 | case DRM_FORMAT_C8: |
| 13195 | if (modifier == DRM_FORMAT_MOD_LINEAR || |
| 13196 | modifier == I915_FORMAT_MOD_X_TILED || |
| 13197 | modifier == I915_FORMAT_MOD_Y_TILED) |
| 13198 | return true; |
| 13199 | /* fall through */ |
| 13200 | default: |
| 13201 | return false; |
| 13202 | } |
| 13203 | } |
| 13204 | |
| 13205 | static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane, |
| 13206 | uint32_t format, |
| 13207 | uint64_t modifier) |
| 13208 | { |
| 13209 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
| 13210 | |
| 13211 | if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) |
| 13212 | return false; |
| 13213 | |
| 13214 | if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL && |
| 13215 | modifier != DRM_FORMAT_MOD_LINEAR) |
| 13216 | return false; |
| 13217 | |
| 13218 | if (INTEL_GEN(dev_priv) >= 9) |
| 13219 | return skl_mod_supported(format, modifier); |
| 13220 | else if (INTEL_GEN(dev_priv) >= 4) |
| 13221 | return i965_mod_supported(format, modifier); |
| 13222 | else |
| 13223 | return i8xx_mod_supported(format, modifier); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13224 | } |
| 13225 | |
| 13226 | static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane, |
| 13227 | uint32_t format, |
| 13228 | uint64_t modifier) |
| 13229 | { |
| 13230 | if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) |
| 13231 | return false; |
| 13232 | |
| 13233 | return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888; |
| 13234 | } |
| 13235 | |
| 13236 | static struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 13237 | .update_plane = drm_atomic_helper_update_plane, |
| 13238 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13239 | .destroy = intel_plane_destroy, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 13240 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13241 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13242 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13243 | .atomic_destroy_state = intel_plane_destroy_state, |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13244 | .format_mod_supported = intel_primary_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13245 | }; |
| 13246 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13247 | static int |
| 13248 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13249 | struct drm_crtc *crtc, |
| 13250 | struct drm_framebuffer *fb, |
| 13251 | int crtc_x, int crtc_y, |
| 13252 | unsigned int crtc_w, unsigned int crtc_h, |
| 13253 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13254 | uint32_t src_w, uint32_t src_h, |
| 13255 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13256 | { |
| 13257 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13258 | int ret; |
| 13259 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13260 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13261 | struct drm_framebuffer *old_fb; |
| 13262 | struct drm_crtc_state *crtc_state = crtc->state; |
| 13263 | |
| 13264 | /* |
| 13265 | * When crtc is inactive or there is a modeset pending, |
| 13266 | * wait for it to complete in the slowpath |
| 13267 | */ |
| 13268 | if (!crtc_state->active || needs_modeset(crtc_state) || |
| 13269 | to_intel_crtc_state(crtc_state)->update_pipe) |
| 13270 | goto slow; |
| 13271 | |
| 13272 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13273 | /* |
| 13274 | * Don't do an async update if there is an outstanding commit modifying |
| 13275 | * the plane. This prevents our async update's changes from getting |
| 13276 | * overridden by a previous synchronous update's state. |
| 13277 | */ |
| 13278 | if (old_plane_state->commit && |
| 13279 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 13280 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13281 | |
| 13282 | /* |
| 13283 | * If any parameters change that may affect watermarks, |
| 13284 | * take the slowpath. Only changing fb or position should be |
| 13285 | * in the fastpath. |
| 13286 | */ |
| 13287 | if (old_plane_state->crtc != crtc || |
| 13288 | old_plane_state->src_w != src_w || |
| 13289 | old_plane_state->src_h != src_h || |
| 13290 | old_plane_state->crtc_w != crtc_w || |
| 13291 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13292 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13293 | goto slow; |
| 13294 | |
| 13295 | new_plane_state = intel_plane_duplicate_state(plane); |
| 13296 | if (!new_plane_state) |
| 13297 | return -ENOMEM; |
| 13298 | |
| 13299 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 13300 | |
| 13301 | new_plane_state->src_x = src_x; |
| 13302 | new_plane_state->src_y = src_y; |
| 13303 | new_plane_state->src_w = src_w; |
| 13304 | new_plane_state->src_h = src_h; |
| 13305 | new_plane_state->crtc_x = crtc_x; |
| 13306 | new_plane_state->crtc_y = crtc_y; |
| 13307 | new_plane_state->crtc_w = crtc_w; |
| 13308 | new_plane_state->crtc_h = crtc_h; |
| 13309 | |
| 13310 | ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state), |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 13311 | to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */ |
| 13312 | to_intel_plane_state(plane->state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13313 | to_intel_plane_state(new_plane_state)); |
| 13314 | if (ret) |
| 13315 | goto out_free; |
| 13316 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13317 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13318 | if (ret) |
| 13319 | goto out_free; |
| 13320 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13321 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 13322 | if (ret) |
| 13323 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13324 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 13325 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13326 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13327 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13328 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 13329 | intel_plane->frontbuffer_bit); |
| 13330 | |
| 13331 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13332 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13333 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13334 | if (plane->state->visible) { |
| 13335 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 13336 | intel_plane->update_plane(intel_plane, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13337 | to_intel_crtc_state(crtc->state), |
| 13338 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13339 | } else { |
| 13340 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 13341 | intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13342 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13343 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13344 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13345 | |
| 13346 | out_unlock: |
| 13347 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 13348 | out_free: |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13349 | if (ret) |
| 13350 | intel_plane_destroy_state(plane, new_plane_state); |
| 13351 | else |
| 13352 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13353 | return ret; |
| 13354 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13355 | slow: |
| 13356 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 13357 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13358 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13359 | } |
| 13360 | |
| 13361 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 13362 | .update_plane = intel_legacy_cursor_update, |
| 13363 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13364 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13365 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13366 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13367 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13368 | .atomic_destroy_state = intel_plane_destroy_state, |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13369 | .format_mod_supported = intel_cursor_plane_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13370 | }; |
| 13371 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13372 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 13373 | enum i9xx_plane_id i9xx_plane) |
| 13374 | { |
| 13375 | if (!HAS_FBC(dev_priv)) |
| 13376 | return false; |
| 13377 | |
| 13378 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 13379 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 13380 | else if (IS_IVYBRIDGE(dev_priv)) |
| 13381 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 13382 | i9xx_plane == PLANE_C; |
| 13383 | else if (INTEL_GEN(dev_priv) >= 4) |
| 13384 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 13385 | else |
| 13386 | return i9xx_plane == PLANE_A; |
| 13387 | } |
| 13388 | |
| 13389 | static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 13390 | enum pipe pipe, enum plane_id plane_id) |
| 13391 | { |
| 13392 | if (!HAS_FBC(dev_priv)) |
| 13393 | return false; |
| 13394 | |
| 13395 | return pipe == PIPE_A && plane_id == PLANE_PRIMARY; |
| 13396 | } |
| 13397 | |
Chandra Konduru | c0b56ab | 2018-05-12 03:03:16 +0530 | [diff] [blame] | 13398 | bool skl_plane_has_planar(struct drm_i915_private *dev_priv, |
| 13399 | enum pipe pipe, enum plane_id plane_id) |
| 13400 | { |
| 13401 | if (plane_id == PLANE_PRIMARY) { |
| 13402 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
| 13403 | return false; |
| 13404 | else if ((INTEL_GEN(dev_priv) == 9 && pipe == PIPE_C) && |
| 13405 | !IS_GEMINILAKE(dev_priv)) |
| 13406 | return false; |
| 13407 | } else if (plane_id >= PLANE_SPRITE0) { |
| 13408 | if (plane_id == PLANE_CURSOR) |
| 13409 | return false; |
| 13410 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) == 10) { |
| 13411 | if (plane_id != PLANE_SPRITE0) |
| 13412 | return false; |
| 13413 | } else { |
| 13414 | if (plane_id != PLANE_SPRITE0 || pipe == PIPE_C || |
| 13415 | IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
| 13416 | return false; |
| 13417 | } |
| 13418 | } |
| 13419 | return true; |
| 13420 | } |
| 13421 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13422 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13423 | 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] | 13424 | { |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13425 | struct intel_plane *primary = NULL; |
| 13426 | struct intel_plane_state *state = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13427 | const uint32_t *intel_primary_formats; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13428 | unsigned int supported_rotations; |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 13429 | unsigned int num_formats; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13430 | const uint64_t *modifiers; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13431 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13432 | |
| 13433 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13434 | if (!primary) { |
| 13435 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13436 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13437 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13438 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13439 | state = intel_create_plane_state(&primary->base); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13440 | if (!state) { |
| 13441 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13442 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13443 | } |
| 13444 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13445 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13446 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13447 | primary->can_scale = false; |
| 13448 | primary->max_downscale = 1; |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13449 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13450 | primary->can_scale = true; |
Chandra Konduru | af99ceda | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 13451 | state->scaler_id = -1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13452 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13453 | primary->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13454 | /* |
| 13455 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 13456 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 13457 | */ |
| 13458 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13459 | primary->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13460 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13461 | primary->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 13462 | primary->id = PLANE_PRIMARY; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 13463 | primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13464 | |
| 13465 | if (INTEL_GEN(dev_priv) >= 9) |
| 13466 | primary->has_fbc = skl_plane_has_fbc(dev_priv, |
| 13467 | primary->pipe, |
| 13468 | primary->id); |
| 13469 | else |
| 13470 | primary->has_fbc = i9xx_plane_has_fbc(dev_priv, |
| 13471 | primary->i9xx_plane); |
| 13472 | |
| 13473 | if (primary->has_fbc) { |
| 13474 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 13475 | |
| 13476 | fbc->possible_framebuffer_bits |= primary->frontbuffer_bit; |
| 13477 | } |
| 13478 | |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13479 | primary->check_plane = intel_check_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13480 | |
Ville Syrjälä | 77064e2 | 2017-12-22 21:22:28 +0200 | [diff] [blame] | 13481 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | c0b56ab | 2018-05-12 03:03:16 +0530 | [diff] [blame] | 13482 | if (skl_plane_has_planar(dev_priv, pipe, PLANE_PRIMARY)) { |
| 13483 | intel_primary_formats = skl_pri_planar_formats; |
| 13484 | num_formats = ARRAY_SIZE(skl_pri_planar_formats); |
| 13485 | } else { |
| 13486 | intel_primary_formats = skl_primary_formats; |
| 13487 | num_formats = ARRAY_SIZE(skl_primary_formats); |
| 13488 | } |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13489 | |
Ville Syrjälä | 77064e2 | 2017-12-22 21:22:28 +0200 | [diff] [blame] | 13490 | if (skl_plane_has_ccs(dev_priv, pipe, PLANE_PRIMARY)) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13491 | modifiers = skl_format_modifiers_ccs; |
| 13492 | else |
| 13493 | modifiers = skl_format_modifiers_noccs; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13494 | |
Juha-Pekka Heikkila | 9a8cc57 | 2017-10-17 23:08:09 +0300 | [diff] [blame] | 13495 | primary->update_plane = skl_update_plane; |
Juha-Pekka Heikkila | 779d4d8 | 2017-10-17 23:08:10 +0300 | [diff] [blame] | 13496 | primary->disable_plane = skl_disable_plane; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13497 | primary->get_hw_state = skl_plane_get_hw_state; |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13498 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13499 | intel_primary_formats = i965_primary_formats; |
| 13500 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13501 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13502 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13503 | primary->update_plane = i9xx_update_plane; |
| 13504 | primary->disable_plane = i9xx_disable_plane; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13505 | primary->get_hw_state = i9xx_plane_get_hw_state; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13506 | } else { |
| 13507 | intel_primary_formats = i8xx_primary_formats; |
| 13508 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13509 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13510 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13511 | primary->update_plane = i9xx_update_plane; |
| 13512 | primary->disable_plane = i9xx_disable_plane; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13513 | primary->get_hw_state = i9xx_plane_get_hw_state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13514 | } |
| 13515 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13516 | if (INTEL_GEN(dev_priv) >= 9) |
| 13517 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
| 13518 | 0, &intel_plane_funcs, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13519 | intel_primary_formats, num_formats, |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13520 | modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13521 | DRM_PLANE_TYPE_PRIMARY, |
| 13522 | "plane 1%c", pipe_name(pipe)); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 13523 | else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13524 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
| 13525 | 0, &intel_plane_funcs, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13526 | intel_primary_formats, num_formats, |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13527 | modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13528 | DRM_PLANE_TYPE_PRIMARY, |
| 13529 | "primary %c", pipe_name(pipe)); |
| 13530 | else |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13531 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
| 13532 | 0, &intel_plane_funcs, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13533 | intel_primary_formats, num_formats, |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13534 | modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13535 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13536 | "plane %c", |
| 13537 | plane_name(primary->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13538 | if (ret) |
| 13539 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13540 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 13541 | if (INTEL_GEN(dev_priv) >= 10) { |
| 13542 | supported_rotations = |
| 13543 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | |
| 13544 | DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 | |
| 13545 | DRM_MODE_REFLECT_X; |
| 13546 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13547 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13548 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | |
| 13549 | DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270; |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 13550 | } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
| 13551 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13552 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 13553 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13554 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13555 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13556 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13557 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13558 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13559 | } |
| 13560 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13561 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13562 | drm_plane_create_rotation_property(&primary->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13563 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13564 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13565 | |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 13566 | if (INTEL_GEN(dev_priv) >= 9) |
| 13567 | drm_plane_create_color_properties(&primary->base, |
| 13568 | BIT(DRM_COLOR_YCBCR_BT601) | |
| 13569 | BIT(DRM_COLOR_YCBCR_BT709), |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 13570 | BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | |
| 13571 | BIT(DRM_COLOR_YCBCR_FULL_RANGE), |
Ville Syrjälä | 23b2808 | 2018-02-14 21:23:26 +0200 | [diff] [blame] | 13572 | DRM_COLOR_YCBCR_BT709, |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 13573 | DRM_COLOR_YCBCR_LIMITED_RANGE); |
| 13574 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13575 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 13576 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13577 | return primary; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13578 | |
| 13579 | fail: |
| 13580 | kfree(state); |
| 13581 | kfree(primary); |
| 13582 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13583 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13584 | } |
| 13585 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13586 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13587 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 13588 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13589 | { |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13590 | struct intel_plane *cursor = NULL; |
| 13591 | struct intel_plane_state *state = NULL; |
| 13592 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13593 | |
| 13594 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13595 | if (!cursor) { |
| 13596 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13597 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13598 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13599 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13600 | state = intel_create_plane_state(&cursor->base); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13601 | if (!state) { |
| 13602 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13603 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13604 | } |
| 13605 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13606 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13607 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13608 | cursor->can_scale = false; |
| 13609 | cursor->max_downscale = 1; |
| 13610 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13611 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 13612 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 13613 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13614 | |
| 13615 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 13616 | cursor->update_plane = i845_update_cursor; |
| 13617 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13618 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 13619 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13620 | } else { |
| 13621 | cursor->update_plane = i9xx_update_cursor; |
| 13622 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13623 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 13624 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13625 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13626 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 13627 | cursor->cursor.base = ~0; |
| 13628 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 13629 | |
| 13630 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 13631 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13632 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13633 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13634 | 0, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13635 | intel_cursor_formats, |
| 13636 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13637 | cursor_format_modifiers, |
| 13638 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13639 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13640 | if (ret) |
| 13641 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13642 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13643 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13644 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13645 | DRM_MODE_ROTATE_0, |
| 13646 | DRM_MODE_ROTATE_0 | |
| 13647 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13648 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13649 | if (INTEL_GEN(dev_priv) >= 9) |
Chandra Konduru | af99ceda | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 13650 | state->scaler_id = -1; |
| 13651 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13652 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 13653 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13654 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13655 | |
| 13656 | fail: |
| 13657 | kfree(state); |
| 13658 | kfree(cursor); |
| 13659 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13660 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13661 | } |
| 13662 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13663 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 13664 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13665 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 13666 | struct intel_crtc_scaler_state *scaler_state = |
| 13667 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13668 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13669 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13670 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13671 | crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe]; |
| 13672 | if (!crtc->num_scalers) |
| 13673 | return; |
| 13674 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 13675 | for (i = 0; i < crtc->num_scalers; i++) { |
| 13676 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 13677 | |
| 13678 | scaler->in_use = 0; |
| 13679 | scaler->mode = PS_SCALER_MODE_DYN; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13680 | } |
| 13681 | |
| 13682 | scaler_state->scaler_id = -1; |
| 13683 | } |
| 13684 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 13685 | 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] | 13686 | { |
| 13687 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13688 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13689 | struct intel_plane *primary = NULL; |
| 13690 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13691 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13692 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 13693 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13694 | if (!intel_crtc) |
| 13695 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13696 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13697 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13698 | if (!crtc_state) { |
| 13699 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13700 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13701 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 13702 | intel_crtc->config = crtc_state; |
| 13703 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 13704 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13705 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13706 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13707 | if (IS_ERR(primary)) { |
| 13708 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13709 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13710 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13711 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13712 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13713 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13714 | struct intel_plane *plane; |
| 13715 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13716 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 13717 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13718 | ret = PTR_ERR(plane); |
| 13719 | goto fail; |
| 13720 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13721 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13722 | } |
| 13723 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13724 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 13725 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13726 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13727 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13728 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13729 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13730 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 13731 | 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] | 13732 | &primary->base, &cursor->base, |
| 13733 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 13734 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13735 | if (ret) |
| 13736 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13737 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13738 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13739 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13740 | /* initialize shared scalers */ |
| 13741 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 13742 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 13743 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 13744 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 13745 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 13746 | |
| 13747 | if (INTEL_GEN(dev_priv) < 9) { |
| 13748 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 13749 | |
| 13750 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 13751 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 13752 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 13753 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 13754 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13755 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13756 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 13757 | intel_color_init(&intel_crtc->base); |
| 13758 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13759 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13760 | |
| 13761 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13762 | |
| 13763 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13764 | /* |
| 13765 | * drm_mode_config_cleanup() will free up any |
| 13766 | * crtcs/planes already initialized. |
| 13767 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13768 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13769 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13770 | |
| 13771 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13772 | } |
| 13773 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13774 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 13775 | { |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13776 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13777 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 13778 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13779 | |
Daniel Vetter | 51ec53d | 2017-03-01 10:52:24 +0100 | [diff] [blame] | 13780 | if (!connector->base.state->crtc) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13781 | return INVALID_PIPE; |
| 13782 | |
Daniel Vetter | 51ec53d | 2017-03-01 10:52:24 +0100 | [diff] [blame] | 13783 | return to_intel_crtc(connector->base.state->crtc)->pipe; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13784 | } |
| 13785 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 13786 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 13787 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13788 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13789 | 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] | 13790 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13791 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13792 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 13793 | 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] | 13794 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 13795 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13796 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13797 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13798 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13799 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13800 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13801 | } |
| 13802 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13803 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13804 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13805 | struct drm_device *dev = encoder->base.dev; |
| 13806 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13807 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13808 | int entry = 0; |
| 13809 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13810 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 13811 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13812 | index_mask |= (1 << entry); |
| 13813 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13814 | entry++; |
| 13815 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13816 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13817 | return index_mask; |
| 13818 | } |
| 13819 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 13820 | static bool has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13821 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 13822 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13823 | return false; |
| 13824 | |
| 13825 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 13826 | return false; |
| 13827 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 13828 | if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13829 | return false; |
| 13830 | |
| 13831 | return true; |
| 13832 | } |
| 13833 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13834 | static bool intel_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13835 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13836 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 13837 | return false; |
| 13838 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 13839 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13840 | return false; |
| 13841 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 13842 | if (IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13843 | return false; |
| 13844 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13845 | if (HAS_PCH_LPT_H(dev_priv) && |
| 13846 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 13847 | return false; |
| 13848 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 13849 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13850 | 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] | 13851 | return false; |
| 13852 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 13853 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13854 | return false; |
| 13855 | |
| 13856 | return true; |
| 13857 | } |
| 13858 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 13859 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 13860 | { |
| 13861 | int pps_num; |
| 13862 | int pps_idx; |
| 13863 | |
| 13864 | if (HAS_DDI(dev_priv)) |
| 13865 | return; |
| 13866 | /* |
| 13867 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 13868 | * everywhere where registers can be write protected. |
| 13869 | */ |
| 13870 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 13871 | pps_num = 2; |
| 13872 | else |
| 13873 | pps_num = 1; |
| 13874 | |
| 13875 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 13876 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 13877 | |
| 13878 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 13879 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 13880 | } |
| 13881 | } |
| 13882 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 13883 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 13884 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 13885 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 13886 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 13887 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 13888 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 13889 | else |
| 13890 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 13891 | |
| 13892 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 13893 | } |
| 13894 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13895 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13896 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13897 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13898 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13899 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 13900 | intel_pps_init(dev_priv); |
| 13901 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 13902 | /* |
| 13903 | * intel_edp_init_connector() depends on this completing first, to |
| 13904 | * prevent the registeration of both eDP and LVDS and the incorrect |
| 13905 | * sharing of the PPS. |
| 13906 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13907 | intel_lvds_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13908 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13909 | if (intel_crt_present(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13910 | intel_crt_init(dev_priv); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13911 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 13912 | if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 13913 | /* |
| 13914 | * FIXME: Broxton doesn't support port detection via the |
| 13915 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 13916 | * detect the ports. |
| 13917 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13918 | intel_ddi_init(dev_priv, PORT_A); |
| 13919 | intel_ddi_init(dev_priv, PORT_B); |
| 13920 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 13921 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13922 | intel_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13923 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13924 | int found; |
| 13925 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13926 | /* |
| 13927 | * Haswell uses DDI functions to detect digital outputs. |
| 13928 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 13929 | * it's there. |
| 13930 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 13931 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13932 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 13933 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13934 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13935 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 13936 | /* 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] | 13937 | * register */ |
| 13938 | found = I915_READ(SFUSE_STRAP); |
| 13939 | |
| 13940 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13941 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13942 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13943 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13944 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13945 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 13946 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 13947 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 13948 | /* |
| 13949 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 13950 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 13951 | if (IS_GEN9_BC(dev_priv) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 13952 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 13953 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 13954 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13955 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 13956 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 13957 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13958 | int found; |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 13959 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13960 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 13961 | if (has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13962 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13963 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13964 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 13965 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13966 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13967 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13968 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13969 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13970 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13971 | } |
| 13972 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13973 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13974 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13975 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13976 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13977 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13978 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13979 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13980 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13981 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13982 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 13983 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 13984 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 13985 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 13986 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13987 | /* |
| 13988 | * The DP_DETECTED bit is the latched state of the DDC |
| 13989 | * SDA pin at boot. However since eDP doesn't require DDC |
| 13990 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 13991 | * eDP ports may have been muxed to an alternate function. |
| 13992 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 13993 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 13994 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 13995 | * |
| 13996 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 13997 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 13998 | * and VBT for the presence of the port. Additionally we can't |
| 13999 | * trust the port type the VBT declares as we've seen at least |
| 14000 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14001 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14002 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14003 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14004 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14005 | 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] | 14006 | 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] | 14007 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14008 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14009 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14010 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14011 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14012 | 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] | 14013 | 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] | 14014 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14015 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14016 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14017 | /* |
| 14018 | * eDP not supported on port D, |
| 14019 | * so no need to worry about it |
| 14020 | */ |
| 14021 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14022 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14023 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14024 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14025 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14026 | } |
| 14027 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14028 | intel_dsi_init(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14029 | } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14030 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14031 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14032 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14033 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14034 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14035 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14036 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14037 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14038 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14039 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14040 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14041 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14042 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14043 | |
| 14044 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14045 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14046 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14047 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14048 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14049 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14050 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14051 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14052 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14053 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14054 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14055 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14056 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14057 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14058 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14059 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14060 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14061 | 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] | 14062 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14063 | } else if (IS_GEN2(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14064 | intel_dvo_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14065 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 14066 | if (SUPPORTS_TV(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14067 | intel_tv_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14068 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14069 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14070 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14071 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14072 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14073 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14074 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14075 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14076 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14077 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14078 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14079 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14080 | } |
| 14081 | |
| 14082 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14083 | { |
| 14084 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14085 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14086 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14087 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14088 | i915_gem_object_lock(intel_fb->obj); |
| 14089 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
| 14090 | i915_gem_object_unlock(intel_fb->obj); |
| 14091 | |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 14092 | i915_gem_object_put(intel_fb->obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14093 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14094 | kfree(intel_fb); |
| 14095 | } |
| 14096 | |
| 14097 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14098 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14099 | unsigned int *handle) |
| 14100 | { |
| 14101 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14102 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14103 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14104 | if (obj->userptr.mm) { |
| 14105 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14106 | return -EINVAL; |
| 14107 | } |
| 14108 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14109 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14110 | } |
| 14111 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14112 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14113 | struct drm_file *file, |
| 14114 | unsigned flags, unsigned color, |
| 14115 | struct drm_clip_rect *clips, |
| 14116 | unsigned num_clips) |
| 14117 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14118 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14119 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14120 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14121 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14122 | |
| 14123 | return 0; |
| 14124 | } |
| 14125 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14126 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14127 | .destroy = intel_user_framebuffer_destroy, |
| 14128 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14129 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14130 | }; |
| 14131 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14132 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14133 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
| 14134 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14135 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14136 | u32 gen = INTEL_GEN(dev_priv); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14137 | |
| 14138 | if (gen >= 9) { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14139 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 14140 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14141 | /* "The stride in bytes must not exceed the of the size of 8K |
| 14142 | * pixels and 32K bytes." |
| 14143 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14144 | return min(8192 * cpp, 32768); |
Ville Syrjälä | 6401c37 | 2017-02-08 19:53:28 +0200 | [diff] [blame] | 14145 | } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14146 | return 32*1024; |
| 14147 | } else if (gen >= 4) { |
| 14148 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14149 | return 16*1024; |
| 14150 | else |
| 14151 | return 32*1024; |
| 14152 | } else if (gen >= 3) { |
| 14153 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14154 | return 8*1024; |
| 14155 | else |
| 14156 | return 16*1024; |
| 14157 | } else { |
| 14158 | /* XXX DSPC is limited to 4k tiled */ |
| 14159 | return 8*1024; |
| 14160 | } |
| 14161 | } |
| 14162 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14163 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14164 | struct drm_i915_gem_object *obj, |
| 14165 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14166 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14167 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14168 | struct drm_framebuffer *fb = &intel_fb->base; |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 14169 | struct drm_format_name_buf format_name; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14170 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14171 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14172 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14173 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14174 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14175 | i915_gem_object_lock(obj); |
| 14176 | obj->framebuffer_references++; |
| 14177 | tiling = i915_gem_object_get_tiling(obj); |
| 14178 | stride = i915_gem_object_get_stride(obj); |
| 14179 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14180 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14181 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14182 | /* |
| 14183 | * If there's a fence, enforce that |
| 14184 | * the fb modifier and tiling mode match. |
| 14185 | */ |
| 14186 | if (tiling != I915_TILING_NONE && |
| 14187 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14188 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14189 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14190 | } |
| 14191 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14192 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14193 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14194 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14195 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14196 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14197 | } |
| 14198 | } |
| 14199 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14200 | /* Passed in modifier sanity checking. */ |
| 14201 | switch (mode_cmd->modifier[0]) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14202 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 14203 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 14204 | switch (mode_cmd->pixel_format) { |
| 14205 | case DRM_FORMAT_XBGR8888: |
| 14206 | case DRM_FORMAT_ABGR8888: |
| 14207 | case DRM_FORMAT_XRGB8888: |
| 14208 | case DRM_FORMAT_ARGB8888: |
| 14209 | break; |
| 14210 | default: |
| 14211 | DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n"); |
| 14212 | goto err; |
| 14213 | } |
| 14214 | /* fall through */ |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14215 | case I915_FORMAT_MOD_Y_TILED: |
| 14216 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14217 | if (INTEL_GEN(dev_priv) < 9) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14218 | DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n", |
| 14219 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14220 | goto err; |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14221 | } |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14222 | case DRM_FORMAT_MOD_LINEAR: |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14223 | case I915_FORMAT_MOD_X_TILED: |
| 14224 | break; |
| 14225 | default: |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14226 | DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n", |
| 14227 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14228 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14229 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14230 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14231 | /* |
| 14232 | * gen2/3 display engine uses the fence if present, |
| 14233 | * so the tiling mode must match the fb modifier exactly. |
| 14234 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14235 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14236 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14237 | 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] | 14238 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14239 | } |
| 14240 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14241 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14242 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14243 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14244 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14245 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14246 | "tiled" : "linear", |
| 14247 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14248 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14249 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14250 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14251 | /* |
| 14252 | * If there's a fence, enforce that |
| 14253 | * the fb pitch and fence stride match. |
| 14254 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14255 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14256 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14257 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14258 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14259 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14260 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14261 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14262 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14263 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14264 | case DRM_FORMAT_RGB565: |
| 14265 | case DRM_FORMAT_XRGB8888: |
| 14266 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14267 | break; |
| 14268 | case DRM_FORMAT_XRGB1555: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14269 | if (INTEL_GEN(dev_priv) > 3) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14270 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14271 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14272 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14273 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14274 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14275 | case DRM_FORMAT_ABGR8888: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14276 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14277 | INTEL_GEN(dev_priv) < 9) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14278 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14279 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14280 | goto err; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14281 | } |
| 14282 | break; |
| 14283 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14284 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14285 | case DRM_FORMAT_XBGR2101010: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14286 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14287 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14288 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14289 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14290 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14291 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14292 | case DRM_FORMAT_ABGR2101010: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14293 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14294 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14295 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14296 | goto err; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14297 | } |
| 14298 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14299 | case DRM_FORMAT_YUYV: |
| 14300 | case DRM_FORMAT_UYVY: |
| 14301 | case DRM_FORMAT_YVYU: |
| 14302 | case DRM_FORMAT_VYUY: |
Ville Syrjälä | ab33081 | 2017-04-21 21:14:32 +0300 | [diff] [blame] | 14303 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14304 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14305 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14306 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14307 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14308 | break; |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14309 | case DRM_FORMAT_NV12: |
| 14310 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_Y_TILED_CCS || |
| 14311 | mode_cmd->modifier[0] == I915_FORMAT_MOD_Yf_TILED_CCS) { |
| 14312 | DRM_DEBUG_KMS("RC not to be enabled with NV12\n"); |
| 14313 | goto err; |
| 14314 | } |
| 14315 | if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) || |
| 14316 | IS_BROXTON(dev_priv)) { |
| 14317 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14318 | drm_get_format_name(mode_cmd->pixel_format, |
| 14319 | &format_name)); |
| 14320 | goto err; |
| 14321 | } |
| 14322 | break; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14323 | default: |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14324 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14325 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14326 | goto err; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14327 | } |
| 14328 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14329 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14330 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14331 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14332 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14333 | 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] | 14334 | |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14335 | if (fb->format->format == DRM_FORMAT_NV12 && |
| 14336 | (fb->width < SKL_MIN_YUV_420_SRC_W || |
| 14337 | fb->height < SKL_MIN_YUV_420_SRC_H || |
| 14338 | (fb->width % 4) != 0 || (fb->height % 4) != 0)) { |
| 14339 | DRM_DEBUG_KMS("src dimensions not correct for NV12\n"); |
| 14340 | return -EINVAL; |
| 14341 | } |
| 14342 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14343 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14344 | u32 stride_alignment; |
| 14345 | |
| 14346 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14347 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14348 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14349 | } |
| 14350 | |
| 14351 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14352 | |
| 14353 | /* |
| 14354 | * Display WA #0531: skl,bxt,kbl,glk |
| 14355 | * |
| 14356 | * Render decompression and plane width > 3840 |
| 14357 | * combined with horizontal panning requires the |
| 14358 | * plane stride to be a multiple of 4. We'll just |
| 14359 | * require the entire fb to accommodate that to avoid |
| 14360 | * potential runtime errors at plane configuration time. |
| 14361 | */ |
| 14362 | if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 && |
| 14363 | (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 14364 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) |
| 14365 | stride_alignment *= 4; |
| 14366 | |
| 14367 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14368 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14369 | i, fb->pitches[i], stride_alignment); |
| 14370 | goto err; |
| 14371 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14372 | } |
| 14373 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14374 | intel_fb->obj = obj; |
| 14375 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14376 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14377 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14378 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14379 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14380 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14381 | if (ret) { |
| 14382 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14383 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14384 | } |
| 14385 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14386 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14387 | |
| 14388 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14389 | i915_gem_object_lock(obj); |
| 14390 | obj->framebuffer_references--; |
| 14391 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14392 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14393 | } |
| 14394 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14395 | static struct drm_framebuffer * |
| 14396 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14397 | struct drm_file *filp, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14398 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14399 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14400 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14401 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14402 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14403 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14404 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14405 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14406 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14407 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14408 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14409 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14410 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14411 | |
| 14412 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14413 | } |
| 14414 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14415 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14416 | { |
| 14417 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14418 | |
| 14419 | drm_atomic_state_default_release(state); |
| 14420 | |
| 14421 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14422 | |
| 14423 | kfree(state); |
| 14424 | } |
| 14425 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14426 | static enum drm_mode_status |
| 14427 | intel_mode_valid(struct drm_device *dev, |
| 14428 | const struct drm_display_mode *mode) |
| 14429 | { |
| 14430 | if (mode->vscan > 1) |
| 14431 | return MODE_NO_VSCAN; |
| 14432 | |
| 14433 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 14434 | return MODE_NO_DBLESCAN; |
| 14435 | |
| 14436 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 14437 | return MODE_H_ILLEGAL; |
| 14438 | |
| 14439 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 14440 | DRM_MODE_FLAG_NCSYNC | |
| 14441 | DRM_MODE_FLAG_PCSYNC)) |
| 14442 | return MODE_HSYNC; |
| 14443 | |
| 14444 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 14445 | DRM_MODE_FLAG_PIXMUX | |
| 14446 | DRM_MODE_FLAG_CLKDIV2)) |
| 14447 | return MODE_BAD; |
| 14448 | |
| 14449 | return MODE_OK; |
| 14450 | } |
| 14451 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14452 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14453 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 14454 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14455 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14456 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14457 | .atomic_check = intel_atomic_check, |
| 14458 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14459 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14460 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14461 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14462 | }; |
| 14463 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14464 | /** |
| 14465 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14466 | * @dev_priv: device private |
| 14467 | */ |
| 14468 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14469 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 14470 | intel_init_cdclk_hooks(dev_priv); |
| 14471 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14472 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14473 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14474 | dev_priv->display.get_initial_plane_config = |
| 14475 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14476 | dev_priv->display.crtc_compute_clock = |
| 14477 | haswell_crtc_compute_clock; |
| 14478 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14479 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14480 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14481 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14482 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14483 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14484 | dev_priv->display.crtc_compute_clock = |
| 14485 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14486 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14487 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14488 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14489 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14490 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14491 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14492 | dev_priv->display.crtc_compute_clock = |
| 14493 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14494 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14495 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14496 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14497 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14498 | dev_priv->display.get_initial_plane_config = |
| 14499 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14500 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 14501 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14502 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14503 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 14504 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14505 | dev_priv->display.get_initial_plane_config = |
| 14506 | i9xx_get_initial_plane_config; |
| 14507 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14508 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14509 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 14510 | } else if (IS_G4X(dev_priv)) { |
| 14511 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14512 | dev_priv->display.get_initial_plane_config = |
| 14513 | i9xx_get_initial_plane_config; |
| 14514 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 14515 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14516 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 14517 | } else if (IS_PINEVIEW(dev_priv)) { |
| 14518 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14519 | dev_priv->display.get_initial_plane_config = |
| 14520 | i9xx_get_initial_plane_config; |
| 14521 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 14522 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14523 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14524 | } else if (!IS_GEN2(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14525 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14526 | dev_priv->display.get_initial_plane_config = |
| 14527 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14528 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14529 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14530 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14531 | } else { |
| 14532 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14533 | dev_priv->display.get_initial_plane_config = |
| 14534 | i9xx_get_initial_plane_config; |
| 14535 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 14536 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14537 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14538 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14539 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14540 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14541 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14542 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14543 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14544 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14545 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14546 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14547 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14548 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 14549 | } |
| 14550 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 14551 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14552 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 14553 | else |
| 14554 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14555 | } |
| 14556 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14557 | /* |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14558 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 14559 | */ |
| 14560 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 14561 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14562 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14563 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14564 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14565 | } |
| 14566 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14567 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14568 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 14569 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14570 | */ |
| 14571 | static void quirk_invert_brightness(struct drm_device *dev) |
| 14572 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14573 | struct drm_i915_private *dev_priv = to_i915(dev); |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14574 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14575 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14576 | } |
| 14577 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14578 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 14579 | static void quirk_backlight_present(struct drm_device *dev) |
| 14580 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14581 | struct drm_i915_private *dev_priv = to_i915(dev); |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14582 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 14583 | DRM_INFO("applying backlight present quirk\n"); |
| 14584 | } |
| 14585 | |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 14586 | /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms |
| 14587 | * which is 300 ms greater than eDP spec T12 min. |
| 14588 | */ |
| 14589 | static void quirk_increase_t12_delay(struct drm_device *dev) |
| 14590 | { |
| 14591 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14592 | |
| 14593 | dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY; |
| 14594 | DRM_INFO("Applying T12 delay quirk\n"); |
| 14595 | } |
| 14596 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14597 | struct intel_quirk { |
| 14598 | int device; |
| 14599 | int subsystem_vendor; |
| 14600 | int subsystem_device; |
| 14601 | void (*hook)(struct drm_device *dev); |
| 14602 | }; |
| 14603 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14604 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 14605 | struct intel_dmi_quirk { |
| 14606 | void (*hook)(struct drm_device *dev); |
| 14607 | const struct dmi_system_id (*dmi_id_list)[]; |
| 14608 | }; |
| 14609 | |
| 14610 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 14611 | { |
| 14612 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 14613 | return 1; |
| 14614 | } |
| 14615 | |
| 14616 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 14617 | { |
| 14618 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 14619 | { |
| 14620 | .callback = intel_dmi_reverse_brightness, |
| 14621 | .ident = "NCR Corporation", |
| 14622 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 14623 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 14624 | }, |
| 14625 | }, |
| 14626 | { } /* terminating entry */ |
| 14627 | }, |
| 14628 | .hook = quirk_invert_brightness, |
| 14629 | }, |
| 14630 | }; |
| 14631 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 14632 | static struct intel_quirk intel_quirks[] = { |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14633 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 14634 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 14635 | |
| 14636 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 14637 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14638 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 14639 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 14640 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 14641 | |
| 14642 | /* Acer/eMachines G725 */ |
| 14643 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 14644 | |
| 14645 | /* Acer/eMachines e725 */ |
| 14646 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 14647 | |
| 14648 | /* Acer/Packard Bell NCL20 */ |
| 14649 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 14650 | |
| 14651 | /* Acer Aspire 4736Z */ |
| 14652 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 14653 | |
| 14654 | /* Acer Aspire 5336 */ |
| 14655 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 14656 | |
| 14657 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 14658 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14659 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 14660 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 14661 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 14662 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 14663 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 14664 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 14665 | |
Jani Nikula | 1b9448b | 2015-11-05 11:49:59 +0200 | [diff] [blame] | 14666 | /* Apple Macbook 4,1 */ |
| 14667 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, |
| 14668 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14669 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 14670 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 14671 | |
| 14672 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 14673 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 14674 | |
| 14675 | /* Dell Chromebook 11 */ |
| 14676 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jani Nikula | 9be64ee | 2015-10-30 14:50:24 +0200 | [diff] [blame] | 14677 | |
| 14678 | /* Dell Chromebook 11 (2015 version) */ |
| 14679 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 14680 | |
| 14681 | /* Toshiba Satellite P50-C-18C */ |
| 14682 | { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14683 | }; |
| 14684 | |
| 14685 | static void intel_init_quirks(struct drm_device *dev) |
| 14686 | { |
| 14687 | struct pci_dev *d = dev->pdev; |
| 14688 | int i; |
| 14689 | |
| 14690 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 14691 | struct intel_quirk *q = &intel_quirks[i]; |
| 14692 | |
| 14693 | if (d->device == q->device && |
| 14694 | (d->subsystem_vendor == q->subsystem_vendor || |
| 14695 | q->subsystem_vendor == PCI_ANY_ID) && |
| 14696 | (d->subsystem_device == q->subsystem_device || |
| 14697 | q->subsystem_device == PCI_ANY_ID)) |
| 14698 | q->hook(dev); |
| 14699 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14700 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 14701 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 14702 | intel_dmi_quirks[i].hook(dev); |
| 14703 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14704 | } |
| 14705 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14706 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 14707 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14708 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14709 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14710 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14711 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14712 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14713 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14714 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14715 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14716 | sr1 = inb(VGA_SR_DATA); |
| 14717 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14718 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14719 | udelay(300); |
| 14720 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14721 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14722 | POSTING_READ(vga_reg); |
| 14723 | } |
| 14724 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14725 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14726 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14727 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 14728 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 14729 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 14730 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 14731 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14732 | } |
| 14733 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14734 | /* |
| 14735 | * Calculate what we think the watermarks should be for the state we've read |
| 14736 | * out of the hardware and then immediately program those watermarks so that |
| 14737 | * we ensure the hardware settings match our internal state. |
| 14738 | * |
| 14739 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 14740 | * current state (which was constructed during hardware readout) and running it |
| 14741 | * through the atomic check code to calculate new watermark values in the |
| 14742 | * state object. |
| 14743 | */ |
| 14744 | static void sanitize_watermarks(struct drm_device *dev) |
| 14745 | { |
| 14746 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14747 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14748 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14749 | struct drm_crtc *crtc; |
| 14750 | struct drm_crtc_state *cstate; |
| 14751 | struct drm_modeset_acquire_ctx ctx; |
| 14752 | int ret; |
| 14753 | int i; |
| 14754 | |
| 14755 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14756 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14757 | return; |
| 14758 | |
| 14759 | /* |
| 14760 | * We need to hold connection_mutex before calling duplicate_state so |
| 14761 | * that the connector loop is protected. |
| 14762 | */ |
| 14763 | drm_modeset_acquire_init(&ctx, 0); |
| 14764 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14765 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14766 | if (ret == -EDEADLK) { |
| 14767 | drm_modeset_backoff(&ctx); |
| 14768 | goto retry; |
| 14769 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14770 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14771 | } |
| 14772 | |
| 14773 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 14774 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14775 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14776 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14777 | intel_state = to_intel_atomic_state(state); |
| 14778 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14779 | /* |
| 14780 | * Hardware readout is the only time we don't want to calculate |
| 14781 | * intermediate watermarks (since we don't trust the current |
| 14782 | * watermarks). |
| 14783 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 14784 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 14785 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14786 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14787 | ret = intel_atomic_check(dev, state); |
| 14788 | if (ret) { |
| 14789 | /* |
| 14790 | * If we fail here, it means that the hardware appears to be |
| 14791 | * programmed in a way that shouldn't be possible, given our |
| 14792 | * understanding of watermark requirements. This might mean a |
| 14793 | * mistake in the hardware readout code or a mistake in the |
| 14794 | * watermark calculations for a given platform. Raise a WARN |
| 14795 | * so that this is noticeable. |
| 14796 | * |
| 14797 | * If this actually happens, we'll have to just leave the |
| 14798 | * BIOS-programmed watermarks untouched and hope for the best. |
| 14799 | */ |
| 14800 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14801 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14802 | } |
| 14803 | |
| 14804 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 14805 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14806 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 14807 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14808 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14809 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 14810 | |
| 14811 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14812 | } |
| 14813 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14814 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14815 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14816 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14817 | drm_modeset_drop_locks(&ctx); |
| 14818 | drm_modeset_acquire_fini(&ctx); |
| 14819 | } |
| 14820 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 14821 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 14822 | { |
| 14823 | if (IS_GEN5(dev_priv)) { |
| 14824 | u32 fdi_pll_clk = |
| 14825 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 14826 | |
| 14827 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
| 14828 | } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) { |
| 14829 | dev_priv->fdi_pll_freq = 270000; |
| 14830 | } else { |
| 14831 | return; |
| 14832 | } |
| 14833 | |
| 14834 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 14835 | } |
| 14836 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14837 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14838 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 14839 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14840 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14841 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14842 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14843 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 14844 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 14845 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14846 | drm_mode_config_init(dev); |
| 14847 | |
| 14848 | dev->mode_config.min_width = 0; |
| 14849 | dev->mode_config.min_height = 0; |
| 14850 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 14851 | dev->mode_config.preferred_depth = 24; |
| 14852 | dev->mode_config.prefer_shadow = 1; |
| 14853 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 14854 | dev->mode_config.allow_fb_modifiers = true; |
| 14855 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 14856 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14857 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 14858 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 14859 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 14860 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 14861 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14862 | intel_init_quirks(dev); |
| 14863 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 14864 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 14865 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 14866 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14867 | return 0; |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 14868 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 14869 | /* |
| 14870 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 14871 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 14872 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 14873 | * indicates as much. |
| 14874 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14875 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 14876 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 14877 | DREF_SSC1_ENABLE); |
| 14878 | |
| 14879 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 14880 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 14881 | bios_lvds_use_ssc ? "en" : "dis", |
| 14882 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 14883 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 14884 | } |
| 14885 | } |
| 14886 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14887 | if (IS_GEN2(dev_priv)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14888 | dev->mode_config.max_width = 2048; |
| 14889 | dev->mode_config.max_height = 2048; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14890 | } else if (IS_GEN3(dev_priv)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 14891 | dev->mode_config.max_width = 4096; |
| 14892 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14893 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14894 | dev->mode_config.max_width = 8192; |
| 14895 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14896 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14897 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 14898 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 14899 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14900 | dev->mode_config.cursor_height = 1023; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14901 | } else if (IS_GEN2(dev_priv)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14902 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 14903 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 14904 | } else { |
| 14905 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 14906 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 14907 | } |
| 14908 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 14909 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14910 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14911 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 14912 | INTEL_INFO(dev_priv)->num_pipes, |
| 14913 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14914 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14915 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14916 | int ret; |
| 14917 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14918 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14919 | if (ret) { |
| 14920 | drm_mode_config_cleanup(dev); |
| 14921 | return ret; |
| 14922 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14923 | } |
| 14924 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 14925 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 14926 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 14927 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 14928 | intel_update_czclk(dev_priv); |
| 14929 | intel_modeset_init_hw(dev); |
| 14930 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 14931 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 14932 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 14933 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14934 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 14935 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14936 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 14937 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14938 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 14939 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14940 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14941 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14942 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 14943 | struct intel_initial_plane_config plane_config = {}; |
| 14944 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14945 | if (!crtc->active) |
| 14946 | continue; |
| 14947 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14948 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14949 | * Note that reserving the BIOS fb up front prevents us |
| 14950 | * from stuffing other stolen allocations like the ring |
| 14951 | * on top. This prevents some ugliness at boot time, and |
| 14952 | * can even allow for smooth boot transitions if the BIOS |
| 14953 | * fb is large enough for the active pipe configuration. |
| 14954 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 14955 | dev_priv->display.get_initial_plane_config(crtc, |
| 14956 | &plane_config); |
| 14957 | |
| 14958 | /* |
| 14959 | * If the fb is shared between multiple heads, we'll |
| 14960 | * just get the first one. |
| 14961 | */ |
| 14962 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14963 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14964 | |
| 14965 | /* |
| 14966 | * Make sure hardware watermarks really match the state we read out. |
| 14967 | * Note that we need to do this after reconstructing the BIOS fb's |
| 14968 | * since the watermark calculation done here will use pstate->fb. |
| 14969 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 14970 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 14971 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14972 | |
| 14973 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14974 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 14975 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 14976 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 14977 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 14978 | 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] | 14979 | /* 640x480@60Hz, ~25175 kHz */ |
| 14980 | struct dpll clock = { |
| 14981 | .m1 = 18, |
| 14982 | .m2 = 7, |
| 14983 | .p1 = 13, |
| 14984 | .p2 = 4, |
| 14985 | .n = 2, |
| 14986 | }; |
| 14987 | u32 dpll, fp; |
| 14988 | int i; |
| 14989 | |
| 14990 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 14991 | |
| 14992 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 14993 | pipe_name(pipe), clock.vco, clock.dot); |
| 14994 | |
| 14995 | fp = i9xx_dpll_compute_fp(&clock); |
| 14996 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 14997 | DPLL_VGA_MODE_DIS | |
| 14998 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 14999 | PLL_P2_DIVIDE_BY_4 | |
| 15000 | PLL_REF_INPUT_DREFCLK | |
| 15001 | DPLL_VCO_ENABLE; |
| 15002 | |
| 15003 | I915_WRITE(FP0(pipe), fp); |
| 15004 | I915_WRITE(FP1(pipe), fp); |
| 15005 | |
| 15006 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15007 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15008 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15009 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15010 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15011 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15012 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15013 | |
| 15014 | /* |
| 15015 | * Apparently we need to have VGA mode enabled prior to changing |
| 15016 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15017 | * dividers, even though the register value does change. |
| 15018 | */ |
| 15019 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15020 | I915_WRITE(DPLL(pipe), dpll); |
| 15021 | |
| 15022 | /* Wait for the clocks to stabilize. */ |
| 15023 | POSTING_READ(DPLL(pipe)); |
| 15024 | udelay(150); |
| 15025 | |
| 15026 | /* The pixel multiplier can only be updated once the |
| 15027 | * DPLL is enabled and the clocks are stable. |
| 15028 | * |
| 15029 | * So write it again. |
| 15030 | */ |
| 15031 | I915_WRITE(DPLL(pipe), dpll); |
| 15032 | |
| 15033 | /* We do this three times for luck */ |
| 15034 | for (i = 0; i < 3 ; i++) { |
| 15035 | I915_WRITE(DPLL(pipe), dpll); |
| 15036 | POSTING_READ(DPLL(pipe)); |
| 15037 | udelay(150); /* wait for warmup */ |
| 15038 | } |
| 15039 | |
| 15040 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15041 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15042 | |
| 15043 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15044 | } |
| 15045 | |
| 15046 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15047 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15048 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15049 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15050 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15051 | pipe_name(pipe)); |
| 15052 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15053 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15054 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15055 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
| 15056 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE); |
| 15057 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15058 | |
| 15059 | I915_WRITE(PIPECONF(pipe), 0); |
| 15060 | POSTING_READ(PIPECONF(pipe)); |
| 15061 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15062 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15063 | |
| 15064 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15065 | POSTING_READ(DPLL(pipe)); |
| 15066 | } |
| 15067 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15068 | static bool intel_plane_mapping_ok(struct intel_crtc *crtc, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 15069 | struct intel_plane *plane) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15070 | { |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15071 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 15072 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
| 15073 | u32 val = I915_READ(DSPCNTR(i9xx_plane)); |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15074 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15075 | return (val & DISPLAY_PLANE_ENABLE) == 0 || |
| 15076 | (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe); |
| 15077 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15078 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15079 | static void |
| 15080 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15081 | { |
| 15082 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15083 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15084 | if (INTEL_GEN(dev_priv) >= 4) |
| 15085 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15086 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15087 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15088 | struct intel_plane *plane = |
| 15089 | to_intel_plane(crtc->base.primary); |
| 15090 | |
| 15091 | if (intel_plane_mapping_ok(crtc, plane)) |
| 15092 | continue; |
| 15093 | |
| 15094 | DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n", |
| 15095 | plane->base.name); |
| 15096 | intel_plane_disable_noatomic(crtc, plane); |
| 15097 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15098 | } |
| 15099 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15100 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15101 | { |
| 15102 | struct drm_device *dev = crtc->base.dev; |
| 15103 | struct intel_encoder *encoder; |
| 15104 | |
| 15105 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15106 | return true; |
| 15107 | |
| 15108 | return false; |
| 15109 | } |
| 15110 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15111 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15112 | { |
| 15113 | struct drm_device *dev = encoder->base.dev; |
| 15114 | struct intel_connector *connector; |
| 15115 | |
| 15116 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15117 | return connector; |
| 15118 | |
| 15119 | return NULL; |
| 15120 | } |
| 15121 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15122 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15123 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15124 | { |
| 15125 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15126 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15127 | } |
| 15128 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15129 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15130 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15131 | { |
| 15132 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15133 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15134 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15135 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15136 | /* 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] | 15137 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15138 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15139 | |
| 15140 | I915_WRITE(reg, |
| 15141 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15142 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15143 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15144 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15145 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 15146 | if (crtc->active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15147 | struct intel_plane *plane; |
| 15148 | |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15149 | drm_crtc_vblank_on(&crtc->base); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15150 | |
| 15151 | /* Disable everything but the primary plane */ |
| 15152 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15153 | const struct intel_plane_state *plane_state = |
| 15154 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15155 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15156 | if (plane_state->base.visible && |
| 15157 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15158 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15159 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15160 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15161 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15162 | /* Adjust the state of the output pipe according to whether we |
| 15163 | * have active connectors/encoders. */ |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 15164 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15165 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15166 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 15167 | if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15168 | /* |
| 15169 | * We start out with underrun reporting disabled to avoid races. |
| 15170 | * For correct bookkeeping mark this on active crtcs. |
| 15171 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15172 | * Also on gmch platforms we dont have any hardware bits to |
| 15173 | * disable the underrun reporting. Which means we need to start |
| 15174 | * out with underrun reporting disabled also on inactive pipes, |
| 15175 | * since otherwise we'll complain about the garbage we read when |
| 15176 | * e.g. coming up after runtime pm. |
| 15177 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15178 | * No protection against concurrent access is required - at |
| 15179 | * worst a fifo underrun happens which also sets this to false. |
| 15180 | */ |
| 15181 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15182 | /* |
| 15183 | * We track the PCH trancoder underrun reporting state |
| 15184 | * within the crtc. With crtc for pipe A housing the underrun |
| 15185 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15186 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15187 | * and marking underrun reporting as disabled for the non-existing |
| 15188 | * PCH transcoders B and C would prevent enabling the south |
| 15189 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15190 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15191 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15192 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15193 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15194 | } |
| 15195 | |
| 15196 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15197 | { |
| 15198 | struct intel_connector *connector; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15199 | |
| 15200 | /* We need to check both for a crtc link (meaning that the |
| 15201 | * encoder is active and trying to read from a pipe) and the |
| 15202 | * pipe itself being active. */ |
| 15203 | bool has_active_crtc = encoder->base.crtc && |
| 15204 | to_intel_crtc(encoder->base.crtc)->active; |
| 15205 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15206 | connector = intel_encoder_find_connector(encoder); |
| 15207 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15208 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15209 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15210 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15211 | |
| 15212 | /* Connector is active, but has no active pipe. This is |
| 15213 | * fallout from our resume register restoring. Disable |
| 15214 | * the encoder manually again. */ |
| 15215 | if (encoder->base.crtc) { |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15216 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
| 15217 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15218 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15219 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15220 | encoder->base.name); |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15221 | 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] | 15222 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15223 | 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] | 15224 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15225 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15226 | |
| 15227 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15228 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15229 | * in our code, like the register restore mess on resume. Clamp |
| 15230 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15231 | |
| 15232 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15233 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15234 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15235 | } |
| 15236 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15237 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15238 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15239 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15240 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15241 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15242 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15243 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15244 | } |
| 15245 | } |
| 15246 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15247 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15248 | { |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15249 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15250 | * at a very early point in our resume sequence, where the power well |
| 15251 | * structures are not yet restored. Since this function is at a very |
| 15252 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15253 | * level, just check if the power well is enabled instead of trying to |
| 15254 | * follow the "don't touch the power well if we don't need it" policy |
| 15255 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15256 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15257 | return; |
| 15258 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15259 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15260 | |
| 15261 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15262 | } |
| 15263 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15264 | /* FIXME read out full plane state for all planes */ |
| 15265 | static void readout_plane_state(struct intel_crtc *crtc) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15266 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15267 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 15268 | struct intel_crtc_state *crtc_state = |
| 15269 | to_intel_crtc_state(crtc->base.state); |
| 15270 | struct intel_plane *plane; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15271 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15272 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 15273 | struct intel_plane_state *plane_state = |
| 15274 | to_intel_plane_state(plane->base.state); |
| 15275 | bool visible = plane->get_hw_state(plane); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15276 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15277 | intel_set_plane_visible(crtc_state, plane_state, visible); |
| 15278 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15279 | } |
| 15280 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15281 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15282 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15283 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15284 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15285 | struct intel_crtc *crtc; |
| 15286 | struct intel_encoder *encoder; |
| 15287 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15288 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15289 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15290 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15291 | dev_priv->active_crtcs = 0; |
| 15292 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15293 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15294 | struct intel_crtc_state *crtc_state = |
| 15295 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15296 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15297 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15298 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15299 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15300 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15301 | crtc_state->base.active = crtc_state->base.enable = |
| 15302 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15303 | |
| 15304 | crtc->base.enabled = crtc_state->base.enable; |
| 15305 | crtc->active = crtc_state->base.active; |
| 15306 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15307 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15308 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15309 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15310 | readout_plane_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15311 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15312 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15313 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15314 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15315 | } |
| 15316 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15317 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15318 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15319 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15320 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15321 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15322 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15323 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15324 | struct intel_crtc_state *crtc_state = |
| 15325 | to_intel_crtc_state(crtc->base.state); |
| 15326 | |
| 15327 | if (crtc_state->base.active && |
| 15328 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15329 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15330 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15331 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15332 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15333 | 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] | 15334 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15335 | } |
| 15336 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15337 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15338 | pipe = 0; |
| 15339 | |
| 15340 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15341 | struct intel_crtc_state *crtc_state; |
| 15342 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15343 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15344 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15345 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15346 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15347 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15348 | } else { |
| 15349 | encoder->base.crtc = NULL; |
| 15350 | } |
| 15351 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15352 | 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] | 15353 | encoder->base.base.id, encoder->base.name, |
| 15354 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15355 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15356 | } |
| 15357 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15358 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15359 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15360 | if (connector->get_hw_state(connector)) { |
| 15361 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15362 | |
| 15363 | encoder = connector->encoder; |
| 15364 | connector->base.encoder = &encoder->base; |
| 15365 | |
| 15366 | if (encoder->base.crtc && |
| 15367 | encoder->base.crtc->state->active) { |
| 15368 | /* |
| 15369 | * This has to be done during hardware readout |
| 15370 | * because anything calling .crtc_disable may |
| 15371 | * rely on the connector_mask being accurate. |
| 15372 | */ |
| 15373 | encoder->base.crtc->state->connector_mask |= |
| 15374 | 1 << drm_connector_index(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15375 | encoder->base.crtc->state->encoder_mask |= |
| 15376 | 1 << drm_encoder_index(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15377 | } |
| 15378 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15379 | } else { |
| 15380 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15381 | connector->base.encoder = NULL; |
| 15382 | } |
| 15383 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15384 | connector->base.base.id, connector->base.name, |
| 15385 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15386 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15387 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15388 | |
| 15389 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15390 | struct intel_crtc_state *crtc_state = |
| 15391 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15392 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15393 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15394 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15395 | if (crtc_state->base.active) { |
| 15396 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15397 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15398 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15399 | 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] | 15400 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15401 | |
| 15402 | /* |
| 15403 | * The initial mode needs to be set in order to keep |
| 15404 | * the atomic core happy. It wants a valid mode if the |
| 15405 | * crtc's enabled, so we do the above call. |
| 15406 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 15407 | * But we don't set all the derived state fully, hence |
| 15408 | * set a flag to indicate that a full recalculation is |
| 15409 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15410 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15411 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15412 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 15413 | intel_crtc_compute_pixel_rate(crtc_state); |
| 15414 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15415 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15416 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15417 | if (WARN_ON(min_cdclk < 0)) |
| 15418 | min_cdclk = 0; |
| 15419 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15420 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 15421 | drm_calc_timestamping_constants(&crtc->base, |
| 15422 | &crtc_state->base.adjusted_mode); |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15423 | update_scanline_offset(crtc); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15424 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15425 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15426 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 15427 | dev_priv->min_voltage_level[crtc->pipe] = |
| 15428 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15429 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15430 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15431 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15432 | } |
| 15433 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15434 | static void |
| 15435 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 15436 | { |
| 15437 | struct intel_encoder *encoder; |
| 15438 | |
| 15439 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 15440 | u64 get_domains; |
| 15441 | enum intel_display_power_domain domain; |
| 15442 | |
| 15443 | if (!encoder->get_power_domains) |
| 15444 | continue; |
| 15445 | |
| 15446 | get_domains = encoder->get_power_domains(encoder); |
| 15447 | for_each_power_domain(domain, get_domains) |
| 15448 | intel_display_power_get(dev_priv, domain); |
| 15449 | } |
| 15450 | } |
| 15451 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15452 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 15453 | { |
| 15454 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 15455 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 15456 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 15457 | DARBF_GATING_DIS); |
| 15458 | |
| 15459 | if (IS_HASWELL(dev_priv)) { |
| 15460 | /* |
| 15461 | * WaRsPkgCStateDisplayPMReq:hsw |
| 15462 | * System hang if this isn't done before disabling all planes! |
| 15463 | */ |
| 15464 | I915_WRITE(CHICKEN_PAR1_1, |
| 15465 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 15466 | } |
| 15467 | } |
| 15468 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15469 | /* Scan out the current hw modeset state, |
| 15470 | * and sanitizes it to the current state |
| 15471 | */ |
| 15472 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15473 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 15474 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15475 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15476 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15477 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15478 | struct intel_crtc *crtc; |
| 15479 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15480 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15481 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15482 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15483 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15484 | |
| 15485 | /* 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] | 15486 | get_encoder_power_domains(dev_priv); |
| 15487 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15488 | intel_sanitize_plane_mapping(dev_priv); |
| 15489 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15490 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15491 | intel_sanitize_encoder(encoder); |
| 15492 | } |
| 15493 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15494 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15495 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15496 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15497 | intel_sanitize_crtc(crtc, ctx); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15498 | intel_dump_pipe_config(crtc, crtc->config, |
| 15499 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15500 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15501 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15502 | intel_modeset_update_connector_atomic_state(dev); |
| 15503 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15504 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15505 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15506 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15507 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15508 | continue; |
| 15509 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 15510 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 15511 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15512 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15513 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15514 | pll->on = false; |
| 15515 | } |
| 15516 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15517 | if (IS_G4X(dev_priv)) { |
| 15518 | g4x_wm_get_hw_state(dev); |
| 15519 | g4x_wm_sanitize(dev_priv); |
| 15520 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 15521 | vlv_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15522 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 15523 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 15524 | skl_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15525 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 15526 | ilk_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15527 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15528 | |
| 15529 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 15530 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15531 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 15532 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15533 | if (WARN_ON(put_domains)) |
| 15534 | modeset_put_power_domains(dev_priv, put_domains); |
| 15535 | } |
| 15536 | intel_display_set_init_power(dev_priv, false); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15537 | |
Imre Deak | 8d8c386 | 2017-02-17 17:39:46 +0200 | [diff] [blame] | 15538 | intel_power_domains_verify_state(dev_priv); |
| 15539 | |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15540 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15541 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15542 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15543 | void intel_display_resume(struct drm_device *dev) |
| 15544 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15545 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15546 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15547 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15548 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15549 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15550 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15551 | if (state) |
| 15552 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15553 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15554 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15555 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15556 | while (1) { |
| 15557 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 15558 | if (ret != -EDEADLK) |
| 15559 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15560 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15561 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15562 | } |
| 15563 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15564 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 15565 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15566 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 15567 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15568 | drm_modeset_drop_locks(&ctx); |
| 15569 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15570 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15571 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15572 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 15573 | if (state) |
| 15574 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15575 | } |
| 15576 | |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 15577 | int intel_connector_register(struct drm_connector *connector) |
| 15578 | { |
| 15579 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 15580 | int ret; |
| 15581 | |
| 15582 | ret = intel_backlight_device_register(intel_connector); |
| 15583 | if (ret) |
| 15584 | goto err; |
| 15585 | |
| 15586 | return 0; |
| 15587 | |
| 15588 | err: |
| 15589 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15590 | } |
| 15591 | |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 15592 | void intel_connector_unregister(struct drm_connector *connector) |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15593 | { |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 15594 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15595 | |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 15596 | intel_backlight_device_unregister(intel_connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15597 | intel_panel_destroy_backlight(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15598 | } |
| 15599 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15600 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 15601 | { |
| 15602 | struct intel_connector *connector; |
| 15603 | struct drm_connector_list_iter conn_iter; |
| 15604 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 15605 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15606 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15607 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 15608 | if (connector->modeset_retry_work.func) |
| 15609 | cancel_work_sync(&connector->modeset_retry_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 15610 | if (connector->hdcp_shim) { |
| 15611 | cancel_delayed_work_sync(&connector->hdcp_check_work); |
| 15612 | cancel_work_sync(&connector->hdcp_prop_work); |
| 15613 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15614 | } |
| 15615 | drm_connector_list_iter_end(&conn_iter); |
| 15616 | } |
| 15617 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15618 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15619 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15620 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15621 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15622 | flush_work(&dev_priv->atomic_helper.free_work); |
| 15623 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 15624 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 15625 | intel_disable_gt_powersave(dev_priv); |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15626 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15627 | /* |
| 15628 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15629 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15630 | * experience fancy races otherwise. |
| 15631 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15632 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15633 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15634 | /* |
| 15635 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15636 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15637 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15638 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15639 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 15640 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 15641 | intel_fbdev_fini(dev_priv); |
| 15642 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15643 | intel_unregister_dsm_handler(); |
| 15644 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 15645 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 15646 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15647 | /* flush any delayed tasks or pending work */ |
| 15648 | flush_scheduled_work(); |
| 15649 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15650 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15651 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 15652 | intel_cleanup_overlay(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15653 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 15654 | intel_cleanup_gt_powersave(dev_priv); |
Daniel Vetter | f594914 | 2016-01-13 11:55:28 +0100 | [diff] [blame] | 15655 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 15656 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15657 | |
| 15658 | destroy_workqueue(dev_priv->modeset_wq); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15659 | } |
| 15660 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15661 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 15662 | struct intel_encoder *encoder) |
| 15663 | { |
| 15664 | connector->encoder = encoder; |
| 15665 | drm_mode_connector_attach_encoder(&connector->base, |
| 15666 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15667 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15668 | |
| 15669 | /* |
| 15670 | * set vga decode state - true == enable VGA decode |
| 15671 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15672 | 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] | 15673 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15674 | 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] | 15675 | u16 gmch_ctrl; |
| 15676 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15677 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15678 | DRM_ERROR("failed to read control word\n"); |
| 15679 | return -EIO; |
| 15680 | } |
| 15681 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15682 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 15683 | return 0; |
| 15684 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15685 | if (state) |
| 15686 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 15687 | else |
| 15688 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15689 | |
| 15690 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 15691 | DRM_ERROR("failed to write control word\n"); |
| 15692 | return -EIO; |
| 15693 | } |
| 15694 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15695 | return 0; |
| 15696 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15697 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 15698 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 15699 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15700 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15701 | |
| 15702 | u32 power_well_driver; |
| 15703 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15704 | int num_transcoders; |
| 15705 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15706 | struct intel_cursor_error_state { |
| 15707 | u32 control; |
| 15708 | u32 position; |
| 15709 | u32 base; |
| 15710 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15711 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15712 | |
| 15713 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15714 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15715 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15716 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15717 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15718 | |
| 15719 | struct intel_plane_error_state { |
| 15720 | u32 control; |
| 15721 | u32 stride; |
| 15722 | u32 size; |
| 15723 | u32 pos; |
| 15724 | u32 addr; |
| 15725 | u32 surface; |
| 15726 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15727 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15728 | |
| 15729 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15730 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15731 | enum transcoder cpu_transcoder; |
| 15732 | |
| 15733 | u32 conf; |
| 15734 | |
| 15735 | u32 htotal; |
| 15736 | u32 hblank; |
| 15737 | u32 hsync; |
| 15738 | u32 vtotal; |
| 15739 | u32 vblank; |
| 15740 | u32 vsync; |
| 15741 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15742 | }; |
| 15743 | |
| 15744 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15745 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15746 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15747 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15748 | int transcoders[] = { |
| 15749 | TRANSCODER_A, |
| 15750 | TRANSCODER_B, |
| 15751 | TRANSCODER_C, |
| 15752 | TRANSCODER_EDP, |
| 15753 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15754 | int i; |
| 15755 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15756 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15757 | return NULL; |
| 15758 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15759 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15760 | if (error == NULL) |
| 15761 | return NULL; |
| 15762 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15763 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 15764 | error->power_well_driver = |
| 15765 | I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15766 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15767 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15768 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15769 | __intel_display_power_is_enabled(dev_priv, |
| 15770 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15771 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15772 | continue; |
| 15773 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 15774 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 15775 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 15776 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15777 | |
| 15778 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 15779 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15780 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 15781 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15782 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 15783 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15784 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 15785 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15786 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15787 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 15788 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 15789 | } |
| 15790 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15791 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15792 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15793 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15794 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15795 | } |
| 15796 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15797 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15798 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 15799 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15800 | error->num_transcoders++; /* Account for eDP. */ |
| 15801 | |
| 15802 | for (i = 0; i < error->num_transcoders; i++) { |
| 15803 | enum transcoder cpu_transcoder = transcoders[i]; |
| 15804 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15805 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15806 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 15807 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15808 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15809 | continue; |
| 15810 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15811 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 15812 | |
| 15813 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 15814 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 15815 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 15816 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 15817 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 15818 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 15819 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15820 | } |
| 15821 | |
| 15822 | return error; |
| 15823 | } |
| 15824 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15825 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 15826 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15827 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15828 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15829 | struct intel_display_error_state *error) |
| 15830 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 15831 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15832 | int i; |
| 15833 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15834 | if (!error) |
| 15835 | return; |
| 15836 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15837 | 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] | 15838 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15839 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15840 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15841 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15842 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15843 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 15844 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15845 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15846 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15847 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15848 | err_printf(m, "Plane [%d]:\n", i); |
| 15849 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 15850 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 15851 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15852 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 15853 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15854 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 15855 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15856 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 15857 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15858 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 15859 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15860 | } |
| 15861 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15862 | err_printf(m, "Cursor [%d]:\n", i); |
| 15863 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 15864 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 15865 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15866 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15867 | |
| 15868 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 15869 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15870 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15871 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 15872 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15873 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 15874 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 15875 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 15876 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 15877 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 15878 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 15879 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 15880 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15881 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 15882 | |
| 15883 | #endif |