Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 32 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 33 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 35 | #include "intel_drv.h" |
Chris Wilson | 5d723d7 | 2016-08-04 16:32:35 +0100 | [diff] [blame] | 36 | #include "intel_frontbuffer.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 38 | #include "i915_drv.h" |
Chris Wilson | 57822dc | 2017-02-22 11:40:48 +0000 | [diff] [blame] | 39 | #include "i915_gem_clflush.h" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 40 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 41 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 42 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 43 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 44 | #include <drm/drm_dp_helper.h> |
| 45 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 46 | #include <drm/drm_plane_helper.h> |
| 47 | #include <drm/drm_rect.h> |
Daniel Vetter | 72fdb40 | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 48 | #include <drm/drm_atomic_uapi.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 49 | #include <linux/dma_remapping.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 50 | #include <linux/reservation.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 51 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 52 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 53 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 54 | DRM_FORMAT_C8, |
| 55 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 56 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 57 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 61 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 62 | DRM_FORMAT_C8, |
| 63 | DRM_FORMAT_RGB565, |
| 64 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 65 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 66 | DRM_FORMAT_XRGB2101010, |
| 67 | DRM_FORMAT_XBGR2101010, |
| 68 | }; |
| 69 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 70 | static const uint64_t i9xx_format_modifiers[] = { |
| 71 | I915_FORMAT_MOD_X_TILED, |
| 72 | DRM_FORMAT_MOD_LINEAR, |
| 73 | DRM_FORMAT_MOD_INVALID |
| 74 | }; |
| 75 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 76 | /* Cursor formats */ |
| 77 | static const uint32_t intel_cursor_formats[] = { |
| 78 | DRM_FORMAT_ARGB8888, |
| 79 | }; |
| 80 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 81 | static const uint64_t cursor_format_modifiers[] = { |
| 82 | DRM_FORMAT_MOD_LINEAR, |
| 83 | DRM_FORMAT_MOD_INVALID |
| 84 | }; |
| 85 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 86 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 87 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 88 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 89 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 90 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 91 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
| 92 | struct drm_i915_gem_object *obj, |
| 93 | struct drm_mode_fb_cmd2 *mode_cmd); |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 94 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state); |
| 95 | static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 96 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 97 | const struct intel_link_m_n *m_n, |
| 98 | const struct intel_link_m_n *m2_n2); |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 99 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 100 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 101 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 102 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 103 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 104 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 105 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 106 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 107 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 108 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 109 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 110 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 111 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state); |
| 112 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state); |
| 113 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 114 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 115 | struct drm_modeset_acquire_ctx *ctx); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 116 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 117 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 118 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 119 | struct { |
| 120 | int min, max; |
| 121 | } dot, vco, n, m, m1, m2, p, p1; |
| 122 | |
| 123 | struct { |
| 124 | int dot_limit; |
| 125 | int p2_slow, p2_fast; |
| 126 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 127 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 128 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 129 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 130 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 131 | { |
| 132 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 133 | |
| 134 | /* Obtain SKU information */ |
| 135 | mutex_lock(&dev_priv->sb_lock); |
| 136 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 137 | CCK_FUSE_HPLL_FREQ_MASK; |
| 138 | mutex_unlock(&dev_priv->sb_lock); |
| 139 | |
| 140 | return vco_freq[hpll_freq] * 1000; |
| 141 | } |
| 142 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 143 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 144 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 145 | { |
| 146 | u32 val; |
| 147 | int divider; |
| 148 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 149 | mutex_lock(&dev_priv->sb_lock); |
| 150 | val = vlv_cck_read(dev_priv, reg); |
| 151 | mutex_unlock(&dev_priv->sb_lock); |
| 152 | |
| 153 | divider = val & CCK_FREQUENCY_VALUES; |
| 154 | |
| 155 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 156 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 157 | "%s change in progress\n", name); |
| 158 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 159 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 160 | } |
| 161 | |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 162 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 163 | const char *name, u32 reg) |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 164 | { |
| 165 | if (dev_priv->hpll_freq == 0) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 166 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 167 | |
| 168 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 169 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 170 | } |
| 171 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 172 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 173 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 174 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 175 | return; |
| 176 | |
| 177 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 178 | CCK_CZ_CLOCK_CONTROL); |
| 179 | |
| 180 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 181 | } |
| 182 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 183 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 184 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 185 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 186 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 187 | if (HAS_DDI(dev_priv)) |
| 188 | return pipe_config->port_clock; /* SPLL */ |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 189 | else |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 190 | return dev_priv->fdi_pll_freq; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 193 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 194 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 195 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 196 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 197 | .m = { .min = 96, .max = 140 }, |
| 198 | .m1 = { .min = 18, .max = 26 }, |
| 199 | .m2 = { .min = 6, .max = 16 }, |
| 200 | .p = { .min = 4, .max = 128 }, |
| 201 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 202 | .p2 = { .dot_limit = 165000, |
| 203 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 206 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 207 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 208 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 209 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 210 | .m = { .min = 96, .max = 140 }, |
| 211 | .m1 = { .min = 18, .max = 26 }, |
| 212 | .m2 = { .min = 6, .max = 16 }, |
| 213 | .p = { .min = 4, .max = 128 }, |
| 214 | .p1 = { .min = 2, .max = 33 }, |
| 215 | .p2 = { .dot_limit = 165000, |
| 216 | .p2_slow = 4, .p2_fast = 4 }, |
| 217 | }; |
| 218 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 219 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 220 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 221 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 222 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 223 | .m = { .min = 96, .max = 140 }, |
| 224 | .m1 = { .min = 18, .max = 26 }, |
| 225 | .m2 = { .min = 6, .max = 16 }, |
| 226 | .p = { .min = 4, .max = 128 }, |
| 227 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 228 | .p2 = { .dot_limit = 165000, |
| 229 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 230 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 231 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 232 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 233 | .dot = { .min = 20000, .max = 400000 }, |
| 234 | .vco = { .min = 1400000, .max = 2800000 }, |
| 235 | .n = { .min = 1, .max = 6 }, |
| 236 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 237 | .m1 = { .min = 8, .max = 18 }, |
| 238 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 239 | .p = { .min = 5, .max = 80 }, |
| 240 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 241 | .p2 = { .dot_limit = 200000, |
| 242 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 245 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 246 | .dot = { .min = 20000, .max = 400000 }, |
| 247 | .vco = { .min = 1400000, .max = 2800000 }, |
| 248 | .n = { .min = 1, .max = 6 }, |
| 249 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 250 | .m1 = { .min = 8, .max = 18 }, |
| 251 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 252 | .p = { .min = 7, .max = 98 }, |
| 253 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 254 | .p2 = { .dot_limit = 112000, |
| 255 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 258 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 259 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 260 | .dot = { .min = 25000, .max = 270000 }, |
| 261 | .vco = { .min = 1750000, .max = 3500000}, |
| 262 | .n = { .min = 1, .max = 4 }, |
| 263 | .m = { .min = 104, .max = 138 }, |
| 264 | .m1 = { .min = 17, .max = 23 }, |
| 265 | .m2 = { .min = 5, .max = 11 }, |
| 266 | .p = { .min = 10, .max = 30 }, |
| 267 | .p1 = { .min = 1, .max = 3}, |
| 268 | .p2 = { .dot_limit = 270000, |
| 269 | .p2_slow = 10, |
| 270 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 271 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 274 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 275 | .dot = { .min = 22000, .max = 400000 }, |
| 276 | .vco = { .min = 1750000, .max = 3500000}, |
| 277 | .n = { .min = 1, .max = 4 }, |
| 278 | .m = { .min = 104, .max = 138 }, |
| 279 | .m1 = { .min = 16, .max = 23 }, |
| 280 | .m2 = { .min = 5, .max = 11 }, |
| 281 | .p = { .min = 5, .max = 80 }, |
| 282 | .p1 = { .min = 1, .max = 8}, |
| 283 | .p2 = { .dot_limit = 165000, |
| 284 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 287 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 288 | .dot = { .min = 20000, .max = 115000 }, |
| 289 | .vco = { .min = 1750000, .max = 3500000 }, |
| 290 | .n = { .min = 1, .max = 3 }, |
| 291 | .m = { .min = 104, .max = 138 }, |
| 292 | .m1 = { .min = 17, .max = 23 }, |
| 293 | .m2 = { .min = 5, .max = 11 }, |
| 294 | .p = { .min = 28, .max = 112 }, |
| 295 | .p1 = { .min = 2, .max = 8 }, |
| 296 | .p2 = { .dot_limit = 0, |
| 297 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 298 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 299 | }; |
| 300 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 301 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 302 | .dot = { .min = 80000, .max = 224000 }, |
| 303 | .vco = { .min = 1750000, .max = 3500000 }, |
| 304 | .n = { .min = 1, .max = 3 }, |
| 305 | .m = { .min = 104, .max = 138 }, |
| 306 | .m1 = { .min = 17, .max = 23 }, |
| 307 | .m2 = { .min = 5, .max = 11 }, |
| 308 | .p = { .min = 14, .max = 42 }, |
| 309 | .p1 = { .min = 2, .max = 6 }, |
| 310 | .p2 = { .dot_limit = 0, |
| 311 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 312 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 315 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 316 | .dot = { .min = 20000, .max = 400000}, |
| 317 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 318 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 319 | .n = { .min = 3, .max = 6 }, |
| 320 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 321 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 322 | .m1 = { .min = 0, .max = 0 }, |
| 323 | .m2 = { .min = 0, .max = 254 }, |
| 324 | .p = { .min = 5, .max = 80 }, |
| 325 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 326 | .p2 = { .dot_limit = 200000, |
| 327 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 328 | }; |
| 329 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 330 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 331 | .dot = { .min = 20000, .max = 400000 }, |
| 332 | .vco = { .min = 1700000, .max = 3500000 }, |
| 333 | .n = { .min = 3, .max = 6 }, |
| 334 | .m = { .min = 2, .max = 256 }, |
| 335 | .m1 = { .min = 0, .max = 0 }, |
| 336 | .m2 = { .min = 0, .max = 254 }, |
| 337 | .p = { .min = 7, .max = 112 }, |
| 338 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 339 | .p2 = { .dot_limit = 112000, |
| 340 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 341 | }; |
| 342 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 343 | /* Ironlake / Sandybridge |
| 344 | * |
| 345 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 346 | * the range value for them is (actual_value - 2). |
| 347 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 348 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 349 | .dot = { .min = 25000, .max = 350000 }, |
| 350 | .vco = { .min = 1760000, .max = 3510000 }, |
| 351 | .n = { .min = 1, .max = 5 }, |
| 352 | .m = { .min = 79, .max = 127 }, |
| 353 | .m1 = { .min = 12, .max = 22 }, |
| 354 | .m2 = { .min = 5, .max = 9 }, |
| 355 | .p = { .min = 5, .max = 80 }, |
| 356 | .p1 = { .min = 1, .max = 8 }, |
| 357 | .p2 = { .dot_limit = 225000, |
| 358 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 361 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 362 | .dot = { .min = 25000, .max = 350000 }, |
| 363 | .vco = { .min = 1760000, .max = 3510000 }, |
| 364 | .n = { .min = 1, .max = 3 }, |
| 365 | .m = { .min = 79, .max = 118 }, |
| 366 | .m1 = { .min = 12, .max = 22 }, |
| 367 | .m2 = { .min = 5, .max = 9 }, |
| 368 | .p = { .min = 28, .max = 112 }, |
| 369 | .p1 = { .min = 2, .max = 8 }, |
| 370 | .p2 = { .dot_limit = 225000, |
| 371 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 372 | }; |
| 373 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 374 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 375 | .dot = { .min = 25000, .max = 350000 }, |
| 376 | .vco = { .min = 1760000, .max = 3510000 }, |
| 377 | .n = { .min = 1, .max = 3 }, |
| 378 | .m = { .min = 79, .max = 127 }, |
| 379 | .m1 = { .min = 12, .max = 22 }, |
| 380 | .m2 = { .min = 5, .max = 9 }, |
| 381 | .p = { .min = 14, .max = 56 }, |
| 382 | .p1 = { .min = 2, .max = 8 }, |
| 383 | .p2 = { .dot_limit = 225000, |
| 384 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 385 | }; |
| 386 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 387 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 388 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 389 | .dot = { .min = 25000, .max = 350000 }, |
| 390 | .vco = { .min = 1760000, .max = 3510000 }, |
| 391 | .n = { .min = 1, .max = 2 }, |
| 392 | .m = { .min = 79, .max = 126 }, |
| 393 | .m1 = { .min = 12, .max = 22 }, |
| 394 | .m2 = { .min = 5, .max = 9 }, |
| 395 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 396 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 397 | .p2 = { .dot_limit = 225000, |
| 398 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 399 | }; |
| 400 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 401 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 402 | .dot = { .min = 25000, .max = 350000 }, |
| 403 | .vco = { .min = 1760000, .max = 3510000 }, |
| 404 | .n = { .min = 1, .max = 3 }, |
| 405 | .m = { .min = 79, .max = 126 }, |
| 406 | .m1 = { .min = 12, .max = 22 }, |
| 407 | .m2 = { .min = 5, .max = 9 }, |
| 408 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 409 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 410 | .p2 = { .dot_limit = 225000, |
| 411 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 412 | }; |
| 413 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 414 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 415 | /* |
| 416 | * These are the data rate limits (measured in fast clocks) |
| 417 | * since those are the strictest limits we have. The fast |
| 418 | * clock and actual rate limits are more relaxed, so checking |
| 419 | * them would make no difference. |
| 420 | */ |
| 421 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 422 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 423 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 424 | .m1 = { .min = 2, .max = 3 }, |
| 425 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 426 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 427 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 428 | }; |
| 429 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 430 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 431 | /* |
| 432 | * These are the data rate limits (measured in fast clocks) |
| 433 | * since those are the strictest limits we have. The fast |
| 434 | * clock and actual rate limits are more relaxed, so checking |
| 435 | * them would make no difference. |
| 436 | */ |
| 437 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 438 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 439 | .n = { .min = 1, .max = 1 }, |
| 440 | .m1 = { .min = 2, .max = 2 }, |
| 441 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 442 | .p1 = { .min = 2, .max = 4 }, |
| 443 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 444 | }; |
| 445 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 446 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 447 | /* FIXME: find real dot limits */ |
| 448 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 449 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 450 | .n = { .min = 1, .max = 1 }, |
| 451 | .m1 = { .min = 2, .max = 2 }, |
| 452 | /* FIXME: find real m2 limits */ |
| 453 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 454 | .p1 = { .min = 2, .max = 4 }, |
| 455 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 456 | }; |
| 457 | |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 458 | static void |
| 459 | skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 460 | { |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 461 | if (enable) |
| 462 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 463 | DUPS1_GATING_DIS | DUPS2_GATING_DIS); |
| 464 | else |
| 465 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 466 | I915_READ(CLKGATE_DIS_PSL(pipe)) & |
| 467 | ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); |
| 468 | } |
| 469 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 470 | static bool |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 471 | needs_modeset(const struct drm_crtc_state *state) |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 472 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 473 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 476 | /* |
| 477 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 478 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 479 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 480 | * The helpers' return value is the rate of the clock that is fed to the |
| 481 | * display engine's pipe which can be the above fast dot clock rate or a |
| 482 | * divided-down version of it. |
| 483 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 484 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 485 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 486 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 487 | clock->m = clock->m2 + 2; |
| 488 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 489 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 490 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 491 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 492 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 493 | |
| 494 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 495 | } |
| 496 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 497 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 498 | { |
| 499 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 500 | } |
| 501 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 502 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 503 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 504 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 505 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 506 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 507 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 508 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 509 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 510 | |
| 511 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 514 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 515 | { |
| 516 | clock->m = clock->m1 * clock->m2; |
| 517 | clock->p = clock->p1 * clock->p2; |
| 518 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 519 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 520 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 521 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 522 | |
| 523 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 524 | } |
| 525 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 526 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 527 | { |
| 528 | clock->m = clock->m1 * clock->m2; |
| 529 | clock->p = clock->p1 * clock->p2; |
| 530 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 531 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 532 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 533 | clock->n << 22); |
| 534 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 535 | |
| 536 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 537 | } |
| 538 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 539 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 540 | |
| 541 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 542 | * Returns whether the given set of divisors are valid for a given refclk with |
| 543 | * the given connectors. |
| 544 | */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 545 | static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 546 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 547 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 548 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 549 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 550 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 551 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 552 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 553 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 554 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 555 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 556 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 557 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 558 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 559 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 560 | if (clock->m1 <= clock->m2) |
| 561 | INTELPllInvalid("m1 <= m2\n"); |
| 562 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 563 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 564 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 565 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 566 | INTELPllInvalid("p out of range\n"); |
| 567 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 568 | INTELPllInvalid("m out of range\n"); |
| 569 | } |
| 570 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 571 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 572 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 573 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 574 | * connector, etc., rather than just a single range. |
| 575 | */ |
| 576 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 577 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 578 | |
| 579 | return true; |
| 580 | } |
| 581 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 582 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 583 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 584 | const struct intel_crtc_state *crtc_state, |
| 585 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 586 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 587 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 588 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 589 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 590 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 591 | * For LVDS just rely on its current settings for dual-channel. |
| 592 | * We haven't figured out how to reliably set up different |
| 593 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 594 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 595 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 596 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 597 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 598 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | } else { |
| 600 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 601 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 602 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 603 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 604 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 605 | } |
| 606 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 607 | /* |
| 608 | * Returns a set of divisors for the desired target clock with the given |
| 609 | * refclk, or FALSE. The returned values represent the clock equation: |
| 610 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 611 | * |
| 612 | * Target and reference clocks are specified in kHz. |
| 613 | * |
| 614 | * If match_clock is provided, then best_clock P divider must match the P |
| 615 | * divider from @match_clock used for LVDS downclocking. |
| 616 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 617 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 618 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 619 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 620 | int target, int refclk, struct dpll *match_clock, |
| 621 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 622 | { |
| 623 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 624 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 625 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 626 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 627 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 628 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 629 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 630 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 631 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 632 | clock.m1++) { |
| 633 | for (clock.m2 = limit->m2.min; |
| 634 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 635 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 636 | break; |
| 637 | for (clock.n = limit->n.min; |
| 638 | clock.n <= limit->n.max; clock.n++) { |
| 639 | for (clock.p1 = limit->p1.min; |
| 640 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 641 | int this_err; |
| 642 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 643 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 644 | if (!intel_PLL_is_valid(to_i915(dev), |
| 645 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 646 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 647 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 648 | if (match_clock && |
| 649 | clock.p != match_clock->p) |
| 650 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 651 | |
| 652 | this_err = abs(clock.dot - target); |
| 653 | if (this_err < err) { |
| 654 | *best_clock = clock; |
| 655 | err = this_err; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | return (err != target); |
| 663 | } |
| 664 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 665 | /* |
| 666 | * Returns a set of divisors for the desired target clock with the given |
| 667 | * refclk, or FALSE. The returned values represent the clock equation: |
| 668 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 669 | * |
| 670 | * Target and reference clocks are specified in kHz. |
| 671 | * |
| 672 | * If match_clock is provided, then best_clock P divider must match the P |
| 673 | * divider from @match_clock used for LVDS downclocking. |
| 674 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 675 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 676 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 677 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 678 | int target, int refclk, struct dpll *match_clock, |
| 679 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 680 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 681 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 682 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 683 | int err = target; |
| 684 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 685 | memset(best_clock, 0, sizeof(*best_clock)); |
| 686 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 687 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 688 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 689 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 690 | clock.m1++) { |
| 691 | for (clock.m2 = limit->m2.min; |
| 692 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 693 | for (clock.n = limit->n.min; |
| 694 | clock.n <= limit->n.max; clock.n++) { |
| 695 | for (clock.p1 = limit->p1.min; |
| 696 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 697 | int this_err; |
| 698 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 699 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 700 | if (!intel_PLL_is_valid(to_i915(dev), |
| 701 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 702 | &clock)) |
| 703 | continue; |
| 704 | if (match_clock && |
| 705 | clock.p != match_clock->p) |
| 706 | continue; |
| 707 | |
| 708 | this_err = abs(clock.dot - target); |
| 709 | if (this_err < err) { |
| 710 | *best_clock = clock; |
| 711 | err = this_err; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | return (err != target); |
| 719 | } |
| 720 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 721 | /* |
| 722 | * Returns a set of divisors for the desired target clock with the given |
| 723 | * refclk, or FALSE. The returned values represent the clock equation: |
| 724 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 725 | * |
| 726 | * Target and reference clocks are specified in kHz. |
| 727 | * |
| 728 | * If match_clock is provided, then best_clock P divider must match the P |
| 729 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 730 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 731 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 732 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 733 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 734 | int target, int refclk, struct dpll *match_clock, |
| 735 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 736 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 737 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 738 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 739 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 740 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 741 | /* approximately equals target * 0.00585 */ |
| 742 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 743 | |
| 744 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 745 | |
| 746 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 747 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 748 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 749 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 750 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 751 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 752 | for (clock.m1 = limit->m1.max; |
| 753 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 754 | for (clock.m2 = limit->m2.max; |
| 755 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 756 | for (clock.p1 = limit->p1.max; |
| 757 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 758 | int this_err; |
| 759 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 760 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 761 | if (!intel_PLL_is_valid(to_i915(dev), |
| 762 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 763 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 764 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 765 | |
| 766 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 767 | if (this_err < err_most) { |
| 768 | *best_clock = clock; |
| 769 | err_most = this_err; |
| 770 | max_n = clock.n; |
| 771 | found = true; |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 777 | return found; |
| 778 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 779 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 780 | /* |
| 781 | * Check if the calculated PLL configuration is more optimal compared to the |
| 782 | * best configuration and error found so far. Return the calculated error. |
| 783 | */ |
| 784 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 785 | const struct dpll *calculated_clock, |
| 786 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 787 | unsigned int best_error_ppm, |
| 788 | unsigned int *error_ppm) |
| 789 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 790 | /* |
| 791 | * For CHV ignore the error and consider only the P value. |
| 792 | * Prefer a bigger P value based on HW requirements. |
| 793 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 794 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 795 | *error_ppm = 0; |
| 796 | |
| 797 | return calculated_clock->p > best_clock->p; |
| 798 | } |
| 799 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 800 | if (WARN_ON_ONCE(!target_freq)) |
| 801 | return false; |
| 802 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 803 | *error_ppm = div_u64(1000000ULL * |
| 804 | abs(target_freq - calculated_clock->dot), |
| 805 | target_freq); |
| 806 | /* |
| 807 | * Prefer a better P value over a better (smaller) error if the error |
| 808 | * is small. Ensure this preference for future configurations too by |
| 809 | * setting the error to 0. |
| 810 | */ |
| 811 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 812 | *error_ppm = 0; |
| 813 | |
| 814 | return true; |
| 815 | } |
| 816 | |
| 817 | return *error_ppm + 10 < best_error_ppm; |
| 818 | } |
| 819 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 820 | /* |
| 821 | * Returns a set of divisors for the desired target clock with the given |
| 822 | * refclk, or FALSE. The returned values represent the clock equation: |
| 823 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 824 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 825 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 826 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 827 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 828 | int target, int refclk, struct dpll *match_clock, |
| 829 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 830 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 831 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 832 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 833 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 834 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 835 | /* min update 19.2 MHz */ |
| 836 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 837 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 838 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 839 | target *= 5; /* fast clock */ |
| 840 | |
| 841 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 842 | |
| 843 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 844 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Ville Syrjälä | 811bbf0 | 2013-09-24 21:26:25 +0300 | [diff] [blame] | 845 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
Ville Syrjälä | 889059d | 2013-09-24 21:26:27 +0300 | [diff] [blame] | 846 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
Ville Syrjälä | c1a9ae4 | 2013-09-24 21:26:23 +0300 | [diff] [blame] | 847 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 848 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 849 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 850 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 851 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 852 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 853 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 854 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 855 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 856 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 857 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 858 | if (!intel_PLL_is_valid(to_i915(dev), |
| 859 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 860 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 861 | continue; |
| 862 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 863 | if (!vlv_PLL_is_optimal(dev, target, |
| 864 | &clock, |
| 865 | best_clock, |
| 866 | bestppm, &ppm)) |
| 867 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 868 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 869 | *best_clock = clock; |
| 870 | bestppm = ppm; |
| 871 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | } |
| 875 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 876 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 877 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 878 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 879 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 880 | /* |
| 881 | * Returns a set of divisors for the desired target clock with the given |
| 882 | * refclk, or FALSE. The returned values represent the clock equation: |
| 883 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 884 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 885 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 886 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 887 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 888 | int target, int refclk, struct dpll *match_clock, |
| 889 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 890 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 891 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 892 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 893 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 894 | struct dpll clock; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 895 | uint64_t m2; |
| 896 | int found = false; |
| 897 | |
| 898 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 899 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 900 | |
| 901 | /* |
| 902 | * Based on hardware doc, the n always set to 1, and m1 always |
| 903 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 904 | * revisit this because n may not 1 anymore. |
| 905 | */ |
| 906 | clock.n = 1, clock.m1 = 2; |
| 907 | target *= 5; /* fast clock */ |
| 908 | |
| 909 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 910 | for (clock.p2 = limit->p2.p2_fast; |
| 911 | clock.p2 >= limit->p2.p2_slow; |
| 912 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 913 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 914 | |
| 915 | clock.p = clock.p1 * clock.p2; |
| 916 | |
| 917 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 918 | clock.n) << 22, refclk * clock.m1); |
| 919 | |
| 920 | if (m2 > INT_MAX/clock.m1) |
| 921 | continue; |
| 922 | |
| 923 | clock.m2 = m2; |
| 924 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 925 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 926 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 927 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 928 | continue; |
| 929 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 930 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 931 | best_error_ppm, &error_ppm)) |
| 932 | continue; |
| 933 | |
| 934 | *best_clock = clock; |
| 935 | best_error_ppm = error_ppm; |
| 936 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
| 940 | return found; |
| 941 | } |
| 942 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 943 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 944 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 945 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 946 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 947 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 948 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 949 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 950 | target_clock, refclk, NULL, best_clock); |
| 951 | } |
| 952 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 953 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 954 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 955 | /* Be paranoid as we can arrive here with only partial |
| 956 | * state retrieved from the hardware during setup. |
| 957 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 958 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 959 | * as Haswell has gained clock readout/fastboot support. |
| 960 | * |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 961 | * We can ditch the crtc->primary->state->fb check as soon as we can |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 962 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 963 | * |
| 964 | * FIXME: The intel_crtc->active here should be switched to |
| 965 | * crtc->state->active once we have proper CRTC states wired up |
| 966 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 967 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 968 | return crtc->active && crtc->base.primary->state->fb && |
| 969 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 970 | } |
| 971 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 972 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 973 | enum pipe pipe) |
| 974 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 975 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 976 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 977 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 978 | } |
| 979 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 980 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
| 981 | enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 982 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 983 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 984 | u32 line1, line2; |
| 985 | u32 line_mask; |
| 986 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 987 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 988 | line_mask = DSL_LINEMASK_GEN2; |
| 989 | else |
| 990 | line_mask = DSL_LINEMASK_GEN3; |
| 991 | |
| 992 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 993 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 994 | line2 = I915_READ(reg) & line_mask; |
| 995 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 996 | return line1 != line2; |
| 997 | } |
| 998 | |
| 999 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) |
| 1000 | { |
| 1001 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1002 | enum pipe pipe = crtc->pipe; |
| 1003 | |
| 1004 | /* Wait for the display line to settle/start moving */ |
| 1005 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) |
| 1006 | DRM_ERROR("pipe %c scanline %s wait timed out\n", |
| 1007 | pipe_name(pipe), onoff(state)); |
| 1008 | } |
| 1009 | |
| 1010 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) |
| 1011 | { |
| 1012 | wait_for_pipe_scanline_moving(crtc, false); |
| 1013 | } |
| 1014 | |
| 1015 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) |
| 1016 | { |
| 1017 | wait_for_pipe_scanline_moving(crtc, true); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1018 | } |
| 1019 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1020 | static void |
| 1021 | intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1022 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1023 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1024 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1025 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1026 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1027 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1028 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1029 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1030 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1031 | if (intel_wait_for_register(dev_priv, |
| 1032 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1033 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1034 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1035 | } else { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1036 | intel_wait_for_pipe_scanline_stopped(crtc); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1037 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1040 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1041 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1042 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1043 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1044 | u32 val; |
| 1045 | bool cur_state; |
| 1046 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1047 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1048 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1049 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1050 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1051 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1052 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1053 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1054 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1055 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1056 | { |
| 1057 | u32 val; |
| 1058 | bool cur_state; |
| 1059 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1060 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1061 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1062 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1063 | |
| 1064 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1065 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1066 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1067 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1068 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1069 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1070 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1071 | enum pipe pipe, bool state) |
| 1072 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1073 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1074 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1075 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1076 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1077 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1078 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1079 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1080 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1081 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1082 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1083 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1084 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1085 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1086 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1087 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1088 | } |
| 1089 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1090 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1091 | |
| 1092 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1093 | enum pipe pipe, bool state) |
| 1094 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1095 | u32 val; |
| 1096 | bool cur_state; |
| 1097 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1098 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1099 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1100 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1101 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1102 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1103 | } |
| 1104 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1105 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1106 | |
| 1107 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1108 | enum pipe pipe) |
| 1109 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1110 | u32 val; |
| 1111 | |
| 1112 | /* ILK FDI PLL is always enabled */ |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 1113 | if (IS_GEN5(dev_priv)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1114 | return; |
| 1115 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1116 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1117 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1118 | return; |
| 1119 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1120 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1121 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1124 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1125 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1126 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1127 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1128 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1129 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1130 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1131 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1132 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1133 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1134 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1135 | } |
| 1136 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1137 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1138 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1139 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1140 | u32 val; |
Ville Syrjälä | 10ed55e | 2018-05-23 17:57:18 +0300 | [diff] [blame] | 1141 | enum pipe panel_pipe = INVALID_PIPE; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1142 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1143 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1144 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1145 | return; |
| 1146 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1147 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1148 | u32 port_sel; |
| 1149 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1150 | pp_reg = PP_CONTROL(0); |
| 1151 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1152 | |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1153 | switch (port_sel) { |
| 1154 | case PANEL_PORT_SELECT_LVDS: |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1155 | intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe); |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1156 | break; |
| 1157 | case PANEL_PORT_SELECT_DPA: |
| 1158 | intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe); |
| 1159 | break; |
| 1160 | case PANEL_PORT_SELECT_DPC: |
| 1161 | intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe); |
| 1162 | break; |
| 1163 | case PANEL_PORT_SELECT_DPD: |
| 1164 | intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe); |
| 1165 | break; |
| 1166 | default: |
| 1167 | MISSING_CASE(port_sel); |
| 1168 | break; |
| 1169 | } |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1170 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1171 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1172 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1173 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1174 | } else { |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1175 | u32 port_sel; |
| 1176 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1177 | pp_reg = PP_CONTROL(0); |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1178 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
| 1179 | |
| 1180 | WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS); |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1181 | intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | val = I915_READ(pp_reg); |
| 1185 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1186 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1187 | locked = false; |
| 1188 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1189 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1190 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1191 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1192 | } |
| 1193 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1194 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1195 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1196 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1197 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1198 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1199 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1200 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1201 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1202 | /* we keep both pipes enabled on 830 */ |
| 1203 | if (IS_I830(dev_priv)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1204 | state = true; |
| 1205 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1206 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1207 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1208 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1209 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1210 | |
| 1211 | intel_display_power_put(dev_priv, power_domain); |
| 1212 | } else { |
| 1213 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1216 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1217 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1218 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1221 | static void assert_plane(struct intel_plane *plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1222 | { |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 1223 | enum pipe pipe; |
| 1224 | bool cur_state; |
| 1225 | |
| 1226 | cur_state = plane->get_hw_state(plane, &pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1227 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1228 | I915_STATE_WARN(cur_state != state, |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1229 | "%s assertion failure (expected %s, current %s)\n", |
| 1230 | plane->base.name, onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1231 | } |
| 1232 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1233 | #define assert_plane_enabled(p) assert_plane(p, true) |
| 1234 | #define assert_plane_disabled(p) assert_plane(p, false) |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1235 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1236 | static void assert_planes_disabled(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1237 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1238 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1239 | struct intel_plane *plane; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1240 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1241 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
| 1242 | assert_plane_disabled(plane); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1245 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1246 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1247 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1248 | drm_crtc_vblank_put(crtc); |
| 1249 | } |
| 1250 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1251 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1252 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1253 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1254 | u32 val; |
| 1255 | bool enabled; |
| 1256 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1257 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1258 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1259 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1260 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1261 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1264 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1265 | enum pipe pipe, enum port port, |
| 1266 | i915_reg_t dp_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1267 | { |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1268 | enum pipe port_pipe; |
| 1269 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1270 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1271 | state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe); |
| 1272 | |
| 1273 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1274 | "PCH DP %c enabled on transcoder %c, should be disabled\n", |
| 1275 | port_name(port), pipe_name(pipe)); |
| 1276 | |
| 1277 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1278 | "IBX PCH DP %c still using transcoder B\n", |
| 1279 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1283 | enum pipe pipe, enum port port, |
| 1284 | i915_reg_t hdmi_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1285 | { |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1286 | enum pipe port_pipe; |
| 1287 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1288 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1289 | state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe); |
| 1290 | |
| 1291 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1292 | "PCH HDMI %c enabled on transcoder %c, should be disabled\n", |
| 1293 | port_name(port), pipe_name(pipe)); |
| 1294 | |
| 1295 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1296 | "IBX PCH HDMI %c still using transcoder B\n", |
| 1297 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1301 | enum pipe pipe) |
| 1302 | { |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1303 | enum pipe port_pipe; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1304 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1305 | assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B); |
| 1306 | assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C); |
| 1307 | assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1308 | |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1309 | I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) && |
| 1310 | port_pipe == pipe, |
| 1311 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
| 1312 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1313 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1314 | I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) && |
| 1315 | port_pipe == pipe, |
| 1316 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
| 1317 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1318 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1319 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB); |
| 1320 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC); |
| 1321 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1324 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1325 | const struct intel_crtc_state *pipe_config) |
| 1326 | { |
| 1327 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1328 | enum pipe pipe = crtc->pipe; |
| 1329 | |
| 1330 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1331 | POSTING_READ(DPLL(pipe)); |
| 1332 | udelay(150); |
| 1333 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1334 | if (intel_wait_for_register(dev_priv, |
| 1335 | DPLL(pipe), |
| 1336 | DPLL_LOCK_VLV, |
| 1337 | DPLL_LOCK_VLV, |
| 1338 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1339 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1340 | } |
| 1341 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1342 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1343 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1344 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1345 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1346 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1347 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1348 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1349 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1350 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1351 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1352 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1353 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1354 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1355 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1356 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1357 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1360 | |
| 1361 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1362 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1363 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1364 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1365 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1366 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1367 | u32 tmp; |
| 1368 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1369 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1370 | |
| 1371 | /* Enable back the 10bit clock to display controller */ |
| 1372 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1373 | tmp |= DPIO_DCLKP_EN; |
| 1374 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1375 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1376 | mutex_unlock(&dev_priv->sb_lock); |
| 1377 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1378 | /* |
| 1379 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1380 | */ |
| 1381 | udelay(1); |
| 1382 | |
| 1383 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1384 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1385 | |
| 1386 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1387 | if (intel_wait_for_register(dev_priv, |
| 1388 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1389 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1390 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1394 | const struct intel_crtc_state *pipe_config) |
| 1395 | { |
| 1396 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1397 | enum pipe pipe = crtc->pipe; |
| 1398 | |
| 1399 | assert_pipe_disabled(dev_priv, pipe); |
| 1400 | |
| 1401 | /* PLL is protected by panel, make sure we can write it */ |
| 1402 | assert_panel_unlocked(dev_priv, pipe); |
| 1403 | |
| 1404 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1405 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1406 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1407 | if (pipe != PIPE_A) { |
| 1408 | /* |
| 1409 | * WaPixelRepeatModeFixForC0:chv |
| 1410 | * |
| 1411 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1412 | * the value from DPLLBMD to either pipe B or C. |
| 1413 | */ |
Ville Syrjälä | dfa311f | 2017-09-13 17:08:54 +0300 | [diff] [blame] | 1414 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1415 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1416 | I915_WRITE(CBR4_VLV, 0); |
| 1417 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1418 | |
| 1419 | /* |
| 1420 | * DPLLB VGA mode also seems to cause problems. |
| 1421 | * We should always have it disabled. |
| 1422 | */ |
| 1423 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1424 | } else { |
| 1425 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1426 | POSTING_READ(DPLL_MD(pipe)); |
| 1427 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1428 | } |
| 1429 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1430 | 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] | 1431 | { |
| 1432 | struct intel_crtc *crtc; |
| 1433 | int count = 0; |
| 1434 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1435 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1436 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1437 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1438 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1439 | |
| 1440 | return count; |
| 1441 | } |
| 1442 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1443 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
| 1444 | const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1445 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1446 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1447 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1448 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1449 | int i; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1450 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1451 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1452 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1453 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1454 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1455 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1456 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1457 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1458 | 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] | 1459 | /* |
| 1460 | * It appears to be important that we don't enable this |
| 1461 | * for the current pipe before otherwise configuring the |
| 1462 | * PLL. No idea how this should be handled if multiple |
| 1463 | * DVO outputs are enabled simultaneosly. |
| 1464 | */ |
| 1465 | dpll |= DPLL_DVO_2X_MODE; |
| 1466 | I915_WRITE(DPLL(!crtc->pipe), |
| 1467 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1468 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1469 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1470 | /* |
| 1471 | * Apparently we need to have VGA mode enabled prior to changing |
| 1472 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1473 | * dividers, even though the register value does change. |
| 1474 | */ |
| 1475 | I915_WRITE(reg, 0); |
| 1476 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1477 | I915_WRITE(reg, dpll); |
| 1478 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1479 | /* Wait for the clocks to stabilize. */ |
| 1480 | POSTING_READ(reg); |
| 1481 | udelay(150); |
| 1482 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1483 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1484 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1485 | crtc_state->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1486 | } else { |
| 1487 | /* The pixel multiplier can only be updated once the |
| 1488 | * DPLL is enabled and the clocks are stable. |
| 1489 | * |
| 1490 | * So write it again. |
| 1491 | */ |
| 1492 | I915_WRITE(reg, dpll); |
| 1493 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1494 | |
| 1495 | /* We do this three times for luck */ |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1496 | for (i = 0; i < 3; i++) { |
| 1497 | I915_WRITE(reg, dpll); |
| 1498 | POSTING_READ(reg); |
| 1499 | udelay(150); /* wait for warmup */ |
| 1500 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1501 | } |
| 1502 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1503 | static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1504 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1505 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1506 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1507 | enum pipe pipe = crtc->pipe; |
| 1508 | |
| 1509 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1510 | if (IS_I830(dev_priv) && |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1511 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1512 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1513 | I915_WRITE(DPLL(PIPE_B), |
| 1514 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1515 | I915_WRITE(DPLL(PIPE_A), |
| 1516 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1517 | } |
| 1518 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1519 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1520 | if (IS_I830(dev_priv)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1521 | return; |
| 1522 | |
| 1523 | /* Make sure the pipe isn't still relying on us */ |
| 1524 | assert_pipe_disabled(dev_priv, pipe); |
| 1525 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1526 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1527 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1528 | } |
| 1529 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1530 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1531 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1532 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1533 | |
| 1534 | /* Make sure the pipe isn't still relying on us */ |
| 1535 | assert_pipe_disabled(dev_priv, pipe); |
| 1536 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1537 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1538 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1539 | if (pipe != PIPE_A) |
| 1540 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1541 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1542 | I915_WRITE(DPLL(pipe), val); |
| 1543 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1547 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1548 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1549 | u32 val; |
| 1550 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1551 | /* Make sure the pipe isn't still relying on us */ |
| 1552 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1553 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1554 | val = DPLL_SSC_REF_CLK_CHV | |
| 1555 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1556 | if (pipe != PIPE_A) |
| 1557 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1558 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1559 | I915_WRITE(DPLL(pipe), val); |
| 1560 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1561 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1562 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1563 | |
| 1564 | /* Disable 10bit clock to display controller */ |
| 1565 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1566 | val &= ~DPIO_DCLKP_EN; |
| 1567 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1568 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1569 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1572 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1573 | struct intel_digital_port *dport, |
| 1574 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1575 | { |
| 1576 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1577 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1578 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1579 | switch (dport->base.port) { |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1580 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1581 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1582 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1583 | break; |
| 1584 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1585 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1586 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1587 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1588 | break; |
| 1589 | case PORT_D: |
| 1590 | port_mask = DPLL_PORTD_READY_MASK; |
| 1591 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1592 | break; |
| 1593 | default: |
| 1594 | BUG(); |
| 1595 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1596 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1597 | if (intel_wait_for_register(dev_priv, |
| 1598 | dpll_reg, port_mask, expected_mask, |
| 1599 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1600 | 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] | 1601 | port_name(dport->base.port), |
| 1602 | I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1605 | static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1606 | { |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1607 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1608 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1609 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1610 | i915_reg_t reg; |
| 1611 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1612 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1613 | /* Make sure PCH DPLL is enabled */ |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1614 | assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1615 | |
| 1616 | /* FDI must be feeding us bits for PCH ports */ |
| 1617 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1618 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1619 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1620 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1621 | /* Workaround: Set the timing override bit before enabling the |
| 1622 | * pch transcoder. */ |
| 1623 | reg = TRANS_CHICKEN2(pipe); |
| 1624 | val = I915_READ(reg); |
| 1625 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1626 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1627 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1628 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1629 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1630 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1631 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1632 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1633 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1634 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1635 | * Make the BPC in transcoder be consistent with |
| 1636 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1637 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1638 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1639 | val &= ~PIPECONF_BPC_MASK; |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1640 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1641 | val |= PIPECONF_8BPC; |
| 1642 | else |
| 1643 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1644 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1645 | |
| 1646 | val &= ~TRANS_INTERLACE_MASK; |
| 1647 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1648 | if (HAS_PCH_IBX(dev_priv) && |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1649 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1650 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1651 | else |
| 1652 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1653 | else |
| 1654 | val |= TRANS_PROGRESSIVE; |
| 1655 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1656 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1657 | if (intel_wait_for_register(dev_priv, |
| 1658 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1659 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1660 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1661 | } |
| 1662 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1663 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1664 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1665 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1666 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1667 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1668 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1669 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1670 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1671 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1672 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1673 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1674 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1675 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1676 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1677 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1678 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1679 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1680 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1681 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1682 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1683 | else |
| 1684 | val |= TRANS_PROGRESSIVE; |
| 1685 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1686 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1687 | if (intel_wait_for_register(dev_priv, |
| 1688 | LPT_TRANSCONF, |
| 1689 | TRANS_STATE_ENABLE, |
| 1690 | TRANS_STATE_ENABLE, |
| 1691 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1692 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1695 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1696 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1697 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1698 | i915_reg_t reg; |
| 1699 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1700 | |
| 1701 | /* FDI relies on the transcoder */ |
| 1702 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1703 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1704 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1705 | /* Ports must be off as well */ |
| 1706 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1707 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1708 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1709 | val = I915_READ(reg); |
| 1710 | val &= ~TRANS_ENABLE; |
| 1711 | I915_WRITE(reg, val); |
| 1712 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1713 | if (intel_wait_for_register(dev_priv, |
| 1714 | reg, TRANS_STATE_ENABLE, 0, |
| 1715 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1716 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1717 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1718 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1719 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1720 | reg = TRANS_CHICKEN2(pipe); |
| 1721 | val = I915_READ(reg); |
| 1722 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1723 | I915_WRITE(reg, val); |
| 1724 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1725 | } |
| 1726 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1727 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1728 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1729 | u32 val; |
| 1730 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1731 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1732 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1733 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1734 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1735 | if (intel_wait_for_register(dev_priv, |
| 1736 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1737 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1738 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1739 | |
| 1740 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1741 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1742 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1743 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1746 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1747 | { |
| 1748 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1749 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1750 | if (HAS_PCH_LPT(dev_priv)) |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1751 | return PIPE_A; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1752 | else |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1753 | return crtc->pipe; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1754 | } |
| 1755 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1756 | 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] | 1757 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1758 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1759 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1760 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1761 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1762 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1763 | u32 val; |
| 1764 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1765 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1766 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1767 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1768 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1769 | /* |
| 1770 | * A pipe without a PLL won't actually be able to drive bits from |
| 1771 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1772 | * need the check. |
| 1773 | */ |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1774 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1775 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1776 | assert_dsi_pll_enabled(dev_priv); |
| 1777 | else |
| 1778 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1779 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1780 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1781 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1782 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1783 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1784 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1785 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1786 | } |
| 1787 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1788 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1789 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1790 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1791 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1792 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1793 | /* we keep both pipes enabled on 830 */ |
| 1794 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1795 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1796 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1797 | |
| 1798 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1799 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1800 | |
| 1801 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1802 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1803 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1804 | * resets to its proper value. That also messes up the frame count |
| 1805 | * when it's derived from the timestamps. So let's wait for the |
| 1806 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1807 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1808 | if (dev_priv->drm.max_vblank_count == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1809 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1812 | 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] | 1813 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1814 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1815 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1816 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1817 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1818 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1819 | u32 val; |
| 1820 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1821 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1822 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1823 | /* |
| 1824 | * Make sure planes won't keep trying to pump pixels to us, |
| 1825 | * or we might hang the display. |
| 1826 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1827 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1828 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1829 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1830 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1831 | if ((val & PIPECONF_ENABLE) == 0) |
| 1832 | return; |
| 1833 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1834 | /* |
| 1835 | * Double wide has implications for planes |
| 1836 | * so best keep it disabled when not needed. |
| 1837 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1838 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1839 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1840 | |
| 1841 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1842 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1843 | val &= ~PIPECONF_ENABLE; |
| 1844 | |
| 1845 | I915_WRITE(reg, val); |
| 1846 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1847 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1850 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1851 | { |
| 1852 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 1853 | } |
| 1854 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1855 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1856 | intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1857 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1858 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1859 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1860 | |
| 1861 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1862 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1863 | return cpp; |
| 1864 | case I915_FORMAT_MOD_X_TILED: |
| 1865 | if (IS_GEN2(dev_priv)) |
| 1866 | return 128; |
| 1867 | else |
| 1868 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1869 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1870 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1871 | return 128; |
| 1872 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1873 | case I915_FORMAT_MOD_Y_TILED: |
| 1874 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 1875 | return 128; |
| 1876 | else |
| 1877 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1878 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1879 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1880 | return 128; |
| 1881 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1882 | case I915_FORMAT_MOD_Yf_TILED: |
| 1883 | switch (cpp) { |
| 1884 | case 1: |
| 1885 | return 64; |
| 1886 | case 2: |
| 1887 | case 4: |
| 1888 | return 128; |
| 1889 | case 8: |
| 1890 | case 16: |
| 1891 | return 256; |
| 1892 | default: |
| 1893 | MISSING_CASE(cpp); |
| 1894 | return cpp; |
| 1895 | } |
| 1896 | break; |
| 1897 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1898 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1899 | return cpp; |
| 1900 | } |
| 1901 | } |
| 1902 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1903 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1904 | intel_tile_height(const struct drm_framebuffer *fb, int color_plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1905 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1906 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1907 | return 1; |
| 1908 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1909 | return intel_tile_size(to_i915(fb->dev)) / |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1910 | intel_tile_width_bytes(fb, color_plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1913 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1914 | static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1915 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1916 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1917 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1918 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane); |
| 1919 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1920 | |
| 1921 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1922 | *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] | 1923 | } |
| 1924 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1925 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1926 | intel_fb_align_height(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1927 | int color_plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1928 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1929 | unsigned int tile_height = intel_tile_height(fb, color_plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1930 | |
| 1931 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1932 | } |
| 1933 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1934 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1935 | { |
| 1936 | unsigned int size = 0; |
| 1937 | int i; |
| 1938 | |
| 1939 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1940 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1941 | |
| 1942 | return size; |
| 1943 | } |
| 1944 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 1945 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 1946 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 1947 | const struct drm_framebuffer *fb, |
| 1948 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 1949 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1950 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 1951 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1952 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 1953 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1957 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 1958 | { |
| 1959 | if (IS_I830(dev_priv)) |
| 1960 | return 16 * 1024; |
| 1961 | else if (IS_I85X(dev_priv)) |
| 1962 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 1963 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 1964 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1965 | else |
| 1966 | return 4 * 1024; |
| 1967 | } |
| 1968 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1969 | 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] | 1970 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1971 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1972 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 1973 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1974 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1975 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1976 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1977 | return 4 * 1024; |
| 1978 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 1979 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1980 | } |
| 1981 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1982 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1983 | int color_plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1984 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1985 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 1986 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 1987 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1988 | if (color_plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 1989 | return 4096; |
| 1990 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1991 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1992 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1993 | return intel_linear_alignment(dev_priv); |
| 1994 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1995 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1996 | return 256 * 1024; |
| 1997 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1998 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 1999 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2000 | case I915_FORMAT_MOD_Y_TILED: |
| 2001 | case I915_FORMAT_MOD_Yf_TILED: |
| 2002 | return 1 * 1024 * 1024; |
| 2003 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2004 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2005 | return 0; |
| 2006 | } |
| 2007 | } |
| 2008 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2009 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2010 | { |
| 2011 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2012 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2013 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2014 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2015 | } |
| 2016 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2017 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2018 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2019 | const struct i915_ggtt_view *view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2020 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2021 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2022 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2023 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2024 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2025 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2026 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2027 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2028 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2029 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2030 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2031 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2032 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2033 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2034 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2035 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2036 | * we should always have valid PTE following the scanout preventing |
| 2037 | * the VT-d warning. |
| 2038 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2039 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2040 | alignment = 256 * 1024; |
| 2041 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2042 | /* |
| 2043 | * Global gtt pte registers are special registers which actually forward |
| 2044 | * writes to a chunk of system memory. Which means that there is no risk |
| 2045 | * that the register values disappear as soon as we call |
| 2046 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2047 | * pin/unpin/fence and not more. |
| 2048 | */ |
| 2049 | intel_runtime_pm_get(dev_priv); |
| 2050 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2051 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2052 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2053 | pinctl = 0; |
| 2054 | |
| 2055 | /* Valleyview is definitely limited to scanning out the first |
| 2056 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2057 | * g4x display engine and that all earlier gen are similarly |
| 2058 | * limited. Testing suggests that it is a little more |
| 2059 | * complicated than this. For example, Cherryview appears quite |
| 2060 | * happy to scanout from anywhere within its global aperture. |
| 2061 | */ |
| 2062 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 2063 | pinctl |= PIN_MAPPABLE; |
| 2064 | |
| 2065 | vma = i915_gem_object_pin_to_display_plane(obj, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2066 | alignment, view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2067 | if (IS_ERR(vma)) |
| 2068 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2069 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2070 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2071 | int ret; |
| 2072 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2073 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2074 | * fence, whereas 965+ only requires a fence if using |
| 2075 | * framebuffer compression. For simplicity, we always, when |
| 2076 | * possible, install a fence as the cost is not that onerous. |
| 2077 | * |
| 2078 | * If we fail to fence the tiled scanout, then either the |
| 2079 | * modeset will reject the change (which is highly unlikely as |
| 2080 | * the affected systems, all but one, do not have unmappable |
| 2081 | * space) or we will not be able to enable full powersaving |
| 2082 | * techniques (also likely not to apply due to various limits |
| 2083 | * FBC and the like impose on the size of the buffer, which |
| 2084 | * presumably we violated anyway with this unmappable buffer). |
| 2085 | * Anyway, it is presumably better to stumble onwards with |
| 2086 | * something and try to run the system in a "less than optimal" |
| 2087 | * mode that matches the user configuration. |
| 2088 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2089 | ret = i915_vma_pin_fence(vma); |
| 2090 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2091 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2092 | vma = ERR_PTR(ret); |
| 2093 | goto err; |
| 2094 | } |
| 2095 | |
| 2096 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2097 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2098 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2099 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2100 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2101 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2102 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2103 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2104 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2105 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2106 | } |
| 2107 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2108 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2109 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2110 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2111 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2112 | if (flags & PLANE_HAS_FENCE) |
| 2113 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2114 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2115 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2116 | } |
| 2117 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2118 | static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane, |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2119 | unsigned int rotation) |
| 2120 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2121 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2122 | return to_intel_framebuffer(fb)->rotated[color_plane].pitch; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2123 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2124 | return fb->pitches[color_plane]; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2125 | } |
| 2126 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2127 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2128 | * Convert the x/y offsets into a linear offset. |
| 2129 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2130 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2131 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2132 | */ |
| 2133 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2134 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2135 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2136 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2137 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2138 | unsigned int cpp = fb->format->cpp[color_plane]; |
| 2139 | unsigned int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2140 | |
| 2141 | return y * pitch + x * cpp; |
| 2142 | } |
| 2143 | |
| 2144 | /* |
| 2145 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2146 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2147 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2148 | */ |
| 2149 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2150 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2151 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2152 | |
| 2153 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2154 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2155 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2156 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2157 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2158 | *x += intel_fb->rotated[color_plane].x; |
| 2159 | *y += intel_fb->rotated[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2160 | } else { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2161 | *x += intel_fb->normal[color_plane].x; |
| 2162 | *y += intel_fb->normal[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2163 | } |
| 2164 | } |
| 2165 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2166 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2167 | unsigned int tile_width, |
| 2168 | unsigned int tile_height, |
| 2169 | unsigned int tile_size, |
| 2170 | unsigned int pitch_tiles, |
| 2171 | u32 old_offset, |
| 2172 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2173 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2174 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2175 | unsigned int tiles; |
| 2176 | |
| 2177 | WARN_ON(old_offset & (tile_size - 1)); |
| 2178 | WARN_ON(new_offset & (tile_size - 1)); |
| 2179 | WARN_ON(new_offset > old_offset); |
| 2180 | |
| 2181 | tiles = (old_offset - new_offset) / tile_size; |
| 2182 | |
| 2183 | *y += tiles / pitch_tiles * tile_height; |
| 2184 | *x += tiles % pitch_tiles * tile_width; |
| 2185 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2186 | /* minimize x in case it got needlessly big */ |
| 2187 | *y += *x / pitch_pixels * tile_height; |
| 2188 | *x %= pitch_pixels; |
| 2189 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2190 | return new_offset; |
| 2191 | } |
| 2192 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2193 | static bool is_surface_linear(u64 modifier, int color_plane) |
| 2194 | { |
| 2195 | return modifier == DRM_FORMAT_MOD_LINEAR; |
| 2196 | } |
| 2197 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2198 | static u32 intel_adjust_aligned_offset(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2199 | const struct drm_framebuffer *fb, |
| 2200 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2201 | unsigned int rotation, |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2202 | unsigned int pitch, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2203 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2204 | { |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2205 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2206 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2207 | |
| 2208 | WARN_ON(new_offset > old_offset); |
| 2209 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2210 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2211 | unsigned int tile_size, tile_width, tile_height; |
| 2212 | unsigned int pitch_tiles; |
| 2213 | |
| 2214 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2215 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [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ä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2218 | pitch_tiles = pitch / tile_height; |
| 2219 | swap(tile_width, tile_height); |
| 2220 | } else { |
| 2221 | pitch_tiles = pitch / (tile_width * cpp); |
| 2222 | } |
| 2223 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2224 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2225 | tile_size, pitch_tiles, |
| 2226 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2227 | } else { |
| 2228 | old_offset += *y * pitch + *x * cpp; |
| 2229 | |
| 2230 | *y = (old_offset - new_offset) / pitch; |
| 2231 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2232 | } |
| 2233 | |
| 2234 | return new_offset; |
| 2235 | } |
| 2236 | |
| 2237 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2238 | * Adjust the tile offset by moving the difference into |
| 2239 | * the x/y offsets. |
| 2240 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2241 | static u32 intel_plane_adjust_aligned_offset(int *x, int *y, |
| 2242 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2243 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2244 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2245 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2246 | return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2247 | state->base.rotation, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2248 | state->color_plane[color_plane].stride, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2249 | old_offset, new_offset); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | /* |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2253 | * Computes the aligned offset to the base tile and adjusts |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2254 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2255 | * |
| 2256 | * In the 90/270 rotated case, x and y are assumed |
| 2257 | * to be already rotated to match the rotated GTT view, and |
| 2258 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2259 | * |
| 2260 | * This function is used when computing the derived information |
| 2261 | * under intel_framebuffer, so using any of that information |
| 2262 | * here is not allowed. Anything under drm_framebuffer can be |
| 2263 | * used. This is why the user has to pass in the pitch since it |
| 2264 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2265 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2266 | static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv, |
| 2267 | int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2268 | const struct drm_framebuffer *fb, |
| 2269 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2270 | unsigned int pitch, |
| 2271 | unsigned int rotation, |
| 2272 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2273 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2274 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2275 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2276 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2277 | if (alignment) |
| 2278 | alignment--; |
| 2279 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2280 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2281 | unsigned int tile_size, tile_width, tile_height; |
| 2282 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2283 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2284 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2285 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2286 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2287 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2288 | pitch_tiles = pitch / tile_height; |
| 2289 | swap(tile_width, tile_height); |
| 2290 | } else { |
| 2291 | pitch_tiles = pitch / (tile_width * cpp); |
| 2292 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2293 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2294 | tile_rows = *y / tile_height; |
| 2295 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2296 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2297 | tiles = *x / tile_width; |
| 2298 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2299 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2300 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2301 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2302 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2303 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2304 | tile_size, pitch_tiles, |
| 2305 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2306 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2307 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2308 | offset_aligned = offset & ~alignment; |
| 2309 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2310 | *y = (offset & alignment) / pitch; |
| 2311 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2312 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2313 | |
| 2314 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2315 | } |
| 2316 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2317 | static u32 intel_plane_compute_aligned_offset(int *x, int *y, |
| 2318 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2319 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2320 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2321 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2322 | 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] | 2323 | const struct drm_framebuffer *fb = state->base.fb; |
| 2324 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2325 | int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2326 | u32 alignment; |
| 2327 | |
| 2328 | if (intel_plane->id == PLANE_CURSOR) |
| 2329 | alignment = intel_cursor_alignment(dev_priv); |
| 2330 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2331 | alignment = intel_surf_alignment(fb, color_plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2332 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2333 | return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2334 | pitch, rotation, alignment); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2335 | } |
| 2336 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2337 | /* Convert the fb->offset[] into x/y offsets */ |
| 2338 | static int intel_fb_offset_to_xy(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2339 | const struct drm_framebuffer *fb, |
| 2340 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2341 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2342 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2343 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2344 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2345 | fb->offsets[color_plane] % intel_tile_size(dev_priv)) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2346 | return -EINVAL; |
| 2347 | |
| 2348 | *x = 0; |
| 2349 | *y = 0; |
| 2350 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2351 | intel_adjust_aligned_offset(x, y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2352 | fb, color_plane, DRM_MODE_ROTATE_0, |
| 2353 | fb->pitches[color_plane], |
| 2354 | fb->offsets[color_plane], 0); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2355 | |
| 2356 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2357 | } |
| 2358 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2359 | static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier) |
| 2360 | { |
| 2361 | switch (fb_modifier) { |
| 2362 | case I915_FORMAT_MOD_X_TILED: |
| 2363 | return I915_TILING_X; |
| 2364 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2365 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2366 | return I915_TILING_Y; |
| 2367 | default: |
| 2368 | return I915_TILING_NONE; |
| 2369 | } |
| 2370 | } |
| 2371 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2372 | /* |
| 2373 | * From the Sky Lake PRM: |
| 2374 | * "The Color Control Surface (CCS) contains the compression status of |
| 2375 | * the cache-line pairs. The compression state of the cache-line pair |
| 2376 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2377 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2378 | * cache-line-pairs. CCS is always Y tiled." |
| 2379 | * |
| 2380 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2381 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2382 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2383 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2384 | * main surface. |
| 2385 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2386 | static const struct drm_format_info ccs_formats[] = { |
| 2387 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2388 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2389 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2390 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2391 | }; |
| 2392 | |
| 2393 | static const struct drm_format_info * |
| 2394 | lookup_format_info(const struct drm_format_info formats[], |
| 2395 | int num_formats, u32 format) |
| 2396 | { |
| 2397 | int i; |
| 2398 | |
| 2399 | for (i = 0; i < num_formats; i++) { |
| 2400 | if (formats[i].format == format) |
| 2401 | return &formats[i]; |
| 2402 | } |
| 2403 | |
| 2404 | return NULL; |
| 2405 | } |
| 2406 | |
| 2407 | static const struct drm_format_info * |
| 2408 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2409 | { |
| 2410 | switch (cmd->modifier[0]) { |
| 2411 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2412 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2413 | return lookup_format_info(ccs_formats, |
| 2414 | ARRAY_SIZE(ccs_formats), |
| 2415 | cmd->pixel_format); |
| 2416 | default: |
| 2417 | return NULL; |
| 2418 | } |
| 2419 | } |
| 2420 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2421 | bool is_ccs_modifier(u64 modifier) |
| 2422 | { |
| 2423 | return modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2424 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 2425 | } |
| 2426 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2427 | static int |
| 2428 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2429 | struct drm_framebuffer *fb) |
| 2430 | { |
| 2431 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2432 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2433 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2434 | u32 gtt_offset_rotated = 0; |
| 2435 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2436 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2437 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2438 | |
| 2439 | for (i = 0; i < num_planes; i++) { |
| 2440 | unsigned int width, height; |
| 2441 | unsigned int cpp, size; |
| 2442 | u32 offset; |
| 2443 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2444 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2445 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2446 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2447 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2448 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2449 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2450 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2451 | if (ret) { |
| 2452 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2453 | i, fb->offsets[i]); |
| 2454 | return ret; |
| 2455 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2456 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2457 | if (is_ccs_modifier(fb->modifier) && i == 1) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2458 | int hsub = fb->format->hsub; |
| 2459 | int vsub = fb->format->vsub; |
| 2460 | int tile_width, tile_height; |
| 2461 | int main_x, main_y; |
| 2462 | int ccs_x, ccs_y; |
| 2463 | |
| 2464 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2465 | tile_width *= hsub; |
| 2466 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2467 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2468 | ccs_x = (x * hsub) % tile_width; |
| 2469 | ccs_y = (y * vsub) % tile_height; |
| 2470 | main_x = intel_fb->normal[0].x % tile_width; |
| 2471 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2472 | |
| 2473 | /* |
| 2474 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2475 | * x/y offsets must match between CCS and the main surface. |
| 2476 | */ |
| 2477 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2478 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2479 | main_x, main_y, |
| 2480 | ccs_x, ccs_y, |
| 2481 | intel_fb->normal[0].x, |
| 2482 | intel_fb->normal[0].y, |
| 2483 | x, y); |
| 2484 | return -EINVAL; |
| 2485 | } |
| 2486 | } |
| 2487 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2488 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2489 | * The fence (if used) is aligned to the start of the object |
| 2490 | * so having the framebuffer wrap around across the edge of the |
| 2491 | * fenced region doesn't really work. We have no API to configure |
| 2492 | * the fence start offset within the object (nor could we probably |
| 2493 | * on gen2/3). So it's just easier if we just require that the |
| 2494 | * fb layout agrees with the fence layout. We already check that the |
| 2495 | * fb stride matches the fence stride elsewhere. |
| 2496 | */ |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2497 | if (i == 0 && i915_gem_object_is_tiled(obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2498 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2499 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2500 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2501 | return -EINVAL; |
| 2502 | } |
| 2503 | |
| 2504 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2505 | * First pixel of the framebuffer from |
| 2506 | * the start of the normal gtt mapping. |
| 2507 | */ |
| 2508 | intel_fb->normal[i].x = x; |
| 2509 | intel_fb->normal[i].y = y; |
| 2510 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2511 | offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i, |
| 2512 | fb->pitches[i], |
| 2513 | DRM_MODE_ROTATE_0, |
| 2514 | tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2515 | offset /= tile_size; |
| 2516 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2517 | if (!is_surface_linear(fb->modifier, i)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2518 | unsigned int tile_width, tile_height; |
| 2519 | unsigned int pitch_tiles; |
| 2520 | struct drm_rect r; |
| 2521 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2522 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2523 | |
| 2524 | rot_info->plane[i].offset = offset; |
| 2525 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2526 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2527 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2528 | |
| 2529 | intel_fb->rotated[i].pitch = |
| 2530 | rot_info->plane[i].height * tile_height; |
| 2531 | |
| 2532 | /* how many tiles does this plane need */ |
| 2533 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2534 | /* |
| 2535 | * If the plane isn't horizontally tile aligned, |
| 2536 | * we need one more tile. |
| 2537 | */ |
| 2538 | if (x != 0) |
| 2539 | size++; |
| 2540 | |
| 2541 | /* rotate the x/y offsets to match the GTT view */ |
| 2542 | r.x1 = x; |
| 2543 | r.y1 = y; |
| 2544 | r.x2 = x + width; |
| 2545 | r.y2 = y + height; |
| 2546 | drm_rect_rotate(&r, |
| 2547 | rot_info->plane[i].width * tile_width, |
| 2548 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2549 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2550 | x = r.x1; |
| 2551 | y = r.y1; |
| 2552 | |
| 2553 | /* rotate the tile dimensions to match the GTT view */ |
| 2554 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2555 | swap(tile_width, tile_height); |
| 2556 | |
| 2557 | /* |
| 2558 | * We only keep the x/y offsets, so push all of the |
| 2559 | * gtt offset into the x/y offsets. |
| 2560 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2561 | intel_adjust_tile_offset(&x, &y, |
| 2562 | tile_width, tile_height, |
| 2563 | tile_size, pitch_tiles, |
| 2564 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2565 | |
| 2566 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2567 | |
| 2568 | /* |
| 2569 | * First pixel of the framebuffer from |
| 2570 | * the start of the rotated gtt mapping. |
| 2571 | */ |
| 2572 | intel_fb->rotated[i].x = x; |
| 2573 | intel_fb->rotated[i].y = y; |
| 2574 | } else { |
| 2575 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2576 | x * cpp, tile_size); |
| 2577 | } |
| 2578 | |
| 2579 | /* how many tiles in total needed in the bo */ |
| 2580 | max_size = max(max_size, offset + size); |
| 2581 | } |
| 2582 | |
Ville Syrjälä | 4e05047 | 2018-09-12 21:04:43 +0300 | [diff] [blame] | 2583 | if (mul_u32_u32(max_size, tile_size) > obj->base.size) { |
| 2584 | DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n", |
| 2585 | mul_u32_u32(max_size, tile_size), obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2586 | return -EINVAL; |
| 2587 | } |
| 2588 | |
| 2589 | return 0; |
| 2590 | } |
| 2591 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2592 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2593 | { |
| 2594 | switch (format) { |
| 2595 | case DISPPLANE_8BPP: |
| 2596 | return DRM_FORMAT_C8; |
| 2597 | case DISPPLANE_BGRX555: |
| 2598 | return DRM_FORMAT_XRGB1555; |
| 2599 | case DISPPLANE_BGRX565: |
| 2600 | return DRM_FORMAT_RGB565; |
| 2601 | default: |
| 2602 | case DISPPLANE_BGRX888: |
| 2603 | return DRM_FORMAT_XRGB8888; |
| 2604 | case DISPPLANE_RGBX888: |
| 2605 | return DRM_FORMAT_XBGR8888; |
| 2606 | case DISPPLANE_BGRX101010: |
| 2607 | return DRM_FORMAT_XRGB2101010; |
| 2608 | case DISPPLANE_RGBX101010: |
| 2609 | return DRM_FORMAT_XBGR2101010; |
| 2610 | } |
| 2611 | } |
| 2612 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2613 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2614 | { |
| 2615 | switch (format) { |
| 2616 | case PLANE_CTL_FORMAT_RGB_565: |
| 2617 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2618 | case PLANE_CTL_FORMAT_NV12: |
| 2619 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2620 | default: |
| 2621 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2622 | if (rgb_order) { |
| 2623 | if (alpha) |
| 2624 | return DRM_FORMAT_ABGR8888; |
| 2625 | else |
| 2626 | return DRM_FORMAT_XBGR8888; |
| 2627 | } else { |
| 2628 | if (alpha) |
| 2629 | return DRM_FORMAT_ARGB8888; |
| 2630 | else |
| 2631 | return DRM_FORMAT_XRGB8888; |
| 2632 | } |
| 2633 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2634 | if (rgb_order) |
| 2635 | return DRM_FORMAT_XBGR2101010; |
| 2636 | else |
| 2637 | return DRM_FORMAT_XRGB2101010; |
| 2638 | } |
| 2639 | } |
| 2640 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2641 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2642 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2643 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2644 | { |
| 2645 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2646 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2647 | struct drm_i915_gem_object *obj = NULL; |
| 2648 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2649 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2650 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2651 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2652 | PAGE_SIZE); |
| 2653 | |
| 2654 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2655 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2656 | if (plane_config->size == 0) |
| 2657 | return false; |
| 2658 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2659 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2660 | * important and we should probably use that space with FBC or other |
| 2661 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2662 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2663 | return false; |
| 2664 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2665 | switch (fb->modifier) { |
| 2666 | case DRM_FORMAT_MOD_LINEAR: |
| 2667 | case I915_FORMAT_MOD_X_TILED: |
| 2668 | case I915_FORMAT_MOD_Y_TILED: |
| 2669 | break; |
| 2670 | default: |
| 2671 | DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n", |
| 2672 | fb->modifier); |
| 2673 | return false; |
| 2674 | } |
| 2675 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2676 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2677 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2678 | base_aligned, |
| 2679 | base_aligned, |
| 2680 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2681 | mutex_unlock(&dev->struct_mutex); |
| 2682 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2683 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2684 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2685 | switch (plane_config->tiling) { |
| 2686 | case I915_TILING_NONE: |
| 2687 | break; |
| 2688 | case I915_TILING_X: |
| 2689 | case I915_TILING_Y: |
| 2690 | obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling; |
| 2691 | break; |
| 2692 | default: |
| 2693 | MISSING_CASE(plane_config->tiling); |
| 2694 | return false; |
| 2695 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2696 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2697 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2698 | mode_cmd.width = fb->width; |
| 2699 | mode_cmd.height = fb->height; |
| 2700 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2701 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2702 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2703 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2704 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2705 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2706 | goto out_unref_obj; |
| 2707 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2708 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2709 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2710 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2711 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2712 | |
| 2713 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2714 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2715 | return false; |
| 2716 | } |
| 2717 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2718 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2719 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2720 | struct intel_plane_state *plane_state, |
| 2721 | bool visible) |
| 2722 | { |
| 2723 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2724 | |
| 2725 | plane_state->base.visible = visible; |
| 2726 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2727 | if (visible) |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2728 | crtc_state->base.plane_mask |= drm_plane_mask(&plane->base); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2729 | else |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2730 | crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2731 | } |
| 2732 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2733 | static void fixup_active_planes(struct intel_crtc_state *crtc_state) |
| 2734 | { |
| 2735 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2736 | struct drm_plane *plane; |
| 2737 | |
| 2738 | /* |
| 2739 | * Active_planes aliases if multiple "primary" or cursor planes |
| 2740 | * have been used on the same (or wrong) pipe. plane_mask uses |
| 2741 | * unique ids, hence we can use that to reconstruct active_planes. |
| 2742 | */ |
| 2743 | crtc_state->active_planes = 0; |
| 2744 | |
| 2745 | drm_for_each_plane_mask(plane, &dev_priv->drm, |
| 2746 | crtc_state->base.plane_mask) |
| 2747 | crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); |
| 2748 | } |
| 2749 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2750 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2751 | struct intel_plane *plane) |
| 2752 | { |
| 2753 | struct intel_crtc_state *crtc_state = |
| 2754 | to_intel_crtc_state(crtc->base.state); |
| 2755 | struct intel_plane_state *plane_state = |
| 2756 | to_intel_plane_state(plane->base.state); |
| 2757 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 2758 | DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", |
| 2759 | plane->base.base.id, plane->base.name, |
| 2760 | crtc->base.base.id, crtc->base.name); |
| 2761 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2762 | intel_set_plane_visible(crtc_state, plane_state, false); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2763 | fixup_active_planes(crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2764 | |
| 2765 | if (plane->id == PLANE_PRIMARY) |
| 2766 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2767 | |
| 2768 | trace_intel_disable_plane(&plane->base, crtc); |
| 2769 | plane->disable_plane(plane, crtc); |
| 2770 | } |
| 2771 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2772 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2773 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2774 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2775 | { |
| 2776 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2777 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2778 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2779 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2780 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2781 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2782 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2783 | struct intel_plane_state *intel_state = |
| 2784 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2785 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2786 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2787 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2788 | return; |
| 2789 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2790 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2791 | fb = &plane_config->fb->base; |
| 2792 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2793 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2794 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2795 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2796 | |
| 2797 | /* |
| 2798 | * Failed to alloc the obj, check to see if we should share |
| 2799 | * an fb with another CRTC instead |
| 2800 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2801 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2802 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2803 | |
| 2804 | if (c == &intel_crtc->base) |
| 2805 | continue; |
| 2806 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2807 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2808 | continue; |
| 2809 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2810 | state = to_intel_plane_state(c->primary->state); |
| 2811 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2812 | continue; |
| 2813 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2814 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2815 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2816 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2817 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2818 | } |
| 2819 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2820 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2821 | /* |
| 2822 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2823 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2824 | * which will lead to problems later if we don't fix it up. The |
| 2825 | * simplest solution is to just disable the primary plane now and |
| 2826 | * pretend the BIOS never had it enabled. |
| 2827 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2828 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2829 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2830 | return; |
| 2831 | |
| 2832 | valid_fb: |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2833 | intel_fill_fb_ggtt_view(&intel_state->view, fb, |
| 2834 | intel_state->base.rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2835 | intel_state->color_plane[0].stride = |
| 2836 | intel_fb_pitch(fb, 0, intel_state->base.rotation); |
| 2837 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2838 | mutex_lock(&dev->struct_mutex); |
| 2839 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2840 | intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2841 | &intel_state->view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2842 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2843 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2844 | mutex_unlock(&dev->struct_mutex); |
| 2845 | if (IS_ERR(intel_state->vma)) { |
| 2846 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2847 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2848 | |
| 2849 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2850 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2851 | return; |
| 2852 | } |
| 2853 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2854 | obj = intel_fb_obj(fb); |
| 2855 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2856 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2857 | plane_state->src_x = 0; |
| 2858 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2859 | plane_state->src_w = fb->width << 16; |
| 2860 | plane_state->src_h = fb->height << 16; |
| 2861 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2862 | plane_state->crtc_x = 0; |
| 2863 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2864 | plane_state->crtc_w = fb->width; |
| 2865 | plane_state->crtc_h = fb->height; |
| 2866 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2867 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2868 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2869 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2870 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2871 | dev_priv->preserve_bios_swizzle = true; |
| 2872 | |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 2873 | plane_state->fb = fb; |
| 2874 | plane_state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2875 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2876 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2877 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2878 | } |
| 2879 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2880 | static int skl_max_plane_width(const struct drm_framebuffer *fb, |
| 2881 | int color_plane, |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2882 | unsigned int rotation) |
| 2883 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2884 | int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2885 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2886 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2887 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2888 | case I915_FORMAT_MOD_X_TILED: |
| 2889 | switch (cpp) { |
| 2890 | case 8: |
| 2891 | return 4096; |
| 2892 | case 4: |
| 2893 | case 2: |
| 2894 | case 1: |
| 2895 | return 8192; |
| 2896 | default: |
| 2897 | MISSING_CASE(cpp); |
| 2898 | break; |
| 2899 | } |
| 2900 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2901 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2902 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2903 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2904 | case I915_FORMAT_MOD_Y_TILED: |
| 2905 | case I915_FORMAT_MOD_Yf_TILED: |
| 2906 | switch (cpp) { |
| 2907 | case 8: |
| 2908 | return 2048; |
| 2909 | case 4: |
| 2910 | return 4096; |
| 2911 | case 2: |
| 2912 | case 1: |
| 2913 | return 8192; |
| 2914 | default: |
| 2915 | MISSING_CASE(cpp); |
| 2916 | break; |
| 2917 | } |
| 2918 | break; |
| 2919 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2920 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | return 2048; |
| 2924 | } |
| 2925 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2926 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2927 | int main_x, int main_y, u32 main_offset) |
| 2928 | { |
| 2929 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2930 | int hsub = fb->format->hsub; |
| 2931 | int vsub = fb->format->vsub; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2932 | int aux_x = plane_state->color_plane[1].x; |
| 2933 | int aux_y = plane_state->color_plane[1].y; |
| 2934 | u32 aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2935 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2936 | |
| 2937 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2938 | int x, y; |
| 2939 | |
| 2940 | if (aux_x == main_x && aux_y == main_y) |
| 2941 | break; |
| 2942 | |
| 2943 | if (aux_offset == 0) |
| 2944 | break; |
| 2945 | |
| 2946 | x = aux_x / hsub; |
| 2947 | y = aux_y / vsub; |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2948 | aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1, |
| 2949 | aux_offset, aux_offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2950 | aux_x = x * hsub + aux_x % hsub; |
| 2951 | aux_y = y * vsub + aux_y % vsub; |
| 2952 | } |
| 2953 | |
| 2954 | if (aux_x != main_x || aux_y != main_y) |
| 2955 | return false; |
| 2956 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2957 | plane_state->color_plane[1].offset = aux_offset; |
| 2958 | plane_state->color_plane[1].x = aux_x; |
| 2959 | plane_state->color_plane[1].y = aux_y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2960 | |
| 2961 | return true; |
| 2962 | } |
| 2963 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 2964 | static int skl_check_main_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2965 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2966 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2967 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2968 | int x = plane_state->base.src.x1 >> 16; |
| 2969 | int y = plane_state->base.src.y1 >> 16; |
| 2970 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 2971 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2972 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 2973 | int max_height = 4096; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2974 | u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2975 | |
| 2976 | if (w > max_width || h > max_height) { |
| 2977 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 2978 | w, h, max_width, max_height); |
| 2979 | return -EINVAL; |
| 2980 | } |
| 2981 | |
| 2982 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2983 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2984 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2985 | |
| 2986 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2987 | * AUX surface offset is specified as the distance from the |
| 2988 | * main surface offset, and it must be non-negative. Make |
| 2989 | * sure that is what we will get. |
| 2990 | */ |
| 2991 | if (offset > aux_offset) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2992 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 2993 | offset, aux_offset & ~(alignment - 1)); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2994 | |
| 2995 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2996 | * When using an X-tiled surface, the plane blows up |
| 2997 | * if the x offset + width exceed the stride. |
| 2998 | * |
| 2999 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 3000 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3001 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3002 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3003 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3004 | while ((x + w) * cpp > plane_state->color_plane[0].stride) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3005 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3006 | 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] | 3007 | return -EINVAL; |
| 3008 | } |
| 3009 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3010 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3011 | offset, offset - alignment); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3012 | } |
| 3013 | } |
| 3014 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3015 | /* |
| 3016 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3017 | * they match with the main surface x/y offsets. |
| 3018 | */ |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3019 | if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3020 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3021 | if (offset == 0) |
| 3022 | break; |
| 3023 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3024 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3025 | offset, offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3028 | if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3029 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3030 | return -EINVAL; |
| 3031 | } |
| 3032 | } |
| 3033 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3034 | plane_state->color_plane[0].offset = offset; |
| 3035 | plane_state->color_plane[0].x = x; |
| 3036 | plane_state->color_plane[0].y = y; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3037 | |
| 3038 | return 0; |
| 3039 | } |
| 3040 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3041 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3042 | { |
| 3043 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3044 | unsigned int rotation = plane_state->base.rotation; |
| 3045 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3046 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3047 | int x = plane_state->base.src.x1 >> 17; |
| 3048 | int y = plane_state->base.src.y1 >> 17; |
| 3049 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3050 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3051 | u32 offset; |
| 3052 | |
| 3053 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3054 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3055 | |
| 3056 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3057 | if (w > max_width || h > max_height) { |
| 3058 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3059 | w, h, max_width, max_height); |
| 3060 | return -EINVAL; |
| 3061 | } |
| 3062 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3063 | plane_state->color_plane[1].offset = offset; |
| 3064 | plane_state->color_plane[1].x = x; |
| 3065 | plane_state->color_plane[1].y = y; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3066 | |
| 3067 | return 0; |
| 3068 | } |
| 3069 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3070 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3071 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3072 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3073 | int src_x = plane_state->base.src.x1 >> 16; |
| 3074 | int src_y = plane_state->base.src.y1 >> 16; |
| 3075 | int hsub = fb->format->hsub; |
| 3076 | int vsub = fb->format->vsub; |
| 3077 | int x = src_x / hsub; |
| 3078 | int y = src_y / vsub; |
| 3079 | u32 offset; |
| 3080 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3081 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3082 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3083 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3084 | plane_state->color_plane[1].offset = offset; |
| 3085 | plane_state->color_plane[1].x = x * hsub + src_x % hsub; |
| 3086 | plane_state->color_plane[1].y = y * vsub + src_y % vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3087 | |
| 3088 | return 0; |
| 3089 | } |
| 3090 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3091 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3092 | { |
| 3093 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3094 | unsigned int rotation = plane_state->base.rotation; |
| 3095 | int ret; |
| 3096 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3097 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3098 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3099 | plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation); |
| 3100 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3101 | ret = intel_plane_check_stride(plane_state); |
| 3102 | if (ret) |
| 3103 | return ret; |
| 3104 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3105 | if (!plane_state->base.visible) |
| 3106 | return 0; |
| 3107 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3108 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3109 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3110 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3111 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3112 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3113 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3114 | /* |
| 3115 | * Handle the AUX surface first since |
| 3116 | * the main surface setup depends on it. |
| 3117 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3118 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3119 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3120 | if (ret) |
| 3121 | return ret; |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3122 | } else if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3123 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3124 | if (ret) |
| 3125 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3126 | } else { |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3127 | plane_state->color_plane[1].offset = ~0xfff; |
| 3128 | plane_state->color_plane[1].x = 0; |
| 3129 | plane_state->color_plane[1].y = 0; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3130 | } |
| 3131 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3132 | ret = skl_check_main_surface(plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3133 | if (ret) |
| 3134 | return ret; |
| 3135 | |
| 3136 | return 0; |
| 3137 | } |
| 3138 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3139 | unsigned int |
| 3140 | i9xx_plane_max_stride(struct intel_plane *plane, |
| 3141 | u32 pixel_format, u64 modifier, |
| 3142 | unsigned int rotation) |
| 3143 | { |
| 3144 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3145 | |
| 3146 | if (!HAS_GMCH_DISPLAY(dev_priv)) { |
| 3147 | return 32*1024; |
| 3148 | } else if (INTEL_GEN(dev_priv) >= 4) { |
| 3149 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3150 | return 16*1024; |
| 3151 | else |
| 3152 | return 32*1024; |
| 3153 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 3154 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3155 | return 8*1024; |
| 3156 | else |
| 3157 | return 16*1024; |
| 3158 | } else { |
| 3159 | if (plane->i9xx_plane == PLANE_C) |
| 3160 | return 4*1024; |
| 3161 | else |
| 3162 | return 8*1024; |
| 3163 | } |
| 3164 | } |
| 3165 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3166 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3167 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3168 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3169 | struct drm_i915_private *dev_priv = |
| 3170 | to_i915(plane_state->base.plane->dev); |
| 3171 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3172 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3173 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3174 | u32 dspcntr; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3175 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3176 | dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3177 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3178 | if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) || |
| 3179 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3180 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3181 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3182 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 3183 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3184 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3185 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3186 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3187 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3188 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3189 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3190 | dspcntr |= DISPPLANE_8BPP; |
| 3191 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3192 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3193 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3194 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3195 | case DRM_FORMAT_RGB565: |
| 3196 | dspcntr |= DISPPLANE_BGRX565; |
| 3197 | break; |
| 3198 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3199 | dspcntr |= DISPPLANE_BGRX888; |
| 3200 | break; |
| 3201 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3202 | dspcntr |= DISPPLANE_RGBX888; |
| 3203 | break; |
| 3204 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3205 | dspcntr |= DISPPLANE_BGRX101010; |
| 3206 | break; |
| 3207 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3208 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3209 | break; |
| 3210 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3211 | MISSING_CASE(fb->format->format); |
| 3212 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3213 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3214 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3215 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3216 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3217 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3218 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3219 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3220 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3221 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3222 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3223 | dspcntr |= DISPPLANE_MIRROR; |
| 3224 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3225 | return dspcntr; |
| 3226 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3227 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3228 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3229 | { |
| 3230 | struct drm_i915_private *dev_priv = |
| 3231 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3232 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3233 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3234 | int src_x = plane_state->base.src.x1 >> 16; |
| 3235 | int src_y = plane_state->base.src.y1 >> 16; |
| 3236 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3237 | int ret; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3238 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3239 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3240 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3241 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3242 | ret = intel_plane_check_stride(plane_state); |
| 3243 | if (ret) |
| 3244 | return ret; |
| 3245 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3246 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3247 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3248 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3249 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 3250 | plane_state, 0); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3251 | else |
| 3252 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3253 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3254 | /* HSW/BDW do this automagically in hardware */ |
| 3255 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3256 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3257 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3258 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3259 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3260 | src_x += src_w - 1; |
| 3261 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3262 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3263 | src_x += src_w - 1; |
| 3264 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3265 | } |
| 3266 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3267 | plane_state->color_plane[0].offset = offset; |
| 3268 | plane_state->color_plane[0].x = src_x; |
| 3269 | plane_state->color_plane[0].y = src_y; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3270 | |
| 3271 | return 0; |
| 3272 | } |
| 3273 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3274 | static int |
| 3275 | i9xx_plane_check(struct intel_crtc_state *crtc_state, |
| 3276 | struct intel_plane_state *plane_state) |
| 3277 | { |
| 3278 | int ret; |
| 3279 | |
Ville Syrjälä | 25721f8 | 2018-09-07 18:24:12 +0300 | [diff] [blame] | 3280 | ret = chv_plane_check_rotation(plane_state); |
| 3281 | if (ret) |
| 3282 | return ret; |
| 3283 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3284 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 3285 | &crtc_state->base, |
| 3286 | DRM_PLANE_HELPER_NO_SCALING, |
| 3287 | DRM_PLANE_HELPER_NO_SCALING, |
| 3288 | false, true); |
| 3289 | if (ret) |
| 3290 | return ret; |
| 3291 | |
| 3292 | if (!plane_state->base.visible) |
| 3293 | return 0; |
| 3294 | |
| 3295 | ret = intel_plane_check_src_coordinates(plane_state); |
| 3296 | if (ret) |
| 3297 | return ret; |
| 3298 | |
| 3299 | ret = i9xx_check_plane_surface(plane_state); |
| 3300 | if (ret) |
| 3301 | return ret; |
| 3302 | |
| 3303 | plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state); |
| 3304 | |
| 3305 | return 0; |
| 3306 | } |
| 3307 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3308 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3309 | const struct intel_crtc_state *crtc_state, |
| 3310 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3311 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3312 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3313 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3314 | u32 linear_offset; |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 3315 | u32 dspcntr = plane_state->ctl; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3316 | i915_reg_t reg = DSPCNTR(i9xx_plane); |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3317 | int x = plane_state->color_plane[0].x; |
| 3318 | int y = plane_state->color_plane[0].y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3319 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3320 | u32 dspaddr_offset; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3321 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3322 | 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] | 3323 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3324 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3325 | dspaddr_offset = plane_state->color_plane[0].offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3326 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3327 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3328 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3329 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3330 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3331 | if (INTEL_GEN(dev_priv) < 4) { |
| 3332 | /* pipesrc and dspsize control the size that is scaled from, |
| 3333 | * which should always be the user's requested size. |
| 3334 | */ |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3335 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3336 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3337 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3338 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
| 3339 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
| 3340 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3341 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3342 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3343 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
| 3344 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3345 | } |
| 3346 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3347 | I915_WRITE_FW(reg, dspcntr); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3348 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3349 | I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3350 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3351 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3352 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3353 | dspaddr_offset); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3354 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3355 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3356 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3357 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3358 | dspaddr_offset); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3359 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3360 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3361 | } else { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3362 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3363 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3364 | dspaddr_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3365 | } |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3366 | POSTING_READ_FW(reg); |
| 3367 | |
| 3368 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3371 | static void i9xx_disable_plane(struct intel_plane *plane, |
| 3372 | struct intel_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3373 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3374 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3375 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3376 | unsigned long irqflags; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3377 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3378 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3379 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3380 | I915_WRITE_FW(DSPCNTR(i9xx_plane), 0); |
| 3381 | if (INTEL_GEN(dev_priv) >= 4) |
| 3382 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3383 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3384 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
| 3385 | POSTING_READ_FW(DSPCNTR(i9xx_plane)); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3386 | |
| 3387 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3388 | } |
| 3389 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3390 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane, |
| 3391 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3392 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3393 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3394 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3395 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3396 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3397 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3398 | |
| 3399 | /* |
| 3400 | * Not 100% correct for planes that can move between pipes, |
| 3401 | * but that's only the case for gen2-4 which don't have any |
| 3402 | * display power wells. |
| 3403 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3404 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3405 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 3406 | return false; |
| 3407 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3408 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 3409 | |
| 3410 | ret = val & DISPLAY_PLANE_ENABLE; |
| 3411 | |
| 3412 | if (INTEL_GEN(dev_priv) >= 5) |
| 3413 | *pipe = plane->pipe; |
| 3414 | else |
| 3415 | *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 3416 | DISPPLANE_SEL_PIPE_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3417 | |
| 3418 | intel_display_power_put(dev_priv, power_domain); |
| 3419 | |
| 3420 | return ret; |
| 3421 | } |
| 3422 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3423 | static u32 |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3424 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3425 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3426 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3427 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3428 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3429 | return intel_tile_width_bytes(fb, color_plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3432 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3433 | { |
| 3434 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3435 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3436 | |
| 3437 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3438 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3439 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3440 | } |
| 3441 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3442 | /* |
| 3443 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3444 | */ |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3445 | static void skl_detach_scalers(const struct intel_crtc_state *crtc_state) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3446 | { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3447 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3448 | const struct intel_crtc_scaler_state *scaler_state = |
| 3449 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3450 | int i; |
| 3451 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3452 | /* loop through and disable scalers that aren't in use */ |
| 3453 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3454 | if (!scaler_state->scalers[i].in_use) |
| 3455 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3456 | } |
| 3457 | } |
| 3458 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3459 | u32 skl_plane_stride(const struct intel_plane_state *plane_state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3460 | int color_plane) |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3461 | { |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3462 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3463 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3464 | u32 stride = plane_state->color_plane[color_plane].stride; |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3465 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3466 | if (color_plane >= fb->format->num_planes) |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3467 | return 0; |
| 3468 | |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3469 | /* |
| 3470 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3471 | * linear buffers or in number of tiles for tiled buffers. |
| 3472 | */ |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3473 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3474 | stride /= intel_tile_height(fb, color_plane); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3475 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3476 | stride /= intel_fb_stride_alignment(fb, color_plane); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3477 | |
| 3478 | return stride; |
| 3479 | } |
| 3480 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3481 | static u32 skl_plane_ctl_format(uint32_t pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3482 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3483 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3484 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3485 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3486 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3487 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3488 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3489 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3490 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3491 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3492 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3493 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3494 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3495 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3496 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3497 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3498 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3499 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3500 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3501 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3502 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3503 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3504 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3505 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3506 | case DRM_FORMAT_NV12: |
| 3507 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3508 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3509 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3510 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3511 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3512 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3515 | static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state) |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3516 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3517 | if (!plane_state->base.fb->format->has_alpha) |
| 3518 | return PLANE_CTL_ALPHA_DISABLE; |
| 3519 | |
| 3520 | switch (plane_state->base.pixel_blend_mode) { |
| 3521 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3522 | return PLANE_CTL_ALPHA_DISABLE; |
| 3523 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3524 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3525 | case DRM_MODE_BLEND_COVERAGE: |
| 3526 | return PLANE_CTL_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3527 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3528 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3529 | return PLANE_CTL_ALPHA_DISABLE; |
| 3530 | } |
| 3531 | } |
| 3532 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3533 | static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state) |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3534 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3535 | if (!plane_state->base.fb->format->has_alpha) |
| 3536 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3537 | |
| 3538 | switch (plane_state->base.pixel_blend_mode) { |
| 3539 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3540 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3541 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3542 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3543 | case DRM_MODE_BLEND_COVERAGE: |
| 3544 | return PLANE_COLOR_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3545 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3546 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3547 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3548 | } |
| 3549 | } |
| 3550 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3551 | static u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3552 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3553 | switch (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3554 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3555 | break; |
| 3556 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3557 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3558 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3559 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3560 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3561 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3562 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3563 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3564 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3565 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3566 | default: |
| 3567 | MISSING_CASE(fb_modifier); |
| 3568 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3569 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3570 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3573 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3574 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3575 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3576 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3577 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3578 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3579 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3580 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3581 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3582 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3583 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3584 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3585 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3586 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3587 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3588 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3589 | MISSING_CASE(rotate); |
| 3590 | } |
| 3591 | |
| 3592 | return 0; |
| 3593 | } |
| 3594 | |
| 3595 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3596 | { |
| 3597 | switch (reflect) { |
| 3598 | case 0: |
| 3599 | break; |
| 3600 | case DRM_MODE_REFLECT_X: |
| 3601 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3602 | case DRM_MODE_REFLECT_Y: |
| 3603 | default: |
| 3604 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3607 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3610 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3611 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3612 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3613 | struct drm_i915_private *dev_priv = |
| 3614 | to_i915(plane_state->base.plane->dev); |
| 3615 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3616 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3617 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3618 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3619 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3620 | plane_ctl = PLANE_CTL_ENABLE; |
| 3621 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3622 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3623 | plane_ctl |= skl_plane_ctl_alpha(plane_state); |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3624 | plane_ctl |= |
| 3625 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3626 | PLANE_CTL_PIPE_CSC_ENABLE | |
| 3627 | PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3628 | |
| 3629 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3630 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3631 | |
| 3632 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3633 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3634 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3635 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3636 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3637 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3638 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3639 | |
| 3640 | if (INTEL_GEN(dev_priv) >= 10) |
| 3641 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3642 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3643 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3644 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3645 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3646 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3647 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3648 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3649 | return plane_ctl; |
| 3650 | } |
| 3651 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3652 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3653 | const struct intel_plane_state *plane_state) |
| 3654 | { |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3655 | struct drm_i915_private *dev_priv = |
| 3656 | to_i915(plane_state->base.plane->dev); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3657 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame^] | 3658 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3659 | u32 plane_color_ctl = 0; |
| 3660 | |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3661 | if (INTEL_GEN(dev_priv) < 11) { |
| 3662 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3663 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
| 3664 | } |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3665 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3666 | plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3667 | |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame^] | 3668 | if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) { |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3669 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3670 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3671 | else |
| 3672 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3673 | |
| 3674 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3675 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame^] | 3676 | } else if (fb->format->is_yuv) { |
| 3677 | plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3678 | } |
Ville Syrjälä | 012d79e | 2018-05-21 21:56:12 +0300 | [diff] [blame] | 3679 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3680 | return plane_color_ctl; |
| 3681 | } |
| 3682 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3683 | static int |
| 3684 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3685 | struct drm_atomic_state *state, |
| 3686 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3687 | { |
| 3688 | struct drm_crtc_state *crtc_state; |
| 3689 | struct drm_crtc *crtc; |
| 3690 | int i, ret; |
| 3691 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3692 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3693 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3694 | |
| 3695 | if (!state) |
| 3696 | return 0; |
| 3697 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3698 | /* |
| 3699 | * We've duplicated the state, pointers to the old state are invalid. |
| 3700 | * |
| 3701 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3702 | */ |
| 3703 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3704 | /* |
| 3705 | * Force recalculation even if we restore |
| 3706 | * current state. With fast modeset this may not result |
| 3707 | * in a modeset when the state is compatible. |
| 3708 | */ |
| 3709 | crtc_state->mode_changed = true; |
| 3710 | } |
| 3711 | |
| 3712 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3713 | if (!HAS_GMCH_DISPLAY(to_i915(dev))) |
| 3714 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3715 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3716 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3717 | |
| 3718 | WARN_ON(ret == -EDEADLK); |
| 3719 | return ret; |
| 3720 | } |
| 3721 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3722 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3723 | { |
Ville Syrjälä | ae98104 | 2016-08-05 23:28:30 +0300 | [diff] [blame] | 3724 | return intel_has_gpu_reset(dev_priv) && |
| 3725 | INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3726 | } |
| 3727 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3728 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3729 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3730 | struct drm_device *dev = &dev_priv->drm; |
| 3731 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3732 | struct drm_atomic_state *state; |
| 3733 | int ret; |
| 3734 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3735 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3736 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3737 | !gpu_reset_clobbers_display(dev_priv)) |
| 3738 | return; |
| 3739 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3740 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3741 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3742 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3743 | |
| 3744 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3745 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3746 | i915_gem_set_wedged(dev_priv); |
| 3747 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3748 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3749 | /* |
| 3750 | * Need mode_config.mutex so that we don't |
| 3751 | * trample ongoing ->detect() and whatnot. |
| 3752 | */ |
| 3753 | mutex_lock(&dev->mode_config.mutex); |
| 3754 | drm_modeset_acquire_init(ctx, 0); |
| 3755 | while (1) { |
| 3756 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3757 | if (ret != -EDEADLK) |
| 3758 | break; |
| 3759 | |
| 3760 | drm_modeset_backoff(ctx); |
| 3761 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3762 | /* |
| 3763 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3764 | * g33 docs say we should at least disable all the planes. |
| 3765 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3766 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3767 | if (IS_ERR(state)) { |
| 3768 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3769 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3770 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3774 | if (ret) { |
| 3775 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3776 | drm_atomic_state_put(state); |
| 3777 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | dev_priv->modeset_restore_state = state; |
| 3781 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3782 | } |
| 3783 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3784 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3785 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3786 | struct drm_device *dev = &dev_priv->drm; |
| 3787 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3788 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3789 | int ret; |
| 3790 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3791 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3792 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3793 | return; |
| 3794 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3795 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3796 | if (!state) |
| 3797 | goto unlock; |
| 3798 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3799 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3800 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3801 | /* for testing only restore the display */ |
| 3802 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3803 | if (ret) |
| 3804 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3805 | } else { |
| 3806 | /* |
| 3807 | * The display has been reset as well, |
| 3808 | * so need a full re-initialization. |
| 3809 | */ |
| 3810 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3811 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3812 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3813 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3814 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3815 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3816 | |
| 3817 | spin_lock_irq(&dev_priv->irq_lock); |
| 3818 | if (dev_priv->display.hpd_irq_setup) |
| 3819 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3820 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3821 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3822 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3823 | if (ret) |
| 3824 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3825 | |
| 3826 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3827 | } |
| 3828 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3829 | drm_atomic_state_put(state); |
| 3830 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3831 | drm_modeset_drop_locks(ctx); |
| 3832 | drm_modeset_acquire_fini(ctx); |
| 3833 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3834 | |
| 3835 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3836 | } |
| 3837 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3838 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3839 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3840 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3841 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3842 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3843 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3844 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3845 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3846 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3847 | /* |
| 3848 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3849 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3850 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3851 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3852 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3853 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3854 | */ |
| 3855 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3856 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3857 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3858 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3859 | |
| 3860 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3861 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3862 | skl_detach_scalers(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3863 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3864 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3865 | skylake_pfit_enable(new_crtc_state); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3866 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3867 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3868 | ironlake_pfit_enable(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3869 | else if (old_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3870 | ironlake_pfit_disable(old_crtc_state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3871 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3872 | } |
| 3873 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3874 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3875 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3876 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3877 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3878 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3879 | i915_reg_t reg; |
| 3880 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3881 | |
| 3882 | /* enable normal train */ |
| 3883 | reg = FDI_TX_CTL(pipe); |
| 3884 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3885 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3886 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3887 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3888 | } else { |
| 3889 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3890 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3891 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3892 | I915_WRITE(reg, temp); |
| 3893 | |
| 3894 | reg = FDI_RX_CTL(pipe); |
| 3895 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3896 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3897 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3898 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3899 | } else { |
| 3900 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3901 | temp |= FDI_LINK_TRAIN_NONE; |
| 3902 | } |
| 3903 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3904 | |
| 3905 | /* wait one idle pattern time */ |
| 3906 | POSTING_READ(reg); |
| 3907 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3908 | |
| 3909 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3910 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3911 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3912 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3913 | } |
| 3914 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3915 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3916 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 3917 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3918 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3919 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3920 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3921 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3922 | i915_reg_t reg; |
| 3923 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3924 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3925 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3926 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3927 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3928 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3929 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3930 | reg = FDI_RX_IMR(pipe); |
| 3931 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3932 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3933 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3934 | I915_WRITE(reg, temp); |
| 3935 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3936 | udelay(150); |
| 3937 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3938 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3939 | reg = FDI_TX_CTL(pipe); |
| 3940 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3941 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3942 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3943 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3944 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3945 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3946 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3947 | reg = FDI_RX_CTL(pipe); |
| 3948 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3949 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3950 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3951 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3952 | |
| 3953 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3954 | udelay(150); |
| 3955 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3956 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3957 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3958 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3959 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3960 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3961 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3962 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3963 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3964 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3965 | |
| 3966 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3967 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3968 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3969 | break; |
| 3970 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3971 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3972 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3973 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3974 | |
| 3975 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3976 | reg = FDI_TX_CTL(pipe); |
| 3977 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3978 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3979 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3980 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3981 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3982 | reg = FDI_RX_CTL(pipe); |
| 3983 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3984 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3985 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3986 | I915_WRITE(reg, temp); |
| 3987 | |
| 3988 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3989 | udelay(150); |
| 3990 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3991 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3992 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3993 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3994 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3995 | |
| 3996 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3997 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3998 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3999 | break; |
| 4000 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4001 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4002 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4003 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4004 | |
| 4005 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4006 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4007 | } |
| 4008 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4009 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4010 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 4011 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 4012 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 4013 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 4014 | }; |
| 4015 | |
| 4016 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4017 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
| 4018 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4019 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4020 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4021 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4022 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4023 | i915_reg_t reg; |
| 4024 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4025 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4026 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4027 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4028 | reg = FDI_RX_IMR(pipe); |
| 4029 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4030 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4031 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4032 | I915_WRITE(reg, temp); |
| 4033 | |
| 4034 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4035 | udelay(150); |
| 4036 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4037 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4038 | reg = FDI_TX_CTL(pipe); |
| 4039 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4040 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4041 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4042 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4043 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4044 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4045 | /* SNB-B */ |
| 4046 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4047 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4048 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4049 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4050 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4051 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4052 | reg = FDI_RX_CTL(pipe); |
| 4053 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4054 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4055 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4056 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4057 | } else { |
| 4058 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4059 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4060 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4061 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4062 | |
| 4063 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4064 | udelay(150); |
| 4065 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4066 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4067 | reg = FDI_TX_CTL(pipe); |
| 4068 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4069 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4070 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4071 | I915_WRITE(reg, temp); |
| 4072 | |
| 4073 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4074 | udelay(500); |
| 4075 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4076 | for (retry = 0; retry < 5; retry++) { |
| 4077 | reg = FDI_RX_IIR(pipe); |
| 4078 | temp = I915_READ(reg); |
| 4079 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4080 | if (temp & FDI_RX_BIT_LOCK) { |
| 4081 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4082 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4083 | break; |
| 4084 | } |
| 4085 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4086 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4087 | if (retry < 5) |
| 4088 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4089 | } |
| 4090 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4091 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4092 | |
| 4093 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4094 | reg = FDI_TX_CTL(pipe); |
| 4095 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4096 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4097 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4098 | if (IS_GEN6(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4099 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4100 | /* SNB-B */ |
| 4101 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4102 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4103 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4104 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4105 | reg = FDI_RX_CTL(pipe); |
| 4106 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4107 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4108 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4109 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4110 | } else { |
| 4111 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4112 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4113 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4114 | I915_WRITE(reg, temp); |
| 4115 | |
| 4116 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4117 | udelay(150); |
| 4118 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4119 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4120 | reg = FDI_TX_CTL(pipe); |
| 4121 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4122 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4123 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4124 | I915_WRITE(reg, temp); |
| 4125 | |
| 4126 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4127 | udelay(500); |
| 4128 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4129 | for (retry = 0; retry < 5; retry++) { |
| 4130 | reg = FDI_RX_IIR(pipe); |
| 4131 | temp = I915_READ(reg); |
| 4132 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4133 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4134 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4135 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4136 | break; |
| 4137 | } |
| 4138 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4139 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4140 | if (retry < 5) |
| 4141 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4142 | } |
| 4143 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4144 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4145 | |
| 4146 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4147 | } |
| 4148 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4149 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4150 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4151 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4152 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4153 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4154 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4155 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4156 | i915_reg_t reg; |
| 4157 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4158 | |
| 4159 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4160 | for train result */ |
| 4161 | reg = FDI_RX_IMR(pipe); |
| 4162 | temp = I915_READ(reg); |
| 4163 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4164 | temp &= ~FDI_RX_BIT_LOCK; |
| 4165 | I915_WRITE(reg, temp); |
| 4166 | |
| 4167 | POSTING_READ(reg); |
| 4168 | udelay(150); |
| 4169 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4170 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4171 | I915_READ(FDI_RX_IIR(pipe))); |
| 4172 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4173 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4174 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4175 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4176 | reg = FDI_TX_CTL(pipe); |
| 4177 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4178 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4179 | temp &= ~FDI_TX_ENABLE; |
| 4180 | I915_WRITE(reg, temp); |
| 4181 | |
| 4182 | reg = FDI_RX_CTL(pipe); |
| 4183 | temp = I915_READ(reg); |
| 4184 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4185 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4186 | temp &= ~FDI_RX_ENABLE; |
| 4187 | I915_WRITE(reg, temp); |
| 4188 | |
| 4189 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4190 | reg = FDI_TX_CTL(pipe); |
| 4191 | temp = I915_READ(reg); |
| 4192 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4193 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4194 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4195 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4196 | temp |= snb_b_fdi_train_param[j/2]; |
| 4197 | temp |= FDI_COMPOSITE_SYNC; |
| 4198 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4199 | |
| 4200 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4201 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4202 | |
| 4203 | reg = FDI_RX_CTL(pipe); |
| 4204 | temp = I915_READ(reg); |
| 4205 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4206 | temp |= FDI_COMPOSITE_SYNC; |
| 4207 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4208 | |
| 4209 | POSTING_READ(reg); |
| 4210 | udelay(1); /* should be 0.5us */ |
| 4211 | |
| 4212 | for (i = 0; i < 4; i++) { |
| 4213 | reg = FDI_RX_IIR(pipe); |
| 4214 | temp = I915_READ(reg); |
| 4215 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4216 | |
| 4217 | if (temp & FDI_RX_BIT_LOCK || |
| 4218 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4219 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4220 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4221 | i); |
| 4222 | break; |
| 4223 | } |
| 4224 | udelay(1); /* should be 0.5us */ |
| 4225 | } |
| 4226 | if (i == 4) { |
| 4227 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4228 | continue; |
| 4229 | } |
| 4230 | |
| 4231 | /* Train 2 */ |
| 4232 | reg = FDI_TX_CTL(pipe); |
| 4233 | temp = I915_READ(reg); |
| 4234 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4235 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4236 | I915_WRITE(reg, temp); |
| 4237 | |
| 4238 | reg = FDI_RX_CTL(pipe); |
| 4239 | temp = I915_READ(reg); |
| 4240 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4241 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4242 | I915_WRITE(reg, temp); |
| 4243 | |
| 4244 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4245 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4246 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4247 | for (i = 0; i < 4; i++) { |
| 4248 | reg = FDI_RX_IIR(pipe); |
| 4249 | temp = I915_READ(reg); |
| 4250 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4251 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4252 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4253 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4254 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4255 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4256 | i); |
| 4257 | goto train_done; |
| 4258 | } |
| 4259 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4260 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4261 | if (i == 4) |
| 4262 | 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] | 4263 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4264 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4265 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4266 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4267 | } |
| 4268 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4269 | static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4270 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4271 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4272 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4273 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4274 | i915_reg_t reg; |
| 4275 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4276 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4277 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4278 | reg = FDI_RX_CTL(pipe); |
| 4279 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4280 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4281 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4282 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4283 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4284 | |
| 4285 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4286 | udelay(200); |
| 4287 | |
| 4288 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4289 | temp = I915_READ(reg); |
| 4290 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4291 | |
| 4292 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4293 | udelay(200); |
| 4294 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4295 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4296 | reg = FDI_TX_CTL(pipe); |
| 4297 | temp = I915_READ(reg); |
| 4298 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4299 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4300 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4301 | POSTING_READ(reg); |
| 4302 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4303 | } |
| 4304 | } |
| 4305 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4306 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4307 | { |
| 4308 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4309 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4310 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4311 | i915_reg_t reg; |
| 4312 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4313 | |
| 4314 | /* Switch from PCDclk to Rawclk */ |
| 4315 | reg = FDI_RX_CTL(pipe); |
| 4316 | temp = I915_READ(reg); |
| 4317 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4318 | |
| 4319 | /* Disable CPU FDI TX PLL */ |
| 4320 | reg = FDI_TX_CTL(pipe); |
| 4321 | temp = I915_READ(reg); |
| 4322 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4323 | |
| 4324 | POSTING_READ(reg); |
| 4325 | udelay(100); |
| 4326 | |
| 4327 | reg = FDI_RX_CTL(pipe); |
| 4328 | temp = I915_READ(reg); |
| 4329 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4330 | |
| 4331 | /* Wait for the clocks to turn off. */ |
| 4332 | POSTING_READ(reg); |
| 4333 | udelay(100); |
| 4334 | } |
| 4335 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4336 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4337 | { |
| 4338 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4339 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4340 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4341 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4342 | i915_reg_t reg; |
| 4343 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4344 | |
| 4345 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4346 | reg = FDI_TX_CTL(pipe); |
| 4347 | temp = I915_READ(reg); |
| 4348 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4349 | POSTING_READ(reg); |
| 4350 | |
| 4351 | reg = FDI_RX_CTL(pipe); |
| 4352 | temp = I915_READ(reg); |
| 4353 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4354 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4355 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4356 | |
| 4357 | POSTING_READ(reg); |
| 4358 | udelay(100); |
| 4359 | |
| 4360 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4361 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4362 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4363 | |
| 4364 | /* still set train pattern 1 */ |
| 4365 | reg = FDI_TX_CTL(pipe); |
| 4366 | temp = I915_READ(reg); |
| 4367 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4368 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4369 | I915_WRITE(reg, temp); |
| 4370 | |
| 4371 | reg = FDI_RX_CTL(pipe); |
| 4372 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4373 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4374 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4375 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4376 | } else { |
| 4377 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4378 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4379 | } |
| 4380 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4381 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4382 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4383 | I915_WRITE(reg, temp); |
| 4384 | |
| 4385 | POSTING_READ(reg); |
| 4386 | udelay(100); |
| 4387 | } |
| 4388 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4389 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4390 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4391 | struct drm_crtc *crtc; |
| 4392 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4393 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4394 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4395 | struct drm_crtc_commit *commit; |
| 4396 | spin_lock(&crtc->commit_lock); |
| 4397 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4398 | struct drm_crtc_commit, commit_entry); |
| 4399 | cleanup_done = commit ? |
| 4400 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4401 | spin_unlock(&crtc->commit_lock); |
| 4402 | |
| 4403 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4404 | continue; |
| 4405 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4406 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4407 | |
| 4408 | return true; |
| 4409 | } |
| 4410 | |
| 4411 | return false; |
| 4412 | } |
| 4413 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4414 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4415 | { |
| 4416 | u32 temp; |
| 4417 | |
| 4418 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4419 | |
| 4420 | mutex_lock(&dev_priv->sb_lock); |
| 4421 | |
| 4422 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4423 | temp |= SBI_SSCCTL_DISABLE; |
| 4424 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4425 | |
| 4426 | mutex_unlock(&dev_priv->sb_lock); |
| 4427 | } |
| 4428 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4429 | /* Program iCLKIP clock to the desired frequency */ |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4430 | static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4431 | { |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4432 | 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] | 4433 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4434 | int clock = crtc_state->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4435 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4436 | u32 temp; |
| 4437 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4438 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4439 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4440 | /* The iCLK virtual clock root frequency is in MHz, |
| 4441 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4442 | * divisors, it is necessary to divide one by another, so we |
| 4443 | * convert the virtual clock precision to KHz here for higher |
| 4444 | * precision. |
| 4445 | */ |
| 4446 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4447 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4448 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4449 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4450 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4451 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4452 | clock << auxdiv); |
| 4453 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4454 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4455 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4456 | /* |
| 4457 | * Near 20MHz is a corner case which is |
| 4458 | * out of range for the 7-bit divisor |
| 4459 | */ |
| 4460 | if (divsel <= 0x7f) |
| 4461 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | /* This should not happen with any sane values */ |
| 4465 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4466 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4467 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4468 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4469 | |
| 4470 | 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] | 4471 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4472 | auxdiv, |
| 4473 | divsel, |
| 4474 | phasedir, |
| 4475 | phaseinc); |
| 4476 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4477 | mutex_lock(&dev_priv->sb_lock); |
| 4478 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4479 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4480 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4481 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4482 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4483 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4484 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4485 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4486 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4487 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4488 | |
| 4489 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4490 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4491 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4492 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4493 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4494 | |
| 4495 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4496 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4497 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4498 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4499 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4500 | mutex_unlock(&dev_priv->sb_lock); |
| 4501 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4502 | /* Wait for initialization time */ |
| 4503 | udelay(24); |
| 4504 | |
| 4505 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4506 | } |
| 4507 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4508 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4509 | { |
| 4510 | u32 divsel, phaseinc, auxdiv; |
| 4511 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4512 | u32 iclk_pi_range = 64; |
| 4513 | u32 desired_divisor; |
| 4514 | u32 temp; |
| 4515 | |
| 4516 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4517 | return 0; |
| 4518 | |
| 4519 | mutex_lock(&dev_priv->sb_lock); |
| 4520 | |
| 4521 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4522 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4523 | mutex_unlock(&dev_priv->sb_lock); |
| 4524 | return 0; |
| 4525 | } |
| 4526 | |
| 4527 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4528 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4529 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4530 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4531 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4532 | |
| 4533 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4534 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4535 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4536 | |
| 4537 | mutex_unlock(&dev_priv->sb_lock); |
| 4538 | |
| 4539 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4540 | |
| 4541 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4542 | desired_divisor << auxdiv); |
| 4543 | } |
| 4544 | |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4545 | static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state, |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4546 | enum pipe pch_transcoder) |
| 4547 | { |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4548 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4549 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4550 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4551 | |
| 4552 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4553 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4554 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4555 | I915_READ(HBLANK(cpu_transcoder))); |
| 4556 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4557 | I915_READ(HSYNC(cpu_transcoder))); |
| 4558 | |
| 4559 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4560 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4561 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4562 | I915_READ(VBLANK(cpu_transcoder))); |
| 4563 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4564 | I915_READ(VSYNC(cpu_transcoder))); |
| 4565 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4566 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4567 | } |
| 4568 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4569 | static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4570 | { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4571 | uint32_t temp; |
| 4572 | |
| 4573 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4574 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4575 | return; |
| 4576 | |
| 4577 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4578 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4579 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4580 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4581 | if (enable) |
| 4582 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4583 | |
| 4584 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4585 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4586 | POSTING_READ(SOUTH_CHICKEN1); |
| 4587 | } |
| 4588 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4589 | static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4590 | { |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4591 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4592 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4593 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4594 | switch (crtc->pipe) { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4595 | case PIPE_A: |
| 4596 | break; |
| 4597 | case PIPE_B: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4598 | if (crtc_state->fdi_lanes > 2) |
| 4599 | cpt_set_fdi_bc_bifurcation(dev_priv, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4600 | else |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4601 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4602 | |
| 4603 | break; |
| 4604 | case PIPE_C: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4605 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4606 | |
| 4607 | break; |
| 4608 | default: |
| 4609 | BUG(); |
| 4610 | } |
| 4611 | } |
| 4612 | |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4613 | /* |
| 4614 | * Finds the encoder associated with the given CRTC. This can only be |
| 4615 | * used when we know that the CRTC isn't feeding multiple encoders! |
| 4616 | */ |
| 4617 | static struct intel_encoder * |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4618 | intel_get_crtc_new_encoder(const struct intel_atomic_state *state, |
| 4619 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4620 | { |
| 4621 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4622 | const struct drm_connector_state *connector_state; |
| 4623 | const struct drm_connector *connector; |
| 4624 | struct intel_encoder *encoder = NULL; |
| 4625 | int num_encoders = 0; |
| 4626 | int i; |
| 4627 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4628 | for_each_new_connector_in_state(&state->base, connector, connector_state, i) { |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4629 | if (connector_state->crtc != &crtc->base) |
| 4630 | continue; |
| 4631 | |
| 4632 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 4633 | num_encoders++; |
| 4634 | } |
| 4635 | |
| 4636 | WARN(num_encoders != 1, "%d encoders for pipe %c\n", |
| 4637 | num_encoders, pipe_name(crtc->pipe)); |
| 4638 | |
| 4639 | return encoder; |
| 4640 | } |
| 4641 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4642 | /* |
| 4643 | * Enable PCH resources required for PCH ports: |
| 4644 | * - PCH PLLs |
| 4645 | * - FDI training & RX/TX |
| 4646 | * - update transcoder timings |
| 4647 | * - DP transcoding bits |
| 4648 | * - transcoder |
| 4649 | */ |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4650 | static void ironlake_pch_enable(const struct intel_atomic_state *state, |
| 4651 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4652 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4653 | 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] | 4654 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4655 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4656 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4657 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4658 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4659 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4660 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4661 | if (IS_IVYBRIDGE(dev_priv)) |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4662 | ivybridge_update_fdi_bc_bifurcation(crtc_state); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4663 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4664 | /* Write the TU size bits before fdi link training, so that error |
| 4665 | * detection works. */ |
| 4666 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4667 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4668 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4669 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4670 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4671 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4672 | /* We need to program the right clock selection before writing the pixel |
| 4673 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4674 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4675 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4676 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4677 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4678 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4679 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4680 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4681 | 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] | 4682 | temp |= sel; |
| 4683 | else |
| 4684 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4685 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4686 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4687 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4688 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4689 | * transcoder, and we actually should do this to not upset any PCH |
| 4690 | * transcoder that already use the clock when we share it. |
| 4691 | * |
| 4692 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4693 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4694 | * the right LVDS enable sequence. */ |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 4695 | intel_enable_shared_dpll(crtc_state); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4696 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4697 | /* set transcoder timing, panel must allow it */ |
| 4698 | assert_panel_unlocked(dev_priv, pipe); |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4699 | ironlake_pch_transcoder_set_timings(crtc_state, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4700 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4701 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4702 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4703 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4704 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4705 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4706 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4707 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4708 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4709 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4710 | enum port port; |
| 4711 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4712 | temp = I915_READ(reg); |
| 4713 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4714 | TRANS_DP_SYNC_MASK | |
| 4715 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4716 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4717 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4718 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4719 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4720 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4721 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4722 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4723 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4724 | port = intel_get_crtc_new_encoder(state, crtc_state)->port; |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4725 | WARN_ON(port < PORT_B || port > PORT_D); |
| 4726 | temp |= TRANS_DP_PORT_SEL(port); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4727 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4728 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4729 | } |
| 4730 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 4731 | ironlake_enable_pch_transcoder(crtc_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4734 | static void lpt_pch_enable(const struct intel_atomic_state *state, |
| 4735 | const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4736 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4737 | 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] | 4738 | 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] | 4739 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4740 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4741 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4742 | |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4743 | lpt_program_iclkip(crtc_state); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4744 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4745 | /* Set transcoder timing. */ |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4746 | ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4747 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4748 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4749 | } |
| 4750 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4751 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4752 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4753 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4754 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4755 | u32 temp; |
| 4756 | |
| 4757 | temp = I915_READ(dslreg); |
| 4758 | udelay(500); |
| 4759 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4760 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4761 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4762 | } |
| 4763 | } |
| 4764 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4765 | /* |
| 4766 | * The hardware phase 0.0 refers to the center of the pixel. |
| 4767 | * We want to start from the top/left edge which is phase |
| 4768 | * -0.5. That matches how the hardware calculates the scaling |
| 4769 | * factors (from top-left of the first pixel to bottom-right |
| 4770 | * of the last pixel, as opposed to the pixel centers). |
| 4771 | * |
| 4772 | * For 4:2:0 subsampled chroma planes we obviously have to |
| 4773 | * adjust that so that the chroma sample position lands in |
| 4774 | * the right spot. |
| 4775 | * |
| 4776 | * Note that for packed YCbCr 4:2:2 formats there is no way to |
| 4777 | * control chroma siting. The hardware simply replicates the |
| 4778 | * chroma samples for both of the luma samples, and thus we don't |
| 4779 | * actually get the expected MPEG2 chroma siting convention :( |
| 4780 | * The same behaviour is observed on pre-SKL platforms as well. |
| 4781 | */ |
| 4782 | u16 skl_scaler_calc_phase(int sub, bool chroma_cosited) |
| 4783 | { |
| 4784 | int phase = -0x8000; |
| 4785 | u16 trip = 0; |
| 4786 | |
| 4787 | if (chroma_cosited) |
| 4788 | phase += (sub - 1) * 0x8000 / sub; |
| 4789 | |
| 4790 | if (phase < 0) |
| 4791 | phase = 0x10000 + phase; |
| 4792 | else |
| 4793 | trip = PS_PHASE_TRIP; |
| 4794 | |
| 4795 | return ((phase >> 2) & PS_PHASE_MASK) | trip; |
| 4796 | } |
| 4797 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4798 | static int |
| 4799 | 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] | 4800 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4801 | int src_w, int src_h, int dst_w, int dst_h, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4802 | const struct drm_format_info *format, bool need_scaler) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4803 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4804 | struct intel_crtc_scaler_state *scaler_state = |
| 4805 | &crtc_state->scaler_state; |
| 4806 | struct intel_crtc *intel_crtc = |
| 4807 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4808 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4809 | const struct drm_display_mode *adjusted_mode = |
| 4810 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4811 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4812 | /* |
| 4813 | * Src coordinates are already rotated by 270 degrees for |
| 4814 | * the 90/270 degree plane rotation cases (to match the |
| 4815 | * GTT mapping), hence no need to account for rotation here. |
| 4816 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4817 | if (src_w != dst_w || src_h != dst_h) |
| 4818 | need_scaler = true; |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 4819 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4820 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4821 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 4822 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 4823 | * Once NV12 is enabled, handle it here while allocating scaler |
| 4824 | * for NV12. |
| 4825 | */ |
| 4826 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4827 | need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4828 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 4829 | return -EINVAL; |
| 4830 | } |
| 4831 | |
| 4832 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4833 | * if plane is being disabled or scaler is no more required or force detach |
| 4834 | * - free scaler binded to this plane/crtc |
| 4835 | * - in order to do this, update crtc->scaler_usage |
| 4836 | * |
| 4837 | * Here scaler state in crtc_state is set free so that |
| 4838 | * scaler can be assigned to other user. Actual register |
| 4839 | * update to free the scaler is done in plane/panel-fit programming. |
| 4840 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4841 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4842 | if (force_detach || !need_scaler) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4843 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4844 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4845 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4846 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4847 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4848 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4849 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4850 | scaler_state->scaler_users); |
| 4851 | *scaler_id = -1; |
| 4852 | } |
| 4853 | return 0; |
| 4854 | } |
| 4855 | |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4856 | if (format && format->format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 4857 | (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] | 4858 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 4859 | return -EINVAL; |
| 4860 | } |
| 4861 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4862 | /* range checks */ |
| 4863 | 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] | 4864 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4865 | (IS_GEN11(dev_priv) && |
| 4866 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 4867 | dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) || |
| 4868 | (!IS_GEN11(dev_priv) && |
| 4869 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4870 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4871 | 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] | 4872 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4873 | 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] | 4874 | return -EINVAL; |
| 4875 | } |
| 4876 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4877 | /* mark this plane as a scaler user in crtc_state */ |
| 4878 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4879 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4880 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4881 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4882 | scaler_state->scaler_users); |
| 4883 | |
| 4884 | return 0; |
| 4885 | } |
| 4886 | |
| 4887 | /** |
| 4888 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4889 | * |
| 4890 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4891 | * |
| 4892 | * Return |
| 4893 | * 0 - scaler_usage updated successfully |
| 4894 | * error - requested scaling cannot be supported or other error condition |
| 4895 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4896 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4897 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4898 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4899 | bool need_scaler = false; |
| 4900 | |
| 4901 | if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
| 4902 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4903 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4904 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4905 | &state->scaler_state.scaler_id, |
| 4906 | state->pipe_src_w, state->pipe_src_h, |
| 4907 | adjusted_mode->crtc_hdisplay, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4908 | adjusted_mode->crtc_vdisplay, NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4909 | } |
| 4910 | |
| 4911 | /** |
| 4912 | * 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] | 4913 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4914 | * @plane_state: atomic plane state to update |
| 4915 | * |
| 4916 | * Return |
| 4917 | * 0 - scaler_usage updated successfully |
| 4918 | * error - requested scaling cannot be supported or other error condition |
| 4919 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4920 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4921 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4922 | { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4923 | struct intel_plane *intel_plane = |
| 4924 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4925 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4926 | int ret; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4927 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4928 | bool need_scaler = false; |
| 4929 | |
| 4930 | /* Pre-gen11 and SDR planes always need a scaler for planar formats. */ |
| 4931 | if (!icl_is_hdr_plane(intel_plane) && |
| 4932 | fb && fb->format->format == DRM_FORMAT_NV12) |
| 4933 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4934 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4935 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4936 | drm_plane_index(&intel_plane->base), |
| 4937 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4938 | drm_rect_width(&plane_state->base.src) >> 16, |
| 4939 | drm_rect_height(&plane_state->base.src) >> 16, |
| 4940 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4941 | drm_rect_height(&plane_state->base.dst), |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4942 | fb ? fb->format : NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4943 | |
| 4944 | if (ret || plane_state->scaler_id < 0) |
| 4945 | return ret; |
| 4946 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4947 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 4948 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4949 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 4950 | intel_plane->base.base.id, |
| 4951 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4952 | return -EINVAL; |
| 4953 | } |
| 4954 | |
| 4955 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4956 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4957 | case DRM_FORMAT_RGB565: |
| 4958 | case DRM_FORMAT_XBGR8888: |
| 4959 | case DRM_FORMAT_XRGB8888: |
| 4960 | case DRM_FORMAT_ABGR8888: |
| 4961 | case DRM_FORMAT_ARGB8888: |
| 4962 | case DRM_FORMAT_XRGB2101010: |
| 4963 | case DRM_FORMAT_XBGR2101010: |
| 4964 | case DRM_FORMAT_YUYV: |
| 4965 | case DRM_FORMAT_YVYU: |
| 4966 | case DRM_FORMAT_UYVY: |
| 4967 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4968 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4969 | break; |
| 4970 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4971 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 4972 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4973 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4974 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4977 | return 0; |
| 4978 | } |
| 4979 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4980 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4981 | { |
| 4982 | int i; |
| 4983 | |
| 4984 | for (i = 0; i < crtc->num_scalers; i++) |
| 4985 | skl_detach_scaler(crtc, i); |
| 4986 | } |
| 4987 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4988 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4989 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4990 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4991 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4992 | enum pipe pipe = crtc->pipe; |
| 4993 | const struct intel_crtc_scaler_state *scaler_state = |
| 4994 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4995 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4996 | if (crtc_state->pch_pfit.enabled) { |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4997 | u16 uv_rgb_hphase, uv_rgb_vphase; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4998 | int id; |
| 4999 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5000 | if (WARN_ON(crtc_state->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5001 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5002 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5003 | uv_rgb_hphase = skl_scaler_calc_phase(1, false); |
| 5004 | uv_rgb_vphase = skl_scaler_calc_phase(1, false); |
| 5005 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5006 | id = scaler_state->scaler_id; |
| 5007 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 5008 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5009 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, id), |
| 5010 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase)); |
| 5011 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, id), |
| 5012 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase)); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5013 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos); |
| 5014 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5015 | } |
| 5016 | } |
| 5017 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5018 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5019 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5020 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5021 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5022 | int pipe = crtc->pipe; |
| 5023 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5024 | if (crtc_state->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5025 | /* Force use of hard-coded filter coefficients |
| 5026 | * as some pre-programmed values are broken, |
| 5027 | * e.g. x201. |
| 5028 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5029 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5030 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 5031 | PF_PIPE_SEL_IVB(pipe)); |
| 5032 | else |
| 5033 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5034 | I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos); |
| 5035 | I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 5036 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5037 | } |
| 5038 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5039 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5040 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5041 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 5042 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5043 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5044 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5045 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5046 | return; |
| 5047 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 5048 | /* |
| 5049 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 5050 | * This function is called from post_plane_update, which is run after |
| 5051 | * a vblank wait. |
| 5052 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5053 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 5054 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5055 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5056 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 5057 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 5058 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5059 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5060 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 5061 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5062 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 5063 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5064 | */ |
| 5065 | } else { |
| 5066 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 5067 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 5068 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5069 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5070 | * the HW state readout code will complain that the expected |
| 5071 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5072 | if (intel_wait_for_register(dev_priv, |
| 5073 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5074 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5075 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5076 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5077 | } |
| 5078 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5079 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5080 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5081 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5082 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5083 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5084 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5085 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5086 | return; |
| 5087 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5088 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5089 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5090 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5091 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5092 | /* |
| 5093 | * Wait for PCODE to finish disabling IPS. The BSpec specified |
| 5094 | * 42ms timeout value leads to occasional timeouts so use 100ms |
| 5095 | * instead. |
| 5096 | */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5097 | if (intel_wait_for_register(dev_priv, |
| 5098 | IPS_CTL, IPS_ENABLE, 0, |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5099 | 100)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5100 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5101 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5102 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5103 | POSTING_READ(IPS_CTL); |
| 5104 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5105 | |
| 5106 | /* 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] | 5107 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5108 | } |
| 5109 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5110 | 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] | 5111 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5112 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5113 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5114 | |
| 5115 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5116 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5117 | mutex_unlock(&dev->struct_mutex); |
| 5118 | } |
| 5119 | |
| 5120 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5121 | * has to recompute where to put it anyway. |
| 5122 | */ |
| 5123 | } |
| 5124 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5125 | /** |
| 5126 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5127 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5128 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5129 | * |
| 5130 | * Performs potentially sleeping operations that must be done after the primary |
| 5131 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5132 | * called due to an explicit primary plane update, or due to an implicit |
| 5133 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5134 | * completely hide the primary plane. |
| 5135 | */ |
| 5136 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5137 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5138 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5139 | { |
| 5140 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5141 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5142 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5143 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5144 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5145 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5146 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5147 | * So don't enable underrun reporting before at least some planes |
| 5148 | * are enabled. |
| 5149 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5150 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5151 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5152 | if (IS_GEN2(dev_priv)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5153 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5154 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5155 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5156 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5157 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5158 | } |
| 5159 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5160 | /* FIXME get rid of this and use pre_plane_update */ |
| 5161 | static void |
| 5162 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5163 | { |
| 5164 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5165 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5166 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5167 | int pipe = intel_crtc->pipe; |
| 5168 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5169 | /* |
| 5170 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5171 | * So disable underrun reporting before all the planes get disabled. |
| 5172 | */ |
| 5173 | if (IS_GEN2(dev_priv)) |
| 5174 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5175 | |
| 5176 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5177 | |
| 5178 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5179 | * Vblank time updates from the shadow to live plane control register |
| 5180 | * are blocked if the memory self-refresh mode is active at that |
| 5181 | * moment. So to make sure the plane gets truly disabled, disable |
| 5182 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5183 | * will be checked/applied by the HW only at the next frame start |
| 5184 | * event which is after the vblank start event, so we need to have a |
| 5185 | * wait-for-vblank between disabling the plane and the pipe. |
| 5186 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5187 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 5188 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5189 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5190 | } |
| 5191 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5192 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5193 | const struct intel_crtc_state *new_crtc_state) |
| 5194 | { |
| 5195 | if (!old_crtc_state->ips_enabled) |
| 5196 | return false; |
| 5197 | |
| 5198 | if (needs_modeset(&new_crtc_state->base)) |
| 5199 | return true; |
| 5200 | |
| 5201 | return !new_crtc_state->ips_enabled; |
| 5202 | } |
| 5203 | |
| 5204 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5205 | const struct intel_crtc_state *new_crtc_state) |
| 5206 | { |
| 5207 | if (!new_crtc_state->ips_enabled) |
| 5208 | return false; |
| 5209 | |
| 5210 | if (needs_modeset(&new_crtc_state->base)) |
| 5211 | return true; |
| 5212 | |
| 5213 | /* |
| 5214 | * We can't read out IPS on broadwell, assume the worst and |
| 5215 | * forcibly enable IPS on the first fastset. |
| 5216 | */ |
| 5217 | if (new_crtc_state->update_pipe && |
| 5218 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5219 | return true; |
| 5220 | |
| 5221 | return !old_crtc_state->ips_enabled; |
| 5222 | } |
| 5223 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5224 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5225 | const struct intel_crtc_state *crtc_state) |
| 5226 | { |
| 5227 | if (!crtc_state->nv12_planes) |
| 5228 | return false; |
| 5229 | |
Rodrigo Vivi | 1347d3c | 2018-10-31 09:28:45 -0700 | [diff] [blame] | 5230 | /* WA Display #0827: Gen9:all */ |
| 5231 | if (IS_GEN9(dev_priv) && !IS_GEMINILAKE(dev_priv)) |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5232 | return true; |
| 5233 | |
| 5234 | return false; |
| 5235 | } |
| 5236 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5237 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5238 | { |
| 5239 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5240 | struct drm_device *dev = crtc->base.dev; |
| 5241 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5242 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5243 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5244 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5245 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5246 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5247 | struct drm_plane_state *old_primary_state = |
| 5248 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5249 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5250 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5251 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5252 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5253 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5254 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5255 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5256 | hsw_enable_ips(pipe_config); |
| 5257 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5258 | if (old_primary_state) { |
| 5259 | struct drm_plane_state *new_primary_state = |
| 5260 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5261 | |
| 5262 | intel_fbc_post_update(crtc); |
| 5263 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5264 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5265 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5266 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5267 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5268 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5269 | |
| 5270 | /* Display WA 827 */ |
| 5271 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5272 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5273 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5274 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5275 | } |
| 5276 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5277 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5278 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5279 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5280 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5281 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5282 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5283 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5284 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5285 | struct drm_plane_state *old_primary_state = |
| 5286 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5287 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5288 | struct intel_atomic_state *old_intel_state = |
| 5289 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5290 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5291 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5292 | hsw_disable_ips(old_crtc_state); |
| 5293 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5294 | if (old_primary_state) { |
| 5295 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5296 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5297 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5298 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5299 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5300 | /* |
| 5301 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5302 | * So disable underrun reporting before all the planes get disabled. |
| 5303 | */ |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5304 | if (IS_GEN2(dev_priv) && old_primary_state->visible && |
| 5305 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5306 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5307 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5308 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5309 | /* Display WA 827 */ |
| 5310 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5311 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5312 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5313 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5314 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5315 | /* |
| 5316 | * Vblank time updates from the shadow to live plane control register |
| 5317 | * are blocked if the memory self-refresh mode is active at that |
| 5318 | * moment. So to make sure the plane gets truly disabled, disable |
| 5319 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5320 | * will be checked/applied by the HW only at the next frame start |
| 5321 | * event which is after the vblank start event, so we need to have a |
| 5322 | * wait-for-vblank between disabling the plane and the pipe. |
| 5323 | */ |
| 5324 | if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active && |
| 5325 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5326 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5327 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5328 | /* |
| 5329 | * IVB workaround: must disable low power watermarks for at least |
| 5330 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5331 | * when scaling is disabled. |
| 5332 | * |
| 5333 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5334 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 5335 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) && |
| 5336 | old_crtc_state->base.active) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5337 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5338 | |
| 5339 | /* |
| 5340 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5341 | * watermark programming here. |
| 5342 | */ |
| 5343 | if (needs_modeset(&pipe_config->base)) |
| 5344 | return; |
| 5345 | |
| 5346 | /* |
| 5347 | * For platforms that support atomic watermarks, program the |
| 5348 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5349 | * will be the intermediate values that are safe for both pre- and |
| 5350 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5351 | * to the final 'target' values and we'll do this again to get the |
| 5352 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5353 | * will be the final target values which will get automatically latched |
| 5354 | * at vblank time; no further programming will be necessary. |
| 5355 | * |
| 5356 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5357 | * we'll continue to update watermarks the old way, if flags tell |
| 5358 | * us to. |
| 5359 | */ |
| 5360 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5361 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5362 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5363 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5364 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5365 | } |
| 5366 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5367 | static void intel_crtc_disable_planes(struct intel_crtc *crtc, unsigned plane_mask) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5368 | { |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5369 | struct drm_device *dev = crtc->base.dev; |
| 5370 | struct intel_plane *plane; |
| 5371 | unsigned fb_bits = 0; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5372 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5373 | intel_crtc_dpms_overlay_disable(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5374 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5375 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 5376 | if (plane_mask & BIT(plane->id)) { |
| 5377 | plane->disable_plane(plane, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5378 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5379 | fb_bits |= plane->frontbuffer_bit; |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | intel_frontbuffer_flip(to_i915(dev), fb_bits); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5384 | } |
| 5385 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5386 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5387 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5388 | struct drm_atomic_state *old_state) |
| 5389 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5390 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5391 | struct drm_connector *conn; |
| 5392 | int i; |
| 5393 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5394 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5395 | struct intel_encoder *encoder = |
| 5396 | to_intel_encoder(conn_state->best_encoder); |
| 5397 | |
| 5398 | if (conn_state->crtc != crtc) |
| 5399 | continue; |
| 5400 | |
| 5401 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5402 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5407 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5408 | struct drm_atomic_state *old_state) |
| 5409 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5410 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5411 | struct drm_connector *conn; |
| 5412 | int i; |
| 5413 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5414 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5415 | struct intel_encoder *encoder = |
| 5416 | to_intel_encoder(conn_state->best_encoder); |
| 5417 | |
| 5418 | if (conn_state->crtc != crtc) |
| 5419 | continue; |
| 5420 | |
| 5421 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5422 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5423 | } |
| 5424 | } |
| 5425 | |
| 5426 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5427 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5428 | struct drm_atomic_state *old_state) |
| 5429 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5430 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5431 | struct drm_connector *conn; |
| 5432 | int i; |
| 5433 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5434 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5435 | struct intel_encoder *encoder = |
| 5436 | to_intel_encoder(conn_state->best_encoder); |
| 5437 | |
| 5438 | if (conn_state->crtc != crtc) |
| 5439 | continue; |
| 5440 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5441 | if (encoder->enable) |
| 5442 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5443 | intel_opregion_notify_encoder(encoder, true); |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5448 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5449 | struct drm_atomic_state *old_state) |
| 5450 | { |
| 5451 | struct drm_connector_state *old_conn_state; |
| 5452 | struct drm_connector *conn; |
| 5453 | int i; |
| 5454 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5455 | 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] | 5456 | struct intel_encoder *encoder = |
| 5457 | to_intel_encoder(old_conn_state->best_encoder); |
| 5458 | |
| 5459 | if (old_conn_state->crtc != crtc) |
| 5460 | continue; |
| 5461 | |
| 5462 | intel_opregion_notify_encoder(encoder, false); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5463 | if (encoder->disable) |
| 5464 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5469 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5470 | struct drm_atomic_state *old_state) |
| 5471 | { |
| 5472 | struct drm_connector_state *old_conn_state; |
| 5473 | struct drm_connector *conn; |
| 5474 | int i; |
| 5475 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5476 | 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] | 5477 | struct intel_encoder *encoder = |
| 5478 | to_intel_encoder(old_conn_state->best_encoder); |
| 5479 | |
| 5480 | if (old_conn_state->crtc != crtc) |
| 5481 | continue; |
| 5482 | |
| 5483 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5484 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5489 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5490 | struct drm_atomic_state *old_state) |
| 5491 | { |
| 5492 | struct drm_connector_state *old_conn_state; |
| 5493 | struct drm_connector *conn; |
| 5494 | int i; |
| 5495 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5496 | 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] | 5497 | struct intel_encoder *encoder = |
| 5498 | to_intel_encoder(old_conn_state->best_encoder); |
| 5499 | |
| 5500 | if (old_conn_state->crtc != crtc) |
| 5501 | continue; |
| 5502 | |
| 5503 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5504 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5505 | } |
| 5506 | } |
| 5507 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5508 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5509 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5510 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5511 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5512 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5513 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5514 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5515 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5516 | struct intel_atomic_state *old_intel_state = |
| 5517 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5518 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5519 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5520 | return; |
| 5521 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5522 | /* |
| 5523 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5524 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5525 | * |
| 5526 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5527 | * between eDP port A enable and vdd enable. Also PCH port |
| 5528 | * enable seems to result in the occasional CPU pipe underrun. |
| 5529 | * |
| 5530 | * Spurious PCH underruns also occur during PCH enabling. |
| 5531 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5532 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5533 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5534 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5535 | if (pipe_config->has_pch_encoder) |
| 5536 | intel_prepare_shared_dpll(pipe_config); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5537 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5538 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5539 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5540 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5541 | intel_set_pipe_timings(pipe_config); |
| 5542 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5543 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5544 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5545 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5546 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5547 | } |
| 5548 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5549 | ironlake_set_pipeconf(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5550 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5551 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5552 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5553 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5554 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5555 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5556 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5557 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5558 | * enabling. */ |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 5559 | ironlake_fdi_pll_enable(pipe_config); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5560 | } else { |
| 5561 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5562 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5563 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5564 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5565 | ironlake_pfit_enable(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5566 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5567 | /* |
| 5568 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5569 | * clocks enabled |
| 5570 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5571 | intel_color_load_luts(&pipe_config->base); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5572 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5573 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5574 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5575 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5576 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5577 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5578 | ironlake_pch_enable(old_intel_state, pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5579 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5580 | assert_vblank_disabled(crtc); |
| 5581 | drm_crtc_vblank_on(crtc); |
| 5582 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5583 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5584 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5585 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5586 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5587 | |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5588 | /* |
| 5589 | * Must wait for vblank to avoid spurious PCH FIFO underruns. |
| 5590 | * And a second vblank wait is needed at least on ILK with |
| 5591 | * some interlaced HDMI modes. Let's do the double wait always |
| 5592 | * in case there are more corner cases we don't know about. |
| 5593 | */ |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5594 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5595 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5596 | intel_wait_for_vblank(dev_priv, pipe); |
| 5597 | } |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5598 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5599 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5600 | } |
| 5601 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5602 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5603 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5604 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5605 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5606 | } |
| 5607 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5608 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5609 | enum pipe pipe, bool apply) |
| 5610 | { |
| 5611 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5612 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5613 | |
| 5614 | if (apply) |
| 5615 | val |= mask; |
| 5616 | else |
| 5617 | val &= ~mask; |
| 5618 | |
| 5619 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5620 | } |
| 5621 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5622 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5623 | { |
| 5624 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5625 | enum pipe pipe = crtc->pipe; |
| 5626 | uint32_t val; |
| 5627 | |
Rodrigo Vivi | 443d5e3 | 2018-10-04 08:18:14 -0700 | [diff] [blame] | 5628 | val = MBUS_DBOX_A_CREDIT(2); |
| 5629 | val |= MBUS_DBOX_BW_CREDIT(1); |
| 5630 | val |= MBUS_DBOX_B_CREDIT(8); |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5631 | |
| 5632 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5633 | } |
| 5634 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5635 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5636 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5637 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5638 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5639 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5640 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5641 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5642 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5643 | struct intel_atomic_state *old_intel_state = |
| 5644 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5645 | bool psl_clkgate_wa; |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5646 | u32 pipe_chicken; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5647 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5648 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5649 | return; |
| 5650 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5651 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5652 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5653 | if (pipe_config->shared_dpll) |
| 5654 | intel_enable_shared_dpll(pipe_config); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5655 | |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5656 | if (INTEL_GEN(dev_priv) >= 11) |
| 5657 | icl_map_plls_to_ports(crtc, pipe_config, old_state); |
| 5658 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame] | 5659 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5660 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5661 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5662 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5663 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5664 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5665 | intel_set_pipe_timings(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5666 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5667 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5668 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5669 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5670 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5671 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5672 | pipe_config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5673 | } |
| 5674 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5675 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5676 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5677 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5678 | } |
| 5679 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5680 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5681 | haswell_set_pipeconf(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5682 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5683 | haswell_set_pipemisc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5684 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5685 | intel_color_set_csc(&pipe_config->base); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5686 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5687 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5688 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5689 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5690 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5691 | pipe_config->pch_pfit.enabled; |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5692 | if (psl_clkgate_wa) |
| 5693 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5694 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5695 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5696 | skylake_pfit_enable(pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5697 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5698 | ironlake_pfit_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5699 | |
| 5700 | /* |
| 5701 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5702 | * clocks enabled |
| 5703 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5704 | intel_color_load_luts(&pipe_config->base); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5705 | |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5706 | /* |
| 5707 | * Display WA #1153: enable hardware to bypass the alpha math |
| 5708 | * and rounding for per-pixel values 00 and 0xff |
| 5709 | */ |
| 5710 | if (INTEL_GEN(dev_priv) >= 11) { |
| 5711 | pipe_chicken = I915_READ(PIPE_CHICKEN(pipe)); |
| 5712 | if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN)) |
| 5713 | I915_WRITE_FW(PIPE_CHICKEN(pipe), |
| 5714 | pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN); |
| 5715 | } |
| 5716 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5717 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5718 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5719 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5720 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5721 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5722 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5723 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5724 | if (INTEL_GEN(dev_priv) >= 11) |
| 5725 | icl_pipe_mbus_enable(intel_crtc); |
| 5726 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5727 | /* 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] | 5728 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5729 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5730 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5731 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5732 | lpt_pch_enable(old_intel_state, pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5733 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5734 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5735 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5736 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5737 | assert_vblank_disabled(crtc); |
| 5738 | drm_crtc_vblank_on(crtc); |
| 5739 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5740 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5741 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5742 | if (psl_clkgate_wa) { |
| 5743 | intel_wait_for_vblank(dev_priv, pipe); |
| 5744 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5745 | } |
| 5746 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5747 | /* If we change the relative order between pipe/planes enabling, we need |
| 5748 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5749 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5750 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5751 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5752 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5753 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5754 | } |
| 5755 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5756 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5757 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5758 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5759 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5760 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5761 | |
| 5762 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5763 | * it's in use. The hw state code will make sure we get this right. */ |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5764 | if (old_crtc_state->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5765 | I915_WRITE(PF_CTL(pipe), 0); |
| 5766 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5767 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5768 | } |
| 5769 | } |
| 5770 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5771 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5772 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5773 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5774 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5775 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5776 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5777 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5778 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5779 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5780 | /* |
| 5781 | * Sometimes spurious CPU pipe underruns happen when the |
| 5782 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 5783 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 5784 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5785 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5786 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5787 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5788 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5789 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5790 | drm_crtc_vblank_off(crtc); |
| 5791 | assert_vblank_disabled(crtc); |
| 5792 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5793 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5794 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5795 | ironlake_pfit_disable(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5796 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5797 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 5798 | ironlake_fdi_disable(crtc); |
| 5799 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5800 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5801 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5802 | if (old_crtc_state->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5803 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5804 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5805 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5806 | i915_reg_t reg; |
| 5807 | u32 temp; |
| 5808 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5809 | /* disable TRANS_DP_CTL */ |
| 5810 | reg = TRANS_DP_CTL(pipe); |
| 5811 | temp = I915_READ(reg); |
| 5812 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5813 | TRANS_DP_PORT_SEL_MASK); |
| 5814 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5815 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5816 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5817 | /* disable DPLL_SEL */ |
| 5818 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5819 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5820 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5821 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5822 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5823 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5824 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5825 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5826 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5827 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5828 | } |
| 5829 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5830 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5831 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5832 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5833 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5834 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5835 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5836 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5837 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5838 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5839 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5840 | drm_crtc_vblank_off(crtc); |
| 5841 | assert_vblank_disabled(crtc); |
| 5842 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5843 | /* 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] | 5844 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5845 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5846 | |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5847 | if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) |
| 5848 | intel_ddi_set_vc_payload_alloc(old_crtc_state, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5849 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5850 | if (!transcoder_is_dsi(cpu_transcoder)) |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 5851 | intel_ddi_disable_transcoder_func(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5852 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5853 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5854 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5855 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5856 | ironlake_pfit_disable(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5857 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5858 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5859 | |
| 5860 | if (INTEL_GEN(dev_priv) >= 11) |
| 5861 | icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state); |
Imre Deak | bdaa29b | 2018-11-01 16:04:24 +0200 | [diff] [blame] | 5862 | |
| 5863 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5864 | } |
| 5865 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5866 | static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5867 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5868 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5869 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5870 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5871 | if (!crtc_state->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5872 | return; |
| 5873 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5874 | /* |
| 5875 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5876 | * according to register description and PRM. |
| 5877 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5878 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5879 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5880 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5881 | I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios); |
| 5882 | I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5883 | |
| 5884 | /* Border color in case we don't scale up to the full screen. Black by |
| 5885 | * default, change to something else for debugging. */ |
| 5886 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5887 | } |
| 5888 | |
Mahesh Kumar | 176597a | 2018-10-04 14:20:43 +0530 | [diff] [blame] | 5889 | bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port) |
| 5890 | { |
| 5891 | if (port == PORT_NONE) |
| 5892 | return false; |
| 5893 | |
| 5894 | if (IS_ICELAKE(dev_priv)) |
| 5895 | return port <= PORT_B; |
| 5896 | |
| 5897 | return false; |
| 5898 | } |
| 5899 | |
Paulo Zanoni | ac213c1 | 2018-05-21 17:25:37 -0700 | [diff] [blame] | 5900 | bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5901 | { |
| 5902 | if (IS_ICELAKE(dev_priv)) |
| 5903 | return port >= PORT_C && port <= PORT_F; |
| 5904 | |
| 5905 | return false; |
| 5906 | } |
| 5907 | |
| 5908 | enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5909 | { |
| 5910 | if (!intel_port_is_tc(dev_priv, port)) |
| 5911 | return PORT_TC_NONE; |
| 5912 | |
| 5913 | return port - PORT_C; |
| 5914 | } |
| 5915 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 5916 | 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] | 5917 | { |
| 5918 | switch (port) { |
| 5919 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5920 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5921 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5922 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5923 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5924 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5925 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5926 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5927 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5928 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 5929 | case PORT_F: |
| 5930 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5931 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5932 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5933 | return POWER_DOMAIN_PORT_OTHER; |
| 5934 | } |
| 5935 | } |
| 5936 | |
Imre Deak | 337837a | 2018-11-01 16:04:23 +0200 | [diff] [blame] | 5937 | enum intel_display_power_domain |
| 5938 | intel_aux_power_domain(struct intel_digital_port *dig_port) |
| 5939 | { |
| 5940 | switch (dig_port->aux_ch) { |
| 5941 | case AUX_CH_A: |
| 5942 | return POWER_DOMAIN_AUX_A; |
| 5943 | case AUX_CH_B: |
| 5944 | return POWER_DOMAIN_AUX_B; |
| 5945 | case AUX_CH_C: |
| 5946 | return POWER_DOMAIN_AUX_C; |
| 5947 | case AUX_CH_D: |
| 5948 | return POWER_DOMAIN_AUX_D; |
| 5949 | case AUX_CH_E: |
| 5950 | return POWER_DOMAIN_AUX_E; |
| 5951 | case AUX_CH_F: |
| 5952 | return POWER_DOMAIN_AUX_F; |
| 5953 | default: |
| 5954 | MISSING_CASE(dig_port->aux_ch); |
| 5955 | return POWER_DOMAIN_AUX_A; |
| 5956 | } |
| 5957 | } |
| 5958 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5959 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 5960 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5961 | { |
| 5962 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5963 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5964 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5965 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5966 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5967 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5968 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5969 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5970 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5971 | return 0; |
| 5972 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 5973 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 5974 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5975 | if (crtc_state->pch_pfit.enabled || |
| 5976 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5977 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5978 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5979 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5980 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5981 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 5982 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5983 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5984 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5985 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 5986 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5987 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5988 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5989 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5990 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5991 | return mask; |
| 5992 | } |
| 5993 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 5994 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5995 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5996 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5997 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5998 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5999 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6000 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6001 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6002 | |
| 6003 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6004 | intel_crtc->enabled_power_domains = new_domains = |
| 6005 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6006 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6007 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6008 | |
| 6009 | for_each_power_domain(domain, domains) |
| 6010 | intel_display_power_get(dev_priv, domain); |
| 6011 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6012 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | 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] | 6016 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6017 | { |
| 6018 | enum intel_display_power_domain domain; |
| 6019 | |
| 6020 | for_each_power_domain(domain, domains) |
| 6021 | intel_display_power_put(dev_priv, domain); |
| 6022 | } |
| 6023 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6024 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6025 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6026 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6027 | struct intel_atomic_state *old_intel_state = |
| 6028 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6029 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6030 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6031 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6032 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6033 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6034 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6035 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6036 | return; |
| 6037 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6038 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6039 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6040 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6041 | intel_set_pipe_timings(pipe_config); |
| 6042 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6043 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6044 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6045 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6046 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6047 | } |
| 6048 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6049 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6050 | |
P Raviraj Sitaram | c59d2da | 2018-09-10 19:57:14 +0530 | [diff] [blame] | 6051 | intel_color_set_csc(&pipe_config->base); |
| 6052 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6053 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6054 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6055 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6056 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6057 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6058 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6059 | if (IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6060 | chv_prepare_pll(intel_crtc, pipe_config); |
| 6061 | chv_enable_pll(intel_crtc, pipe_config); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6062 | } else { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6063 | vlv_prepare_pll(intel_crtc, pipe_config); |
| 6064 | vlv_enable_pll(intel_crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6065 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6066 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6067 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6068 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6069 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6070 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6071 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6072 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6073 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6074 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6075 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6076 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6077 | assert_vblank_disabled(crtc); |
| 6078 | drm_crtc_vblank_on(crtc); |
| 6079 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6080 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6081 | } |
| 6082 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6083 | static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6084 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6085 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6086 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6087 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6088 | I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0); |
| 6089 | I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6090 | } |
| 6091 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6092 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6093 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6094 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6095 | struct intel_atomic_state *old_intel_state = |
| 6096 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6097 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6098 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6099 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6100 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6101 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6102 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6103 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6104 | return; |
| 6105 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6106 | i9xx_set_pll_dividers(pipe_config); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6107 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6108 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6109 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6110 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6111 | intel_set_pipe_timings(pipe_config); |
| 6112 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6113 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6114 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6115 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6116 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6117 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6118 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6119 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6120 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6121 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6122 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 6123 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6124 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6125 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6126 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6127 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6128 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6129 | if (dev_priv->display.initial_watermarks != NULL) |
| 6130 | dev_priv->display.initial_watermarks(old_intel_state, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6131 | pipe_config); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6132 | else |
| 6133 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6134 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6135 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6136 | assert_vblank_disabled(crtc); |
| 6137 | drm_crtc_vblank_on(crtc); |
| 6138 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6139 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6140 | } |
| 6141 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6142 | static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state) |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6143 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6144 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 6145 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6146 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6147 | if (!old_crtc_state->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6148 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6149 | |
| 6150 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6151 | |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 6152 | DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n", |
| 6153 | I915_READ(PFIT_CONTROL)); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6154 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6155 | } |
| 6156 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6157 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6158 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6159 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6160 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6161 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6162 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6163 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6164 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6165 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6166 | /* |
| 6167 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6168 | * wait for planes to fully turn off before disabling the pipe. |
| 6169 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6170 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6171 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6172 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6173 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6174 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6175 | drm_crtc_vblank_off(crtc); |
| 6176 | assert_vblank_disabled(crtc); |
| 6177 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6178 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6179 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6180 | i9xx_pfit_disable(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6181 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6182 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6183 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6184 | if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6185 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6186 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6187 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6188 | vlv_disable_pll(dev_priv, pipe); |
| 6189 | else |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6190 | i9xx_disable_pll(old_crtc_state); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6191 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6192 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6193 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6194 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6195 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6196 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6197 | |
| 6198 | if (!dev_priv->display.initial_watermarks) |
| 6199 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6200 | |
| 6201 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6202 | if (IS_I830(dev_priv)) |
| 6203 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6204 | } |
| 6205 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6206 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6207 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6208 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6209 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6210 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6211 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6212 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6213 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6214 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6215 | struct drm_atomic_state *state; |
| 6216 | struct intel_crtc_state *crtc_state; |
| 6217 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6218 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6219 | if (!intel_crtc->active) |
| 6220 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6221 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6222 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6223 | const struct intel_plane_state *plane_state = |
| 6224 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6225 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6226 | if (plane_state->base.visible) |
| 6227 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6228 | } |
| 6229 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6230 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6231 | if (!state) { |
| 6232 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6233 | crtc->base.id, crtc->name); |
| 6234 | return; |
| 6235 | } |
| 6236 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6237 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6238 | |
| 6239 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6240 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6241 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6242 | |
| 6243 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6244 | |
| 6245 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6246 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6247 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6248 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6249 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6250 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6251 | |
| 6252 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6253 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6254 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6255 | crtc->enabled = false; |
| 6256 | crtc->state->connector_mask = 0; |
| 6257 | crtc->state->encoder_mask = 0; |
| 6258 | |
| 6259 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6260 | encoder->base.crtc = NULL; |
| 6261 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6262 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6263 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 6264 | intel_disable_shared_dpll(to_intel_crtc_state(crtc->state)); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6265 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6266 | domains = intel_crtc->enabled_power_domains; |
| 6267 | for_each_power_domain(domain, domains) |
| 6268 | intel_display_power_put(dev_priv, domain); |
| 6269 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6270 | |
| 6271 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6272 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6273 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6274 | } |
| 6275 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6276 | /* |
| 6277 | * turn all crtc's off, but do not adjust state |
| 6278 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6279 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6280 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6281 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6282 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6283 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6284 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6285 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6286 | state = drm_atomic_helper_suspend(dev); |
| 6287 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6288 | if (ret) |
| 6289 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6290 | else |
| 6291 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6292 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6293 | } |
| 6294 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6295 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6296 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6297 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6298 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6299 | drm_encoder_cleanup(encoder); |
| 6300 | kfree(intel_encoder); |
| 6301 | } |
| 6302 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6303 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6304 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6305 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6306 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6307 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6308 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6309 | |
| 6310 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6311 | connector->base.base.id, |
| 6312 | connector->base.name); |
| 6313 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6314 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6315 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6316 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6317 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6318 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6319 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6320 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6321 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6322 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6323 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6324 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6325 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6326 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6327 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6328 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6329 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6330 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6331 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6332 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6333 | "attached encoder crtc differs from connector crtc\n"); |
| 6334 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6335 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6336 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6337 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6338 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6339 | } |
| 6340 | } |
| 6341 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6342 | 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] | 6343 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6344 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6345 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6346 | |
| 6347 | return 0; |
| 6348 | } |
| 6349 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6350 | 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] | 6351 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6352 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6353 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6354 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6355 | struct intel_crtc *other_crtc; |
| 6356 | struct intel_crtc_state *other_crtc_state; |
| 6357 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6358 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6359 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6360 | if (pipe_config->fdi_lanes > 4) { |
| 6361 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6362 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6363 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6364 | } |
| 6365 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6366 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6367 | if (pipe_config->fdi_lanes > 2) { |
| 6368 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6369 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6370 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6371 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6372 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6373 | } |
| 6374 | } |
| 6375 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6376 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6377 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6378 | |
| 6379 | /* Ivybridge 3 pipe is really complicated */ |
| 6380 | switch (pipe) { |
| 6381 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6382 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6383 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6384 | if (pipe_config->fdi_lanes <= 2) |
| 6385 | return 0; |
| 6386 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6387 | 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] | 6388 | other_crtc_state = |
| 6389 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6390 | if (IS_ERR(other_crtc_state)) |
| 6391 | return PTR_ERR(other_crtc_state); |
| 6392 | |
| 6393 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6394 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6395 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6396 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6397 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6398 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6399 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6400 | if (pipe_config->fdi_lanes > 2) { |
| 6401 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6402 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6403 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6404 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6405 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6406 | 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] | 6407 | other_crtc_state = |
| 6408 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6409 | if (IS_ERR(other_crtc_state)) |
| 6410 | return PTR_ERR(other_crtc_state); |
| 6411 | |
| 6412 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6413 | 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] | 6414 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6415 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6416 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6417 | default: |
| 6418 | BUG(); |
| 6419 | } |
| 6420 | } |
| 6421 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6422 | #define RETRY 1 |
| 6423 | 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] | 6424 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6425 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6426 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6427 | 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] | 6428 | int lane, link_bw, fdi_dotclock, ret; |
| 6429 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6430 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6431 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6432 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6433 | * each output octet as 10 bits. The actual frequency |
| 6434 | * is stored as a divider into a 100MHz clock, and the |
| 6435 | * mode pixel clock is stored in units of 1KHz. |
| 6436 | * Hence the bw of each lane in terms of the mode signal |
| 6437 | * is: |
| 6438 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6439 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6440 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6441 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6442 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6443 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6444 | pipe_config->pipe_bpp); |
| 6445 | |
| 6446 | pipe_config->fdi_lanes = lane; |
| 6447 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6448 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6449 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6450 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6451 | 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] | 6452 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6453 | pipe_config->pipe_bpp -= 2*3; |
| 6454 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6455 | pipe_config->pipe_bpp); |
| 6456 | needs_recompute = true; |
| 6457 | pipe_config->bw_constrained = true; |
| 6458 | |
| 6459 | goto retry; |
| 6460 | } |
| 6461 | |
| 6462 | if (needs_recompute) |
| 6463 | return RETRY; |
| 6464 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6465 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6466 | } |
| 6467 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6468 | 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] | 6469 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6470 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6471 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6472 | |
| 6473 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6474 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6475 | return false; |
| 6476 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6477 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6478 | return false; |
| 6479 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6480 | if (crtc_state->pipe_bpp > 24) |
| 6481 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6482 | |
| 6483 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6484 | * We compare against max which means we must take |
| 6485 | * the increased cdclk requirement into account when |
| 6486 | * calculating the new cdclk. |
| 6487 | * |
| 6488 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6489 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6490 | if (IS_BROADWELL(dev_priv) && |
| 6491 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6492 | return false; |
| 6493 | |
| 6494 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6495 | } |
| 6496 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6497 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6498 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6499 | struct drm_i915_private *dev_priv = |
| 6500 | to_i915(crtc_state->base.crtc->dev); |
| 6501 | struct intel_atomic_state *intel_state = |
| 6502 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6503 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6504 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6505 | return false; |
| 6506 | |
| 6507 | if (crtc_state->ips_force_disable) |
| 6508 | return false; |
| 6509 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6510 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6511 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6512 | return false; |
| 6513 | |
| 6514 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6515 | if (IS_BROADWELL(dev_priv) && |
| 6516 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6517 | return false; |
| 6518 | |
| 6519 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6520 | } |
| 6521 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6522 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6523 | { |
| 6524 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6525 | |
| 6526 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6527 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6528 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6529 | } |
| 6530 | |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6531 | static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
| 6532 | { |
| 6533 | uint32_t pixel_rate; |
| 6534 | |
| 6535 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6536 | |
| 6537 | /* |
| 6538 | * We only use IF-ID interlacing. If we ever use |
| 6539 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6540 | */ |
| 6541 | |
| 6542 | if (pipe_config->pch_pfit.enabled) { |
| 6543 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
| 6544 | uint32_t pfit_size = pipe_config->pch_pfit.size; |
| 6545 | |
| 6546 | pipe_w = pipe_config->pipe_src_w; |
| 6547 | pipe_h = pipe_config->pipe_src_h; |
| 6548 | |
| 6549 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6550 | pfit_h = pfit_size & 0xFFFF; |
| 6551 | if (pipe_w < pfit_w) |
| 6552 | pipe_w = pfit_w; |
| 6553 | if (pipe_h < pfit_h) |
| 6554 | pipe_h = pfit_h; |
| 6555 | |
| 6556 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6557 | return pixel_rate; |
| 6558 | |
| 6559 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 6560 | pfit_w * pfit_h); |
| 6561 | } |
| 6562 | |
| 6563 | return pixel_rate; |
| 6564 | } |
| 6565 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6566 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6567 | { |
| 6568 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6569 | |
| 6570 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 6571 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6572 | crtc_state->pixel_rate = |
| 6573 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6574 | else |
| 6575 | crtc_state->pixel_rate = |
| 6576 | ilk_pipe_pixel_rate(crtc_state); |
| 6577 | } |
| 6578 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6579 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6580 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6581 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6582 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6583 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6584 | 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] | 6585 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6586 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6587 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6588 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6589 | |
| 6590 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6591 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6592 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6593 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6594 | if (intel_crtc_supports_double_wide(crtc) && |
| 6595 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6596 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6597 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6598 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6599 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6600 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6601 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6602 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6603 | adjusted_mode->crtc_clock, clock_limit, |
| 6604 | yesno(pipe_config->double_wide)); |
| 6605 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6606 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6607 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 6608 | if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 6609 | pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) && |
| 6610 | pipe_config->base.ctm) { |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6611 | /* |
| 6612 | * There is only one pipe CSC unit per pipe, and we need that |
| 6613 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6614 | * applied we can't support YCBCR420 output. |
| 6615 | */ |
| 6616 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6617 | return -EINVAL; |
| 6618 | } |
| 6619 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6620 | /* |
| 6621 | * Pipe horizontal size must be even in: |
| 6622 | * - DVO ganged mode |
| 6623 | * - LVDS dual channel mode |
| 6624 | * - Double wide pipe |
| 6625 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6626 | if (pipe_config->pipe_src_w & 1) { |
| 6627 | if (pipe_config->double_wide) { |
| 6628 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6629 | return -EINVAL; |
| 6630 | } |
| 6631 | |
| 6632 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6633 | intel_is_dual_link_lvds(dev)) { |
| 6634 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6635 | return -EINVAL; |
| 6636 | } |
| 6637 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6638 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6639 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6640 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6641 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6642 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6643 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6644 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6645 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6646 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6647 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6648 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6649 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6650 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6651 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6652 | } |
| 6653 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6654 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6655 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6656 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6657 | while (*num > DATA_LINK_M_N_MASK || |
| 6658 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6659 | *num >>= 1; |
| 6660 | *den >>= 1; |
| 6661 | } |
| 6662 | } |
| 6663 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6664 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6665 | uint32_t *ret_m, uint32_t *ret_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6666 | bool constant_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6667 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6668 | /* |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6669 | * Several DP dongles in particular seem to be fussy about |
| 6670 | * too large link M/N values. Give N value as 0x8000 that |
| 6671 | * should be acceptable by specific devices. 0x8000 is the |
| 6672 | * specified fixed N value for asynchronous clock mode, |
| 6673 | * which the devices expect also in synchronous clock mode. |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6674 | */ |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6675 | if (constant_n) |
| 6676 | *ret_n = 0x8000; |
| 6677 | else |
| 6678 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6679 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6680 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6681 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6682 | } |
| 6683 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6684 | void |
| 6685 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 6686 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6687 | struct intel_link_m_n *m_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6688 | bool constant_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6689 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6690 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6691 | |
| 6692 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6693 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6694 | &m_n->gmch_m, &m_n->gmch_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6695 | constant_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6696 | |
| 6697 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6698 | &m_n->link_m, &m_n->link_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6699 | constant_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6700 | } |
| 6701 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6702 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6703 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6704 | if (i915_modparams.panel_use_ssc >= 0) |
| 6705 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6706 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6707 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6708 | } |
| 6709 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6710 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6711 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6712 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6713 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6714 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6715 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6716 | { |
| 6717 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6718 | } |
| 6719 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6720 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6721 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6722 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6723 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6724 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6725 | u32 fp, fp2 = 0; |
| 6726 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6727 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6728 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6729 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6730 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6731 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6732 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6733 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6734 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6735 | } |
| 6736 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6737 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6738 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6739 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6740 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6741 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6742 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6743 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6744 | } |
| 6745 | } |
| 6746 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6747 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6748 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6749 | { |
| 6750 | u32 reg_val; |
| 6751 | |
| 6752 | /* |
| 6753 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6754 | * and set it to a reasonable value instead. |
| 6755 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6756 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6757 | reg_val &= 0xffffff00; |
| 6758 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6759 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6760 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6761 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 6762 | reg_val &= 0x00ffffff; |
| 6763 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6764 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6765 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6766 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6767 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6768 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6769 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6770 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6771 | reg_val &= 0x00ffffff; |
| 6772 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6773 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6774 | } |
| 6775 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6776 | static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 6777 | const struct intel_link_m_n *m_n) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6778 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6779 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6780 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6781 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6782 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6783 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6784 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6785 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6786 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6787 | } |
| 6788 | |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6789 | static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv, |
| 6790 | enum transcoder transcoder) |
| 6791 | { |
| 6792 | if (IS_HASWELL(dev_priv)) |
| 6793 | return transcoder == TRANSCODER_EDP; |
| 6794 | |
| 6795 | /* |
| 6796 | * Strictly speaking some registers are available before |
| 6797 | * gen7, but we only support DRRS on gen7+ |
| 6798 | */ |
| 6799 | return IS_GEN7(dev_priv) || IS_CHERRYVIEW(dev_priv); |
| 6800 | } |
| 6801 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6802 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 6803 | const struct intel_link_m_n *m_n, |
| 6804 | const struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6805 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6806 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6807 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6808 | enum pipe pipe = crtc->pipe; |
| 6809 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6810 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6811 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6812 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6813 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6814 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6815 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6816 | /* |
| 6817 | * M2_N2 registers are set only if DRRS is supported |
| 6818 | * (to make sure the registers are not unnecessarily accessed). |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6819 | */ |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6820 | if (m2_n2 && crtc_state->has_drrs && |
| 6821 | transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6822 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6823 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6824 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6825 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6826 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6827 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6828 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6829 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6830 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6831 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6832 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6833 | } |
| 6834 | } |
| 6835 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6836 | void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6837 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6838 | const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6839 | |
| 6840 | if (m_n == M1_N1) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6841 | dp_m_n = &crtc_state->dp_m_n; |
| 6842 | dp_m2_n2 = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6843 | } else if (m_n == M2_N2) { |
| 6844 | |
| 6845 | /* |
| 6846 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6847 | * needs to be programmed into M1_N1. |
| 6848 | */ |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6849 | dp_m_n = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6850 | } else { |
| 6851 | DRM_ERROR("Unsupported divider value\n"); |
| 6852 | return; |
| 6853 | } |
| 6854 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6855 | if (crtc_state->has_pch_encoder) |
| 6856 | intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6857 | else |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6858 | intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6859 | } |
| 6860 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 6861 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 6862 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6863 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6864 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6865 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6866 | if (crtc->pipe != PIPE_A) |
| 6867 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6868 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6869 | /* 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] | 6870 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6871 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 6872 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 6873 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6874 | pipe_config->dpll_hw_state.dpll_md = |
| 6875 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 6876 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6877 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6878 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 6879 | struct intel_crtc_state *pipe_config) |
| 6880 | { |
| 6881 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6882 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6883 | if (crtc->pipe != PIPE_A) |
| 6884 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6885 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6886 | /* 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] | 6887 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6888 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 6889 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6890 | pipe_config->dpll_hw_state.dpll_md = |
| 6891 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6892 | } |
| 6893 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6894 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6895 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6896 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6897 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6898 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6899 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6900 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6901 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6902 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6903 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6904 | /* Enable Refclk */ |
| 6905 | I915_WRITE(DPLL(pipe), |
| 6906 | pipe_config->dpll_hw_state.dpll & |
| 6907 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 6908 | |
| 6909 | /* No need to actually set up the DPLL with DSI */ |
| 6910 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 6911 | return; |
| 6912 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6913 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6914 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6915 | bestn = pipe_config->dpll.n; |
| 6916 | bestm1 = pipe_config->dpll.m1; |
| 6917 | bestm2 = pipe_config->dpll.m2; |
| 6918 | bestp1 = pipe_config->dpll.p1; |
| 6919 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6920 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6921 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6922 | |
| 6923 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6924 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6925 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6926 | |
| 6927 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6928 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6929 | |
| 6930 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6931 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6932 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6933 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6934 | |
| 6935 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6936 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6937 | |
| 6938 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6939 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6940 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6941 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6942 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6943 | |
| 6944 | /* |
| 6945 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6946 | * but we don't support that). |
| 6947 | * Note: don't use the DAC post divider as it seems unstable. |
| 6948 | */ |
| 6949 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6950 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6951 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6952 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6953 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6954 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6955 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6956 | if (pipe_config->port_clock == 162000 || |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 6957 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) || |
| 6958 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6959 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6960 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6961 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6962 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6963 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6964 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 6965 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6966 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6967 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6968 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6969 | 0x0df40000); |
| 6970 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6971 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6972 | 0x0df70000); |
| 6973 | } else { /* HDMI or VGA */ |
| 6974 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6975 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6976 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6977 | 0x0df70000); |
| 6978 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6979 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6980 | 0x0df40000); |
| 6981 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6982 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6983 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6984 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 6985 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6986 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6987 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6988 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6989 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6990 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6991 | } |
| 6992 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6993 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6994 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6995 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6996 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6997 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6998 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6999 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7000 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7001 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7002 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7003 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7004 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7005 | /* Enable Refclk and SSC */ |
| 7006 | I915_WRITE(DPLL(pipe), |
| 7007 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7008 | |
| 7009 | /* No need to actually set up the DPLL with DSI */ |
| 7010 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7011 | return; |
| 7012 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7013 | bestn = pipe_config->dpll.n; |
| 7014 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7015 | bestm1 = pipe_config->dpll.m1; |
| 7016 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7017 | bestp1 = pipe_config->dpll.p1; |
| 7018 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7019 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7020 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7021 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7022 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7023 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7024 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7025 | /* p1 and p2 divider */ |
| 7026 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7027 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7028 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7029 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7030 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7031 | |
| 7032 | /* Feedback post-divider - m2 */ |
| 7033 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7034 | |
| 7035 | /* Feedback refclk divider - n and m1 */ |
| 7036 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7037 | DPIO_CHV_M1_DIV_BY_2 | |
| 7038 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7039 | |
| 7040 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7041 | 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] | 7042 | |
| 7043 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7044 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7045 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7046 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7047 | if (bestm2_frac) |
| 7048 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7049 | 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] | 7050 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7051 | /* Program digital lock detect threshold */ |
| 7052 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7053 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7054 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7055 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7056 | if (!bestm2_frac) |
| 7057 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7058 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7059 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7060 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7061 | if (vco == 5400000) { |
| 7062 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7063 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7064 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7065 | tribuf_calcntr = 0x9; |
| 7066 | } else if (vco <= 6200000) { |
| 7067 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7068 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7069 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7070 | tribuf_calcntr = 0x9; |
| 7071 | } else if (vco <= 6480000) { |
| 7072 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7073 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7074 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7075 | tribuf_calcntr = 0x8; |
| 7076 | } else { |
| 7077 | /* Not supported. Apply the same limits as in the max case */ |
| 7078 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7079 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7080 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7081 | tribuf_calcntr = 0; |
| 7082 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7083 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7084 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7085 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7086 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7087 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7088 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7089 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7090 | /* AFC Recal */ |
| 7091 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7092 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7093 | DPIO_AFC_RECAL); |
| 7094 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7095 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7096 | } |
| 7097 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7098 | /** |
| 7099 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7100 | * @dev_priv: i915 private structure |
| 7101 | * @pipe: pipe PLL to enable |
| 7102 | * @dpll: PLL configuration |
| 7103 | * |
| 7104 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7105 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7106 | * be enabled. |
| 7107 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7108 | 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] | 7109 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7110 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7111 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7112 | struct intel_crtc_state *pipe_config; |
| 7113 | |
| 7114 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7115 | if (!pipe_config) |
| 7116 | return -ENOMEM; |
| 7117 | |
| 7118 | pipe_config->base.crtc = &crtc->base; |
| 7119 | pipe_config->pixel_multiplier = 1; |
| 7120 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7121 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7122 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7123 | chv_compute_dpll(crtc, pipe_config); |
| 7124 | chv_prepare_pll(crtc, pipe_config); |
| 7125 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7126 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7127 | vlv_compute_dpll(crtc, pipe_config); |
| 7128 | vlv_prepare_pll(crtc, pipe_config); |
| 7129 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7130 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7131 | |
| 7132 | kfree(pipe_config); |
| 7133 | |
| 7134 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7135 | } |
| 7136 | |
| 7137 | /** |
| 7138 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7139 | * @dev_priv: i915 private structure |
| 7140 | * @pipe: pipe PLL to disable |
| 7141 | * |
| 7142 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7143 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7144 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7145 | 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] | 7146 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7147 | if (IS_CHERRYVIEW(dev_priv)) |
| 7148 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7149 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7150 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7151 | } |
| 7152 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7153 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7154 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7155 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7156 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7157 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7158 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7159 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7160 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7161 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7162 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7163 | dpll = DPLL_VGA_MODE_DIS; |
| 7164 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7165 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7166 | dpll |= DPLLB_MODE_LVDS; |
| 7167 | else |
| 7168 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7169 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7170 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7171 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7172 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7173 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7174 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7175 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7176 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7177 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7178 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7179 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7180 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7181 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7182 | |
| 7183 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7184 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7185 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7186 | else { |
| 7187 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7188 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7189 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7190 | } |
| 7191 | switch (clock->p2) { |
| 7192 | case 5: |
| 7193 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7194 | break; |
| 7195 | case 7: |
| 7196 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7197 | break; |
| 7198 | case 10: |
| 7199 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7200 | break; |
| 7201 | case 14: |
| 7202 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7203 | break; |
| 7204 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7205 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7206 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7207 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7208 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7209 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7210 | 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] | 7211 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7212 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7213 | else |
| 7214 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7215 | |
| 7216 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7217 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7218 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7219 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7220 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7221 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7222 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7226 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7227 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7228 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7229 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7230 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7231 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7232 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7233 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7234 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7235 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7236 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7237 | dpll = DPLL_VGA_MODE_DIS; |
| 7238 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7239 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7240 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7241 | } else { |
| 7242 | if (clock->p1 == 2) |
| 7243 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7244 | else |
| 7245 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7246 | if (clock->p2 == 4) |
| 7247 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7248 | } |
| 7249 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7250 | if (!IS_I830(dev_priv) && |
| 7251 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7252 | dpll |= DPLL_DVO_2X_MODE; |
| 7253 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7254 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7255 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7256 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7257 | else |
| 7258 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7259 | |
| 7260 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7261 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7262 | } |
| 7263 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7264 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7265 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7266 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7267 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7268 | enum pipe pipe = crtc->pipe; |
| 7269 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 7270 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7271 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7272 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7273 | |
| 7274 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7275 | * the hw state checker will get angry at the mismatch. */ |
| 7276 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7277 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7278 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7279 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7280 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7281 | crtc_vtotal -= 1; |
| 7282 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7283 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7284 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7285 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7286 | else |
| 7287 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7288 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7289 | if (vsyncshift < 0) |
| 7290 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7291 | } |
| 7292 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7293 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7294 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7295 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7296 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7297 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7298 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7299 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7300 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7301 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7302 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7303 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7304 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7305 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7306 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7307 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7308 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7309 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7310 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7311 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7312 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7313 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7314 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7315 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7316 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7317 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7318 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7319 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7320 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7321 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7322 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7323 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7324 | } |
| 7325 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7326 | static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state) |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7327 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7328 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7329 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7330 | enum pipe pipe = crtc->pipe; |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7331 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7332 | /* pipesrc controls the size that is scaled from, which should |
| 7333 | * always be the user's requested size. |
| 7334 | */ |
| 7335 | I915_WRITE(PIPESRC(pipe), |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7336 | ((crtc_state->pipe_src_w - 1) << 16) | |
| 7337 | (crtc_state->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7338 | } |
| 7339 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7340 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7341 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7342 | { |
| 7343 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7344 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7345 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7346 | uint32_t tmp; |
| 7347 | |
| 7348 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7349 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7350 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7351 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7352 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7353 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7354 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7355 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7356 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7357 | |
| 7358 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7359 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7360 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7361 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7362 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7363 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7364 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7365 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7366 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7367 | |
| 7368 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7369 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7370 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7371 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7372 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7373 | } |
| 7374 | |
| 7375 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7376 | struct intel_crtc_state *pipe_config) |
| 7377 | { |
| 7378 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7379 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7380 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7381 | |
| 7382 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7383 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7384 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7385 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7386 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7387 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7388 | } |
| 7389 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7390 | 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] | 7391 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7392 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7393 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7394 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7395 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7396 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7397 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7398 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7399 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7400 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7401 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7402 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7403 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7404 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7405 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7406 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7407 | |
| 7408 | mode->hsync = drm_mode_hsync(mode); |
| 7409 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7410 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7411 | } |
| 7412 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7413 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7414 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7415 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7416 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7417 | uint32_t pipeconf; |
| 7418 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7419 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7420 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7421 | /* we keep both pipes enabled on 830 */ |
| 7422 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7423 | pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7424 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7425 | if (crtc_state->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7426 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7427 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7428 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7429 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7430 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7431 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7432 | if (crtc_state->dither && crtc_state->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7433 | pipeconf |= PIPECONF_DITHER_EN | |
| 7434 | PIPECONF_DITHER_TYPE_SP; |
| 7435 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7436 | switch (crtc_state->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7437 | case 18: |
| 7438 | pipeconf |= PIPECONF_6BPC; |
| 7439 | break; |
| 7440 | case 24: |
| 7441 | pipeconf |= PIPECONF_8BPC; |
| 7442 | break; |
| 7443 | case 30: |
| 7444 | pipeconf |= PIPECONF_10BPC; |
| 7445 | break; |
| 7446 | default: |
| 7447 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7448 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7449 | } |
| 7450 | } |
| 7451 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7452 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7453 | if (INTEL_GEN(dev_priv) < 4 || |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7454 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7455 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7456 | else |
| 7457 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7458 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7459 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7460 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7461 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7462 | crtc_state->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7463 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7464 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7465 | I915_WRITE(PIPECONF(crtc->pipe), pipeconf); |
| 7466 | POSTING_READ(PIPECONF(crtc->pipe)); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7467 | } |
| 7468 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7469 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7470 | struct intel_crtc_state *crtc_state) |
| 7471 | { |
| 7472 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7473 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7474 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7475 | int refclk = 48000; |
| 7476 | |
| 7477 | memset(&crtc_state->dpll_hw_state, 0, |
| 7478 | sizeof(crtc_state->dpll_hw_state)); |
| 7479 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7480 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7481 | if (intel_panel_use_ssc(dev_priv)) { |
| 7482 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7483 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7484 | } |
| 7485 | |
| 7486 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7487 | } 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] | 7488 | limit = &intel_limits_i8xx_dvo; |
| 7489 | } else { |
| 7490 | limit = &intel_limits_i8xx_dac; |
| 7491 | } |
| 7492 | |
| 7493 | if (!crtc_state->clock_set && |
| 7494 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7495 | refclk, NULL, &crtc_state->dpll)) { |
| 7496 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7497 | return -EINVAL; |
| 7498 | } |
| 7499 | |
| 7500 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7501 | |
| 7502 | return 0; |
| 7503 | } |
| 7504 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7505 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7506 | struct intel_crtc_state *crtc_state) |
| 7507 | { |
| 7508 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7509 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7510 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7511 | int refclk = 96000; |
| 7512 | |
| 7513 | memset(&crtc_state->dpll_hw_state, 0, |
| 7514 | sizeof(crtc_state->dpll_hw_state)); |
| 7515 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7516 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7517 | if (intel_panel_use_ssc(dev_priv)) { |
| 7518 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7519 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7520 | } |
| 7521 | |
| 7522 | if (intel_is_dual_link_lvds(dev)) |
| 7523 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7524 | else |
| 7525 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7526 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7527 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7528 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7529 | } 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] | 7530 | limit = &intel_limits_g4x_sdvo; |
| 7531 | } else { |
| 7532 | /* The option is for other outputs */ |
| 7533 | limit = &intel_limits_i9xx_sdvo; |
| 7534 | } |
| 7535 | |
| 7536 | if (!crtc_state->clock_set && |
| 7537 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7538 | refclk, NULL, &crtc_state->dpll)) { |
| 7539 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7540 | return -EINVAL; |
| 7541 | } |
| 7542 | |
| 7543 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7544 | |
| 7545 | return 0; |
| 7546 | } |
| 7547 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7548 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7549 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7550 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7551 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7552 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7553 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7554 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7555 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7556 | memset(&crtc_state->dpll_hw_state, 0, |
| 7557 | sizeof(crtc_state->dpll_hw_state)); |
| 7558 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7559 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7560 | if (intel_panel_use_ssc(dev_priv)) { |
| 7561 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7562 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7563 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7564 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7565 | limit = &intel_limits_pineview_lvds; |
| 7566 | } else { |
| 7567 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7568 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7569 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7570 | if (!crtc_state->clock_set && |
| 7571 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7572 | refclk, NULL, &crtc_state->dpll)) { |
| 7573 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7574 | return -EINVAL; |
| 7575 | } |
| 7576 | |
| 7577 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7578 | |
| 7579 | return 0; |
| 7580 | } |
| 7581 | |
| 7582 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7583 | struct intel_crtc_state *crtc_state) |
| 7584 | { |
| 7585 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7586 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7587 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7588 | int refclk = 96000; |
| 7589 | |
| 7590 | memset(&crtc_state->dpll_hw_state, 0, |
| 7591 | sizeof(crtc_state->dpll_hw_state)); |
| 7592 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7593 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7594 | if (intel_panel_use_ssc(dev_priv)) { |
| 7595 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7596 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7597 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7598 | |
| 7599 | limit = &intel_limits_i9xx_lvds; |
| 7600 | } else { |
| 7601 | limit = &intel_limits_i9xx_sdvo; |
| 7602 | } |
| 7603 | |
| 7604 | if (!crtc_state->clock_set && |
| 7605 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7606 | refclk, NULL, &crtc_state->dpll)) { |
| 7607 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7608 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7609 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7610 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7611 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7612 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7613 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7614 | } |
| 7615 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7616 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7617 | struct intel_crtc_state *crtc_state) |
| 7618 | { |
| 7619 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7620 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7621 | |
| 7622 | memset(&crtc_state->dpll_hw_state, 0, |
| 7623 | sizeof(crtc_state->dpll_hw_state)); |
| 7624 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7625 | if (!crtc_state->clock_set && |
| 7626 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7627 | refclk, NULL, &crtc_state->dpll)) { |
| 7628 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7629 | return -EINVAL; |
| 7630 | } |
| 7631 | |
| 7632 | chv_compute_dpll(crtc, crtc_state); |
| 7633 | |
| 7634 | return 0; |
| 7635 | } |
| 7636 | |
| 7637 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7638 | struct intel_crtc_state *crtc_state) |
| 7639 | { |
| 7640 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7641 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7642 | |
| 7643 | memset(&crtc_state->dpll_hw_state, 0, |
| 7644 | sizeof(crtc_state->dpll_hw_state)); |
| 7645 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7646 | if (!crtc_state->clock_set && |
| 7647 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7648 | refclk, NULL, &crtc_state->dpll)) { |
| 7649 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7650 | return -EINVAL; |
| 7651 | } |
| 7652 | |
| 7653 | vlv_compute_dpll(crtc, crtc_state); |
| 7654 | |
| 7655 | return 0; |
| 7656 | } |
| 7657 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7658 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7659 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7660 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7661 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7662 | uint32_t tmp; |
| 7663 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7664 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7665 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7666 | return; |
| 7667 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7668 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7669 | if (!(tmp & PFIT_ENABLE)) |
| 7670 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7671 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7672 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7673 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7674 | if (crtc->pipe != PIPE_B) |
| 7675 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7676 | } else { |
| 7677 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7678 | return; |
| 7679 | } |
| 7680 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7681 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7682 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7683 | } |
| 7684 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7685 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7686 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7687 | { |
| 7688 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7689 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7690 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7691 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7692 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7693 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7694 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7695 | /* In case of DSI, DPLL will not be used */ |
| 7696 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7697 | return; |
| 7698 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7699 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7700 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7701 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7702 | |
| 7703 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7704 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7705 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7706 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7707 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7708 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7709 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7710 | } |
| 7711 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7712 | static void |
| 7713 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7714 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7715 | { |
| 7716 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7717 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7718 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7719 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7720 | enum pipe pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7721 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7722 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7723 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7724 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7725 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7726 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7727 | if (!plane->get_hw_state(plane, &pipe)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7728 | return; |
| 7729 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7730 | WARN_ON(pipe != crtc->pipe); |
| 7731 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7732 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7733 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7734 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7735 | return; |
| 7736 | } |
| 7737 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7738 | fb = &intel_fb->base; |
| 7739 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7740 | fb->dev = dev; |
| 7741 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7742 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7743 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7744 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7745 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7746 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7747 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7748 | } |
| 7749 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7750 | |
| 7751 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7752 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 7753 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7754 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 7755 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 7756 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 7757 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 7758 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7759 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7760 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7761 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7762 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 7763 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7764 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7765 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7766 | } |
| 7767 | plane_config->base = base; |
| 7768 | |
| 7769 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7770 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7771 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7772 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7773 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7774 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7775 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 7776 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7777 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7778 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7779 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7780 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7781 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 7782 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7783 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7784 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7785 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7786 | } |
| 7787 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7788 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7789 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7790 | { |
| 7791 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7792 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7793 | int pipe = pipe_config->cpu_transcoder; |
| 7794 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7795 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7796 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7797 | int refclk = 100000; |
| 7798 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7799 | /* In case of DSI, DPLL will not be used */ |
| 7800 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7801 | return; |
| 7802 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7803 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7804 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7805 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7806 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7807 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7808 | 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] | 7809 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7810 | |
| 7811 | 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] | 7812 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 7813 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 7814 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7815 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7816 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7817 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7818 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7819 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7820 | } |
| 7821 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7822 | static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc, |
| 7823 | struct intel_crtc_state *pipe_config) |
| 7824 | { |
| 7825 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7826 | enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB; |
| 7827 | |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 7828 | pipe_config->lspcon_downsampling = false; |
| 7829 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7830 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
| 7831 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 7832 | |
| 7833 | if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) { |
| 7834 | bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE; |
| 7835 | bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 7836 | |
| 7837 | if (ycbcr420_enabled) { |
| 7838 | /* We support 4:2:0 in full blend mode only */ |
| 7839 | if (!blend) |
| 7840 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 7841 | else if (!(IS_GEMINILAKE(dev_priv) || |
| 7842 | INTEL_GEN(dev_priv) >= 10)) |
| 7843 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 7844 | else |
| 7845 | output = INTEL_OUTPUT_FORMAT_YCBCR420; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 7846 | } else { |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 7847 | /* |
| 7848 | * Currently there is no interface defined to |
| 7849 | * check user preference between RGB/YCBCR444 |
| 7850 | * or YCBCR420. So the only possible case for |
| 7851 | * YCBCR444 usage is driving YCBCR420 output |
| 7852 | * with LSPCON, when pipe is configured for |
| 7853 | * YCBCR444 output and LSPCON takes care of |
| 7854 | * downsampling it. |
| 7855 | */ |
| 7856 | pipe_config->lspcon_downsampling = true; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 7857 | output = INTEL_OUTPUT_FORMAT_YCBCR444; |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7858 | } |
| 7859 | } |
| 7860 | } |
| 7861 | |
| 7862 | pipe_config->output_format = output; |
| 7863 | } |
| 7864 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7865 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7866 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7867 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7868 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7869 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7870 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7871 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7872 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7873 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 7874 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7875 | return false; |
| 7876 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 7877 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7878 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 7879 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7880 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7881 | ret = false; |
| 7882 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7883 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7884 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7885 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7886 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7887 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7888 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7889 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7890 | case PIPECONF_6BPC: |
| 7891 | pipe_config->pipe_bpp = 18; |
| 7892 | break; |
| 7893 | case PIPECONF_8BPC: |
| 7894 | pipe_config->pipe_bpp = 24; |
| 7895 | break; |
| 7896 | case PIPECONF_10BPC: |
| 7897 | pipe_config->pipe_bpp = 30; |
| 7898 | break; |
| 7899 | default: |
| 7900 | break; |
| 7901 | } |
| 7902 | } |
| 7903 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7904 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7905 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7906 | pipe_config->limited_color_range = true; |
| 7907 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7908 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 7909 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 7910 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7911 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7912 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7913 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7914 | i9xx_get_pfit_config(crtc, pipe_config); |
| 7915 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7916 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 7917 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7918 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 7919 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 7920 | else |
| 7921 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7922 | pipe_config->pixel_multiplier = |
| 7923 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 7924 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7925 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7926 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7927 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7928 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 7929 | pipe_config->pixel_multiplier = |
| 7930 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 7931 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 7932 | } else { |
| 7933 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 7934 | * port and will be fixed up in the encoder->get_config |
| 7935 | * function. */ |
| 7936 | pipe_config->pixel_multiplier = 1; |
| 7937 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7938 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7939 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7940 | /* |
| 7941 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 7942 | * on 830. Filter it out here so that we don't |
| 7943 | * report errors due to that. |
| 7944 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7945 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7946 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 7947 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7948 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 7949 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 7950 | } else { |
| 7951 | /* Mask out read-only status bits. */ |
| 7952 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 7953 | DPLL_PORTC_READY_MASK | |
| 7954 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7955 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7956 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7957 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7958 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 7959 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7960 | vlv_crtc_clock_get(crtc, pipe_config); |
| 7961 | else |
| 7962 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7963 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 7964 | /* |
| 7965 | * Normally the dotclock is filled in by the encoder .get_config() |
| 7966 | * but in case the pipe is enabled w/o any ports we need a sane |
| 7967 | * default. |
| 7968 | */ |
| 7969 | pipe_config->base.adjusted_mode.crtc_clock = |
| 7970 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 7971 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7972 | ret = true; |
| 7973 | |
| 7974 | out: |
| 7975 | intel_display_power_put(dev_priv, power_domain); |
| 7976 | |
| 7977 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7978 | } |
| 7979 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 7980 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7981 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7982 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7983 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7984 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7985 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7986 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7987 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7988 | bool has_ck505 = false; |
| 7989 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7990 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7991 | |
| 7992 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 7993 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7994 | switch (encoder->type) { |
| 7995 | case INTEL_OUTPUT_LVDS: |
| 7996 | has_panel = true; |
| 7997 | has_lvds = true; |
| 7998 | break; |
| 7999 | case INTEL_OUTPUT_EDP: |
| 8000 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 8001 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8002 | has_cpu_edp = true; |
| 8003 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8004 | default: |
| 8005 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8006 | } |
| 8007 | } |
| 8008 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8009 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8010 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8011 | can_ssc = has_ck505; |
| 8012 | } else { |
| 8013 | has_ck505 = false; |
| 8014 | can_ssc = true; |
| 8015 | } |
| 8016 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8017 | /* Check if any DPLLs are using the SSC source */ |
| 8018 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8019 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8020 | |
| 8021 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8022 | continue; |
| 8023 | |
| 8024 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8025 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8026 | using_ssc_source = true; |
| 8027 | break; |
| 8028 | } |
| 8029 | } |
| 8030 | |
| 8031 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8032 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8033 | |
| 8034 | /* Ironlake: try to setup display ref clock before DPLL |
| 8035 | * enabling. This is only under driver's control after |
| 8036 | * PCH B stepping, previous chipset stepping should be |
| 8037 | * ignoring this setting. |
| 8038 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8039 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8040 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8041 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8042 | * compute the final state we want first and check if we need to |
| 8043 | * make any changes at all. |
| 8044 | */ |
| 8045 | final = val; |
| 8046 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8047 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8048 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8049 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8050 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8051 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8052 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8053 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8054 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8055 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8056 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8057 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8058 | |
| 8059 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8060 | final |= DREF_SSC1_ENABLE; |
| 8061 | |
| 8062 | if (has_cpu_edp) { |
| 8063 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8064 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8065 | else |
| 8066 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8067 | } else |
| 8068 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8069 | } else if (using_ssc_source) { |
| 8070 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8071 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8072 | } |
| 8073 | |
| 8074 | if (final == val) |
| 8075 | return; |
| 8076 | |
| 8077 | /* Always enable nonspread source */ |
| 8078 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8079 | |
| 8080 | if (has_ck505) |
| 8081 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8082 | else |
| 8083 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8084 | |
| 8085 | if (has_panel) { |
| 8086 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8087 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8088 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8089 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8090 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8091 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8092 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8093 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8094 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8095 | |
| 8096 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8097 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8098 | POSTING_READ(PCH_DREF_CONTROL); |
| 8099 | udelay(200); |
| 8100 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8101 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8102 | |
| 8103 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8104 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8105 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8106 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8107 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8108 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8109 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8110 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8111 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8112 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8113 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8114 | POSTING_READ(PCH_DREF_CONTROL); |
| 8115 | udelay(200); |
| 8116 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8117 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8118 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8119 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8120 | |
| 8121 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8122 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8123 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8124 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8125 | POSTING_READ(PCH_DREF_CONTROL); |
| 8126 | udelay(200); |
| 8127 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8128 | if (!using_ssc_source) { |
| 8129 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8130 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8131 | /* Turn off the SSC source */ |
| 8132 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8133 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8134 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8135 | /* Turn off SSC1 */ |
| 8136 | val &= ~DREF_SSC1_ENABLE; |
| 8137 | |
| 8138 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8139 | POSTING_READ(PCH_DREF_CONTROL); |
| 8140 | udelay(200); |
| 8141 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8142 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8143 | |
| 8144 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8145 | } |
| 8146 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8147 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8148 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8149 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8150 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8151 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8152 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8153 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8154 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8155 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8156 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8157 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8158 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8159 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8160 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8161 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8162 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8163 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8164 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8165 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | /* WaMPhyProgramming:hsw */ |
| 8169 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8170 | { |
| 8171 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8172 | |
| 8173 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8174 | tmp &= ~(0xFF << 24); |
| 8175 | tmp |= (0x12 << 24); |
| 8176 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8177 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8178 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8179 | tmp |= (1 << 11); |
| 8180 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8181 | |
| 8182 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8183 | tmp |= (1 << 11); |
| 8184 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8185 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8186 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8187 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8188 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8189 | |
| 8190 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8191 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8192 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8193 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8194 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8195 | tmp &= ~(7 << 13); |
| 8196 | tmp |= (5 << 13); |
| 8197 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8198 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8199 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8200 | tmp &= ~(7 << 13); |
| 8201 | tmp |= (5 << 13); |
| 8202 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8203 | |
| 8204 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8205 | tmp &= ~0xFF; |
| 8206 | tmp |= 0x1C; |
| 8207 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8208 | |
| 8209 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8210 | tmp &= ~0xFF; |
| 8211 | tmp |= 0x1C; |
| 8212 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8213 | |
| 8214 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8215 | tmp &= ~(0xFF << 16); |
| 8216 | tmp |= (0x1C << 16); |
| 8217 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8218 | |
| 8219 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8220 | tmp &= ~(0xFF << 16); |
| 8221 | tmp |= (0x1C << 16); |
| 8222 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8223 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8224 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8225 | tmp |= (1 << 27); |
| 8226 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8227 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8228 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8229 | tmp |= (1 << 27); |
| 8230 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8231 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8232 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8233 | tmp &= ~(0xF << 28); |
| 8234 | tmp |= (4 << 28); |
| 8235 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8236 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8237 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8238 | tmp &= ~(0xF << 28); |
| 8239 | tmp |= (4 << 28); |
| 8240 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8241 | } |
| 8242 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8243 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8244 | * Programming" based on the parameters passed: |
| 8245 | * - Sequence to enable CLKOUT_DP |
| 8246 | * - Sequence to enable CLKOUT_DP without spread |
| 8247 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8248 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8249 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8250 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8251 | { |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8252 | uint32_t reg, tmp; |
| 8253 | |
| 8254 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8255 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8256 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8257 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8258 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8259 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8260 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8261 | |
| 8262 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8263 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8264 | tmp |= SBI_SSCCTL_PATHALT; |
| 8265 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8266 | |
| 8267 | udelay(24); |
| 8268 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8269 | if (with_spread) { |
| 8270 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8271 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8272 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8273 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8274 | if (with_fdi) { |
| 8275 | lpt_reset_fdi_mphy(dev_priv); |
| 8276 | lpt_program_fdi_mphy(dev_priv); |
| 8277 | } |
| 8278 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8279 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8280 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8281 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8282 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8283 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8284 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8285 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8286 | } |
| 8287 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8288 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8289 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8290 | { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8291 | uint32_t reg, tmp; |
| 8292 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8293 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8294 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8295 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8296 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8297 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8298 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8299 | |
| 8300 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8301 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8302 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8303 | tmp |= SBI_SSCCTL_PATHALT; |
| 8304 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8305 | udelay(32); |
| 8306 | } |
| 8307 | tmp |= SBI_SSCCTL_DISABLE; |
| 8308 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8309 | } |
| 8310 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8311 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8312 | } |
| 8313 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8314 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8315 | |
| 8316 | static const uint16_t sscdivintphase[] = { |
| 8317 | [BEND_IDX( 50)] = 0x3B23, |
| 8318 | [BEND_IDX( 45)] = 0x3B23, |
| 8319 | [BEND_IDX( 40)] = 0x3C23, |
| 8320 | [BEND_IDX( 35)] = 0x3C23, |
| 8321 | [BEND_IDX( 30)] = 0x3D23, |
| 8322 | [BEND_IDX( 25)] = 0x3D23, |
| 8323 | [BEND_IDX( 20)] = 0x3E23, |
| 8324 | [BEND_IDX( 15)] = 0x3E23, |
| 8325 | [BEND_IDX( 10)] = 0x3F23, |
| 8326 | [BEND_IDX( 5)] = 0x3F23, |
| 8327 | [BEND_IDX( 0)] = 0x0025, |
| 8328 | [BEND_IDX( -5)] = 0x0025, |
| 8329 | [BEND_IDX(-10)] = 0x0125, |
| 8330 | [BEND_IDX(-15)] = 0x0125, |
| 8331 | [BEND_IDX(-20)] = 0x0225, |
| 8332 | [BEND_IDX(-25)] = 0x0225, |
| 8333 | [BEND_IDX(-30)] = 0x0325, |
| 8334 | [BEND_IDX(-35)] = 0x0325, |
| 8335 | [BEND_IDX(-40)] = 0x0425, |
| 8336 | [BEND_IDX(-45)] = 0x0425, |
| 8337 | [BEND_IDX(-50)] = 0x0525, |
| 8338 | }; |
| 8339 | |
| 8340 | /* |
| 8341 | * Bend CLKOUT_DP |
| 8342 | * steps -50 to 50 inclusive, in steps of 5 |
| 8343 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8344 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8345 | */ |
| 8346 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8347 | { |
| 8348 | uint32_t tmp; |
| 8349 | int idx = BEND_IDX(steps); |
| 8350 | |
| 8351 | if (WARN_ON(steps % 5 != 0)) |
| 8352 | return; |
| 8353 | |
| 8354 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8355 | return; |
| 8356 | |
| 8357 | mutex_lock(&dev_priv->sb_lock); |
| 8358 | |
| 8359 | if (steps % 10 != 0) |
| 8360 | tmp = 0xAAAAAAAB; |
| 8361 | else |
| 8362 | tmp = 0x00000000; |
| 8363 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8364 | |
| 8365 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8366 | tmp &= 0xffff0000; |
| 8367 | tmp |= sscdivintphase[idx]; |
| 8368 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8369 | |
| 8370 | mutex_unlock(&dev_priv->sb_lock); |
| 8371 | } |
| 8372 | |
| 8373 | #undef BEND_IDX |
| 8374 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8375 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8376 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8377 | struct intel_encoder *encoder; |
| 8378 | bool has_vga = false; |
| 8379 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8380 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8381 | switch (encoder->type) { |
| 8382 | case INTEL_OUTPUT_ANALOG: |
| 8383 | has_vga = true; |
| 8384 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8385 | default: |
| 8386 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8387 | } |
| 8388 | } |
| 8389 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8390 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8391 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8392 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8393 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8394 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8395 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8396 | } |
| 8397 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8398 | /* |
| 8399 | * Initialize reference clocks when the driver loads |
| 8400 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8401 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8402 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8403 | 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] | 8404 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8405 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8406 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8407 | } |
| 8408 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8409 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8410 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8411 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8412 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8413 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8414 | uint32_t val; |
| 8415 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8416 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8417 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8418 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8419 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8420 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8421 | break; |
| 8422 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8423 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8424 | break; |
| 8425 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8426 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8427 | break; |
| 8428 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8429 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8430 | break; |
| 8431 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8432 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8433 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8434 | } |
| 8435 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8436 | if (crtc_state->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8437 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8438 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8439 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8440 | val |= PIPECONF_INTERLACED_ILK; |
| 8441 | else |
| 8442 | val |= PIPECONF_PROGRESSIVE; |
| 8443 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8444 | if (crtc_state->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8445 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8446 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8447 | I915_WRITE(PIPECONF(pipe), val); |
| 8448 | POSTING_READ(PIPECONF(pipe)); |
| 8449 | } |
| 8450 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8451 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8452 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8453 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8454 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8455 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8456 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8457 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8458 | if (IS_HASWELL(dev_priv) && crtc_state->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8459 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8460 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8461 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8462 | val |= PIPECONF_INTERLACED_ILK; |
| 8463 | else |
| 8464 | val |= PIPECONF_PROGRESSIVE; |
| 8465 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8466 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8467 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8468 | } |
| 8469 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8470 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state) |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8471 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8472 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8473 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8474 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8475 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8476 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8477 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8478 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8479 | case 18: |
| 8480 | val |= PIPEMISC_DITHER_6_BPC; |
| 8481 | break; |
| 8482 | case 24: |
| 8483 | val |= PIPEMISC_DITHER_8_BPC; |
| 8484 | break; |
| 8485 | case 30: |
| 8486 | val |= PIPEMISC_DITHER_10_BPC; |
| 8487 | break; |
| 8488 | case 36: |
| 8489 | val |= PIPEMISC_DITHER_12_BPC; |
| 8490 | break; |
| 8491 | default: |
| 8492 | /* Case prevented by pipe_config_set_bpp. */ |
| 8493 | BUG(); |
| 8494 | } |
| 8495 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8496 | if (crtc_state->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8497 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8498 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8499 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 8500 | crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8501 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8502 | |
| 8503 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8504 | val |= PIPEMISC_YUV420_ENABLE | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8505 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8506 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8507 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8508 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8509 | } |
| 8510 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8511 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8512 | { |
| 8513 | /* |
| 8514 | * Account for spread spectrum to avoid |
| 8515 | * oversubscribing the link. Max center spread |
| 8516 | * is 2.5%; use 5% for safety's sake. |
| 8517 | */ |
| 8518 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8519 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8520 | } |
| 8521 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8522 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8523 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8524 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8525 | } |
| 8526 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8527 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8528 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8529 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8530 | { |
| 8531 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8532 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8533 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8534 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8535 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8536 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8537 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8538 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8539 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8540 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8541 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8542 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8543 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8544 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8545 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8546 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8547 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8548 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8549 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8550 | fp |= FP_CB_TUNE; |
| 8551 | |
| 8552 | if (reduced_clock) { |
| 8553 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8554 | |
| 8555 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8556 | fp2 |= FP_CB_TUNE; |
| 8557 | } else { |
| 8558 | fp2 = fp; |
| 8559 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8560 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8561 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8562 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8563 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8564 | dpll |= DPLLB_MODE_LVDS; |
| 8565 | else |
| 8566 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8567 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8568 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8569 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8570 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8571 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8572 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8573 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8574 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8575 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8576 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8577 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8578 | /* |
| 8579 | * The high speed IO clock is only really required for |
| 8580 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8581 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8582 | * the clock needlessly does no real harm, except use up a |
| 8583 | * bit of power potentially. |
| 8584 | * |
| 8585 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8586 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8587 | * driving PCH ports at the same time. On SNB we could do this, |
| 8588 | * and potentially avoid enabling the second DPLL, but it's not |
| 8589 | * clear if it''s a win or loss power wise. No point in doing |
| 8590 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8591 | */ |
| 8592 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8593 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8594 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8595 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8596 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8597 | 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] | 8598 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8599 | 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] | 8600 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8601 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8602 | case 5: |
| 8603 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8604 | break; |
| 8605 | case 7: |
| 8606 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8607 | break; |
| 8608 | case 10: |
| 8609 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8610 | break; |
| 8611 | case 14: |
| 8612 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8613 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8614 | } |
| 8615 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8616 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8617 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8618 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8619 | else |
| 8620 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8621 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8622 | dpll |= DPLL_VCO_ENABLE; |
| 8623 | |
| 8624 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8625 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8626 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8627 | } |
| 8628 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8629 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8630 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8631 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8632 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8633 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8634 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8635 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8636 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8637 | memset(&crtc_state->dpll_hw_state, 0, |
| 8638 | sizeof(crtc_state->dpll_hw_state)); |
| 8639 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8640 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8641 | if (!crtc_state->has_pch_encoder) |
| 8642 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8643 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8644 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8645 | if (intel_panel_use_ssc(dev_priv)) { |
| 8646 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8647 | dev_priv->vbt.lvds_ssc_freq); |
| 8648 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8649 | } |
| 8650 | |
| 8651 | if (intel_is_dual_link_lvds(dev)) { |
| 8652 | if (refclk == 100000) |
| 8653 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8654 | else |
| 8655 | limit = &intel_limits_ironlake_dual_lvds; |
| 8656 | } else { |
| 8657 | if (refclk == 100000) |
| 8658 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8659 | else |
| 8660 | limit = &intel_limits_ironlake_single_lvds; |
| 8661 | } |
| 8662 | } else { |
| 8663 | limit = &intel_limits_ironlake_dac; |
| 8664 | } |
| 8665 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8666 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8667 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8668 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8669 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8670 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8671 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8672 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8673 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8674 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8675 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 8676 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 8677 | pipe_name(crtc->pipe)); |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8678 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8679 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8680 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8681 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8682 | } |
| 8683 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8684 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8685 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8686 | { |
| 8687 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8688 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8689 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8690 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8691 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8692 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8693 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8694 | & ~TU_SIZE_MASK; |
| 8695 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8696 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8697 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8698 | } |
| 8699 | |
| 8700 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8701 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8702 | struct intel_link_m_n *m_n, |
| 8703 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8704 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8705 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8706 | enum pipe pipe = crtc->pipe; |
| 8707 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8708 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8709 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8710 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8711 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8712 | & ~TU_SIZE_MASK; |
| 8713 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8714 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8715 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 8716 | |
| 8717 | if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8718 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8719 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8720 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8721 | & ~TU_SIZE_MASK; |
| 8722 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8723 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8724 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8725 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8726 | } else { |
| 8727 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8728 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8729 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8730 | & ~TU_SIZE_MASK; |
| 8731 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8732 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8733 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8734 | } |
| 8735 | } |
| 8736 | |
| 8737 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8738 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8739 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8740 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8741 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8742 | else |
| 8743 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8744 | &pipe_config->dp_m_n, |
| 8745 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8746 | } |
| 8747 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8748 | 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] | 8749 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8750 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8751 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8752 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8753 | } |
| 8754 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8755 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8756 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8757 | { |
| 8758 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8759 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8760 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8761 | uint32_t ps_ctrl = 0; |
| 8762 | int id = -1; |
| 8763 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8764 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8765 | /* find scaler attached to this pipe */ |
| 8766 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8767 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8768 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8769 | id = i; |
| 8770 | pipe_config->pch_pfit.enabled = true; |
| 8771 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8772 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8773 | break; |
| 8774 | } |
| 8775 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8776 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8777 | scaler_state->scaler_id = id; |
| 8778 | if (id >= 0) { |
| 8779 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8780 | } else { |
| 8781 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8782 | } |
| 8783 | } |
| 8784 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8785 | static void |
| 8786 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8787 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8788 | { |
| 8789 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8790 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8791 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 8792 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8793 | enum pipe pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8794 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8795 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8796 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8797 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8798 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8799 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8800 | if (!plane->get_hw_state(plane, &pipe)) |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 8801 | return; |
| 8802 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8803 | WARN_ON(pipe != crtc->pipe); |
| 8804 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8805 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8806 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8807 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8808 | return; |
| 8809 | } |
| 8810 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8811 | fb = &intel_fb->base; |
| 8812 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 8813 | fb->dev = dev; |
| 8814 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8815 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8816 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 8817 | if (INTEL_GEN(dev_priv) >= 11) |
| 8818 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 8819 | else |
| 8820 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8821 | |
| 8822 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8823 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8824 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 8825 | } else { |
| 8826 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 8827 | } |
| 8828 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8829 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8830 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 8831 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8832 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8833 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8834 | switch (tiling) { |
| 8835 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 8836 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8837 | break; |
| 8838 | case PLANE_CTL_TILED_X: |
| 8839 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8840 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8841 | break; |
| 8842 | case PLANE_CTL_TILED_Y: |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 8843 | plane_config->tiling = I915_TILING_Y; |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8844 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8845 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 8846 | else |
| 8847 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8848 | break; |
| 8849 | case PLANE_CTL_TILED_YF: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8850 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8851 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 8852 | else |
| 8853 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8854 | break; |
| 8855 | default: |
| 8856 | MISSING_CASE(tiling); |
| 8857 | goto error; |
| 8858 | } |
| 8859 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8860 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8861 | plane_config->base = base; |
| 8862 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8863 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8864 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8865 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8866 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8867 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8868 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8869 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8870 | stride_mult = intel_fb_stride_alignment(fb, 0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8871 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8872 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8873 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8874 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8875 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8876 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8877 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8878 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 8879 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8880 | plane_config->size); |
| 8881 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8882 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8883 | return; |
| 8884 | |
| 8885 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 8886 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8887 | } |
| 8888 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8889 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8890 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8891 | { |
| 8892 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8893 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8894 | uint32_t tmp; |
| 8895 | |
| 8896 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 8897 | |
| 8898 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 8899 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8900 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 8901 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8902 | |
| 8903 | /* We currently do not free assignements of panel fitters on |
| 8904 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 8905 | * differentiates them) so just WARN about this case for now. */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8906 | if (IS_GEN7(dev_priv)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8907 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 8908 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 8909 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8910 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8911 | } |
| 8912 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8913 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8914 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8915 | { |
| 8916 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8917 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8918 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8919 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8920 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8921 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8922 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8923 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8924 | return false; |
| 8925 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 8926 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8927 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8928 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8929 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8930 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8931 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8932 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8933 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8934 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8935 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8936 | case PIPECONF_6BPC: |
| 8937 | pipe_config->pipe_bpp = 18; |
| 8938 | break; |
| 8939 | case PIPECONF_8BPC: |
| 8940 | pipe_config->pipe_bpp = 24; |
| 8941 | break; |
| 8942 | case PIPECONF_10BPC: |
| 8943 | pipe_config->pipe_bpp = 30; |
| 8944 | break; |
| 8945 | case PIPECONF_12BPC: |
| 8946 | pipe_config->pipe_bpp = 36; |
| 8947 | break; |
| 8948 | default: |
| 8949 | break; |
| 8950 | } |
| 8951 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8952 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8953 | pipe_config->limited_color_range = true; |
| 8954 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8955 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8956 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8957 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8958 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8959 | pipe_config->has_pch_encoder = true; |
| 8960 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8961 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8962 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8963 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8964 | |
| 8965 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8966 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8967 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 8968 | /* |
| 8969 | * The pipe->pch transcoder and pch transcoder->pll |
| 8970 | * mapping is fixed. |
| 8971 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8972 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8973 | } else { |
| 8974 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8975 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8976 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8977 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8978 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8979 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8980 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8981 | pipe_config->shared_dpll = |
| 8982 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 8983 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8984 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 8985 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 8986 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8987 | |
| 8988 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8989 | pipe_config->pixel_multiplier = |
| 8990 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8991 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8992 | |
| 8993 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8994 | } else { |
| 8995 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8996 | } |
| 8997 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8998 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8999 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9000 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9001 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9002 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9003 | ret = true; |
| 9004 | |
| 9005 | out: |
| 9006 | intel_display_power_put(dev_priv, power_domain); |
| 9007 | |
| 9008 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9009 | } |
| 9010 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9011 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9012 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 9013 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9014 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9015 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9016 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9017 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9018 | pipe_name(crtc->pipe)); |
| 9019 | |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 9020 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2), |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 9021 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9022 | 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] | 9023 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9024 | 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] | 9025 | 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] | 9026 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9027 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9028 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9029 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9030 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9031 | 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] | 9032 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9033 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9034 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9035 | 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] | 9036 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9037 | /* |
| 9038 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9039 | * interrupts remain enabled. We used to check for that, but since it's |
| 9040 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9041 | * the interrupts, the check below should be enough. |
| 9042 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9043 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9044 | } |
| 9045 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9046 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9047 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9048 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9049 | return I915_READ(D_COMP_HSW); |
| 9050 | else |
| 9051 | return I915_READ(D_COMP_BDW); |
| 9052 | } |
| 9053 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9054 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9055 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9056 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9057 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9058 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9059 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 9060 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9061 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9062 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9063 | I915_WRITE(D_COMP_BDW, val); |
| 9064 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9065 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9066 | } |
| 9067 | |
| 9068 | /* |
| 9069 | * This function implements pieces of two sequences from BSpec: |
| 9070 | * - Sequence for display software to disable LCPLL |
| 9071 | * - Sequence for display software to allow package C8+ |
| 9072 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9073 | * register. Callers should take care of disabling all the display engine |
| 9074 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9075 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9076 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9077 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9078 | { |
| 9079 | uint32_t val; |
| 9080 | |
| 9081 | assert_can_disable_lcpll(dev_priv); |
| 9082 | |
| 9083 | val = I915_READ(LCPLL_CTL); |
| 9084 | |
| 9085 | if (switch_to_fclk) { |
| 9086 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9087 | I915_WRITE(LCPLL_CTL, val); |
| 9088 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9089 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9090 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9091 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9092 | |
| 9093 | val = I915_READ(LCPLL_CTL); |
| 9094 | } |
| 9095 | |
| 9096 | val |= LCPLL_PLL_DISABLE; |
| 9097 | I915_WRITE(LCPLL_CTL, val); |
| 9098 | POSTING_READ(LCPLL_CTL); |
| 9099 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 9100 | 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] | 9101 | DRM_ERROR("LCPLL still locked\n"); |
| 9102 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9103 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9104 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9105 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9106 | ndelay(100); |
| 9107 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9108 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9109 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9110 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9111 | |
| 9112 | if (allow_power_down) { |
| 9113 | val = I915_READ(LCPLL_CTL); |
| 9114 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9115 | I915_WRITE(LCPLL_CTL, val); |
| 9116 | POSTING_READ(LCPLL_CTL); |
| 9117 | } |
| 9118 | } |
| 9119 | |
| 9120 | /* |
| 9121 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9122 | * source. |
| 9123 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9124 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9125 | { |
| 9126 | uint32_t val; |
| 9127 | |
| 9128 | val = I915_READ(LCPLL_CTL); |
| 9129 | |
| 9130 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9131 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9132 | return; |
| 9133 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9134 | /* |
| 9135 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9136 | * 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] | 9137 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9138 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9139 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9140 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9141 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9142 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9143 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9144 | } |
| 9145 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9146 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9147 | val |= D_COMP_COMP_FORCE; |
| 9148 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9149 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9150 | |
| 9151 | val = I915_READ(LCPLL_CTL); |
| 9152 | val &= ~LCPLL_PLL_DISABLE; |
| 9153 | I915_WRITE(LCPLL_CTL, val); |
| 9154 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9155 | if (intel_wait_for_register(dev_priv, |
| 9156 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9157 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9158 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9159 | |
| 9160 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9161 | val = I915_READ(LCPLL_CTL); |
| 9162 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9163 | I915_WRITE(LCPLL_CTL, val); |
| 9164 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9165 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9166 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9167 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9168 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9169 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9170 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9171 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9172 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9173 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9174 | } |
| 9175 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9176 | /* |
| 9177 | * Package states C8 and deeper are really deep PC states that can only be |
| 9178 | * reached when all the devices on the system allow it, so even if the graphics |
| 9179 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9180 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9181 | * |
| 9182 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9183 | * well is disabled and most interrupts are disabled, and these are also |
| 9184 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9185 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9186 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9187 | * hang the machine. |
| 9188 | * |
| 9189 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9190 | * the state of some registers, so when we come back from PC8+ we need to |
| 9191 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9192 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9193 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9194 | * because of the runtime PM support). |
| 9195 | * |
| 9196 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9197 | * documentation. |
| 9198 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9199 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9200 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9201 | uint32_t val; |
| 9202 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9203 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9204 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9205 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9206 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9207 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9208 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9209 | } |
| 9210 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9211 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9212 | hsw_disable_lcpll(dev_priv, true, true); |
| 9213 | } |
| 9214 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9215 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9216 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9217 | uint32_t val; |
| 9218 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9219 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9220 | |
| 9221 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9222 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9223 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9224 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9225 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9226 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9227 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9228 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9229 | } |
| 9230 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9231 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9232 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9233 | { |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9234 | struct intel_atomic_state *state = |
| 9235 | to_intel_atomic_state(crtc_state->base.state); |
| 9236 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9237 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9238 | struct intel_encoder *encoder = |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9239 | intel_get_crtc_new_encoder(state, crtc_state); |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9240 | |
| 9241 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 9242 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 9243 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9244 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9245 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9246 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9247 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9248 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9249 | } |
| 9250 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9251 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9252 | enum port port, |
| 9253 | struct intel_crtc_state *pipe_config) |
| 9254 | { |
| 9255 | enum intel_dpll_id id; |
| 9256 | u32 temp; |
| 9257 | |
| 9258 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9259 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9260 | |
| 9261 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9262 | return; |
| 9263 | |
| 9264 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9265 | } |
| 9266 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9267 | static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9268 | enum port port, |
| 9269 | struct intel_crtc_state *pipe_config) |
| 9270 | { |
| 9271 | enum intel_dpll_id id; |
| 9272 | u32 temp; |
| 9273 | |
| 9274 | /* TODO: TBT pll not implemented. */ |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9275 | if (intel_port_is_combophy(dev_priv, port)) { |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9276 | temp = I915_READ(DPCLKA_CFGCR0_ICL) & |
| 9277 | DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
| 9278 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
| 9279 | |
Vandita Kulkarni | a54270d | 2018-10-03 12:52:00 +0530 | [diff] [blame] | 9280 | if (WARN_ON(!intel_dpll_is_combophy(id))) |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9281 | return; |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9282 | } else if (intel_port_is_tc(dev_priv, port)) { |
Vandita Kulkarni | cb6caf7 | 2018-10-03 12:51:58 +0530 | [diff] [blame] | 9283 | id = icl_port_to_mg_pll_id(port); |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9284 | } else { |
| 9285 | WARN(1, "Invalid port %x\n", port); |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9286 | return; |
| 9287 | } |
| 9288 | |
| 9289 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9290 | } |
| 9291 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9292 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9293 | enum port port, |
| 9294 | struct intel_crtc_state *pipe_config) |
| 9295 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9296 | enum intel_dpll_id id; |
| 9297 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9298 | switch (port) { |
| 9299 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9300 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9301 | break; |
| 9302 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9303 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9304 | break; |
| 9305 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9306 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9307 | break; |
| 9308 | default: |
| 9309 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9310 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9311 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9312 | |
| 9313 | 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] | 9314 | } |
| 9315 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9316 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9317 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9318 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9319 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9320 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9321 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9322 | |
| 9323 | 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] | 9324 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9325 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9326 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9327 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9328 | |
| 9329 | 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] | 9330 | } |
| 9331 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9332 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9333 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9334 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9335 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9336 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9337 | 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] | 9338 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9339 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9340 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9341 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9342 | break; |
| 9343 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9344 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9345 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9346 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9347 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9348 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9349 | case PORT_CLK_SEL_LCPLL_810: |
| 9350 | id = DPLL_ID_LCPLL_810; |
| 9351 | break; |
| 9352 | case PORT_CLK_SEL_LCPLL_1350: |
| 9353 | id = DPLL_ID_LCPLL_1350; |
| 9354 | break; |
| 9355 | case PORT_CLK_SEL_LCPLL_2700: |
| 9356 | id = DPLL_ID_LCPLL_2700; |
| 9357 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9358 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9359 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9360 | /* fall through */ |
| 9361 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9362 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9363 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9364 | |
| 9365 | 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] | 9366 | } |
| 9367 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9368 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9369 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9370 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9371 | { |
| 9372 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9373 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9374 | enum intel_display_power_domain power_domain; |
| 9375 | u32 tmp; |
| 9376 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9377 | /* |
| 9378 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
| 9379 | * transcoder handled below. |
| 9380 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9381 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9382 | |
| 9383 | /* |
| 9384 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9385 | * consistency and less surprising code; it's in always on power). |
| 9386 | */ |
| 9387 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9388 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9389 | enum pipe trans_edp_pipe; |
| 9390 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9391 | default: |
| 9392 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 9393 | /* fall through */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9394 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9395 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9396 | trans_edp_pipe = PIPE_A; |
| 9397 | break; |
| 9398 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9399 | trans_edp_pipe = PIPE_B; |
| 9400 | break; |
| 9401 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9402 | trans_edp_pipe = PIPE_C; |
| 9403 | break; |
| 9404 | } |
| 9405 | |
| 9406 | if (trans_edp_pipe == crtc->pipe) |
| 9407 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9408 | } |
| 9409 | |
| 9410 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9411 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9412 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9413 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9414 | |
| 9415 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9416 | |
| 9417 | return tmp & PIPECONF_ENABLE; |
| 9418 | } |
| 9419 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9420 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9421 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9422 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9423 | { |
| 9424 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9425 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9426 | enum intel_display_power_domain power_domain; |
| 9427 | enum port port; |
| 9428 | enum transcoder cpu_transcoder; |
| 9429 | u32 tmp; |
| 9430 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9431 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9432 | if (port == PORT_A) |
| 9433 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9434 | else |
| 9435 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9436 | |
| 9437 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9438 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9439 | continue; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9440 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9441 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9442 | /* |
| 9443 | * The PLL needs to be enabled with a valid divider |
| 9444 | * configuration, otherwise accessing DSI registers will hang |
| 9445 | * the machine. See BSpec North Display Engine |
| 9446 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9447 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9448 | */ |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 9449 | if (!bxt_dsi_pll_is_enabled(dev_priv)) |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9450 | break; |
| 9451 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9452 | /* XXX: this works for video mode only */ |
| 9453 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9454 | if (!(tmp & DPI_ENABLE)) |
| 9455 | continue; |
| 9456 | |
| 9457 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9458 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9459 | continue; |
| 9460 | |
| 9461 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9462 | break; |
| 9463 | } |
| 9464 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9465 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9466 | } |
| 9467 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9468 | 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] | 9469 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9470 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9471 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9472 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9473 | enum port port; |
| 9474 | uint32_t tmp; |
| 9475 | |
| 9476 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9477 | |
| 9478 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9479 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9480 | if (IS_ICELAKE(dev_priv)) |
| 9481 | icelake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9482 | else if (IS_CANNONLAKE(dev_priv)) |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9483 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9484 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9485 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9486 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9487 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9488 | else |
| 9489 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9490 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9491 | pll = pipe_config->shared_dpll; |
| 9492 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9493 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9494 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9495 | } |
| 9496 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9497 | /* |
| 9498 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9499 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9500 | * the PCH transcoder is on. |
| 9501 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9502 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9503 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9504 | pipe_config->has_pch_encoder = true; |
| 9505 | |
| 9506 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9507 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9508 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9509 | |
| 9510 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9511 | } |
| 9512 | } |
| 9513 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9514 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9515 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9516 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9517 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9518 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9519 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9520 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9521 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9522 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9523 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9524 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9525 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9526 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9527 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9528 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9529 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9530 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9531 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9532 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9533 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9534 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9535 | WARN_ON(active); |
| 9536 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9537 | } |
| 9538 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9539 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9540 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9541 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9542 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9543 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9544 | intel_get_pipe_timings(crtc, pipe_config); |
| 9545 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9546 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9547 | intel_get_pipe_src_size(crtc, pipe_config); |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 9548 | intel_get_crtc_ycbcr_config(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9549 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9550 | pipe_config->gamma_mode = |
| 9551 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9552 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9553 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9554 | 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] | 9555 | power_domain_mask |= BIT_ULL(power_domain); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9556 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9557 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9558 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9559 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9560 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9561 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9562 | if (hsw_crtc_supports_ips(crtc)) { |
| 9563 | if (IS_HASWELL(dev_priv)) |
| 9564 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9565 | else { |
| 9566 | /* |
| 9567 | * We cannot readout IPS state on broadwell, set to |
| 9568 | * true so we can set it to a defined state on first |
| 9569 | * commit. |
| 9570 | */ |
| 9571 | pipe_config->ips_enabled = true; |
| 9572 | } |
| 9573 | } |
| 9574 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9575 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9576 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9577 | pipe_config->pixel_multiplier = |
| 9578 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9579 | } else { |
| 9580 | pipe_config->pixel_multiplier = 1; |
| 9581 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9582 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9583 | out: |
| 9584 | for_each_power_domain(power_domain, power_domain_mask) |
| 9585 | intel_display_power_put(dev_priv, power_domain); |
| 9586 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9587 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9588 | } |
| 9589 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9590 | 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] | 9591 | { |
| 9592 | struct drm_i915_private *dev_priv = |
| 9593 | to_i915(plane_state->base.plane->dev); |
| 9594 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9595 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9596 | u32 base; |
| 9597 | |
| 9598 | if (INTEL_INFO(dev_priv)->cursor_needs_physical) |
| 9599 | base = obj->phys_handle->busaddr; |
| 9600 | else |
| 9601 | base = intel_plane_ggtt_offset(plane_state); |
| 9602 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 9603 | base += plane_state->color_plane[0].offset; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9604 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9605 | /* ILK+ do this automagically */ |
| 9606 | if (HAS_GMCH_DISPLAY(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9607 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9608 | base += (plane_state->base.crtc_h * |
| 9609 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9610 | |
| 9611 | return base; |
| 9612 | } |
| 9613 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9614 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9615 | { |
| 9616 | int x = plane_state->base.crtc_x; |
| 9617 | int y = plane_state->base.crtc_y; |
| 9618 | u32 pos = 0; |
| 9619 | |
| 9620 | if (x < 0) { |
| 9621 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9622 | x = -x; |
| 9623 | } |
| 9624 | pos |= x << CURSOR_X_SHIFT; |
| 9625 | |
| 9626 | if (y < 0) { |
| 9627 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9628 | y = -y; |
| 9629 | } |
| 9630 | pos |= y << CURSOR_Y_SHIFT; |
| 9631 | |
| 9632 | return pos; |
| 9633 | } |
| 9634 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9635 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9636 | { |
| 9637 | const struct drm_mode_config *config = |
| 9638 | &plane_state->base.plane->dev->mode_config; |
| 9639 | int width = plane_state->base.crtc_w; |
| 9640 | int height = plane_state->base.crtc_h; |
| 9641 | |
| 9642 | return width > 0 && width <= config->cursor_width && |
| 9643 | height > 0 && height <= config->cursor_height; |
| 9644 | } |
| 9645 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9646 | static int intel_cursor_check_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9647 | { |
| 9648 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9649 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9650 | int src_x, src_y; |
| 9651 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9652 | int ret; |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9653 | |
| 9654 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
| 9655 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 9656 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9657 | ret = intel_plane_check_stride(plane_state); |
| 9658 | if (ret) |
| 9659 | return ret; |
| 9660 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9661 | src_x = plane_state->base.src_x >> 16; |
| 9662 | src_y = plane_state->base.src_y >> 16; |
| 9663 | |
| 9664 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 9665 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 9666 | plane_state, 0); |
| 9667 | |
| 9668 | if (src_x != 0 || src_y != 0) { |
| 9669 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 9670 | return -EINVAL; |
| 9671 | } |
| 9672 | |
| 9673 | plane_state->color_plane[0].offset = offset; |
| 9674 | |
| 9675 | return 0; |
| 9676 | } |
| 9677 | |
| 9678 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 9679 | struct intel_plane_state *plane_state) |
| 9680 | { |
| 9681 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9682 | int ret; |
| 9683 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9684 | if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 9685 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 9686 | return -EINVAL; |
| 9687 | } |
| 9688 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9689 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 9690 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9691 | DRM_PLANE_HELPER_NO_SCALING, |
| 9692 | DRM_PLANE_HELPER_NO_SCALING, |
| 9693 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9694 | if (ret) |
| 9695 | return ret; |
| 9696 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9697 | if (!plane_state->base.visible) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9698 | return 0; |
| 9699 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9700 | ret = intel_plane_check_src_coordinates(plane_state); |
| 9701 | if (ret) |
| 9702 | return ret; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9703 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9704 | ret = intel_cursor_check_surface(plane_state); |
| 9705 | if (ret) |
| 9706 | return ret; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9707 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9708 | return 0; |
| 9709 | } |
| 9710 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 9711 | static unsigned int |
| 9712 | i845_cursor_max_stride(struct intel_plane *plane, |
| 9713 | u32 pixel_format, u64 modifier, |
| 9714 | unsigned int rotation) |
| 9715 | { |
| 9716 | return 2048; |
| 9717 | } |
| 9718 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9719 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9720 | const struct intel_plane_state *plane_state) |
| 9721 | { |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9722 | return CURSOR_ENABLE | |
| 9723 | CURSOR_GAMMA_ENABLE | |
| 9724 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9725 | CURSOR_STRIDE(plane_state->color_plane[0].stride); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9726 | } |
| 9727 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9728 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9729 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9730 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9731 | |
| 9732 | /* |
| 9733 | * 845g/865g are only limited by the width of their cursors, |
| 9734 | * the height is arbitrary up to the precision of the register. |
| 9735 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9736 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9737 | } |
| 9738 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9739 | static int i845_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9740 | struct intel_plane_state *plane_state) |
| 9741 | { |
| 9742 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9743 | int ret; |
| 9744 | |
| 9745 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9746 | if (ret) |
| 9747 | return ret; |
| 9748 | |
| 9749 | /* 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] | 9750 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9751 | return 0; |
| 9752 | |
| 9753 | /* Check for which cursor types we support */ |
| 9754 | if (!i845_cursor_size_ok(plane_state)) { |
| 9755 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9756 | plane_state->base.crtc_w, |
| 9757 | plane_state->base.crtc_h); |
| 9758 | return -EINVAL; |
| 9759 | } |
| 9760 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9761 | WARN_ON(plane_state->base.visible && |
| 9762 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 9763 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9764 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9765 | case 256: |
| 9766 | case 512: |
| 9767 | case 1024: |
| 9768 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9769 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9770 | default: |
| 9771 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 9772 | fb->pitches[0]); |
| 9773 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9774 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9775 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9776 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 9777 | |
| 9778 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9779 | } |
| 9780 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9781 | static void i845_update_cursor(struct intel_plane *plane, |
| 9782 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9783 | const struct intel_plane_state *plane_state) |
| 9784 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9785 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9786 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 9787 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9788 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 9789 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9790 | unsigned int width = plane_state->base.crtc_w; |
| 9791 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9792 | |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 9793 | cntl = plane_state->ctl; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9794 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9795 | |
| 9796 | base = intel_cursor_base(plane_state); |
| 9797 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9798 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9799 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9800 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 9801 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9802 | /* On these chipsets we can only modify the base/size/stride |
| 9803 | * whilst the cursor is disabled. |
| 9804 | */ |
| 9805 | if (plane->cursor.base != base || |
| 9806 | plane->cursor.size != size || |
| 9807 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9808 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9809 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9810 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9811 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9812 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9813 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9814 | plane->cursor.base = base; |
| 9815 | plane->cursor.size = size; |
| 9816 | plane->cursor.cntl = cntl; |
| 9817 | } else { |
| 9818 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9819 | } |
| 9820 | |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9821 | POSTING_READ_FW(CURCNTR(PIPE_A)); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9822 | |
| 9823 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 9824 | } |
| 9825 | |
| 9826 | static void i845_disable_cursor(struct intel_plane *plane, |
| 9827 | struct intel_crtc *crtc) |
| 9828 | { |
| 9829 | i845_update_cursor(plane, NULL, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9830 | } |
| 9831 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9832 | static bool i845_cursor_get_hw_state(struct intel_plane *plane, |
| 9833 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9834 | { |
| 9835 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9836 | enum intel_display_power_domain power_domain; |
| 9837 | bool ret; |
| 9838 | |
| 9839 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
| 9840 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9841 | return false; |
| 9842 | |
| 9843 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 9844 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9845 | *pipe = PIPE_A; |
| 9846 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9847 | intel_display_power_put(dev_priv, power_domain); |
| 9848 | |
| 9849 | return ret; |
| 9850 | } |
| 9851 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 9852 | static unsigned int |
| 9853 | i9xx_cursor_max_stride(struct intel_plane *plane, |
| 9854 | u32 pixel_format, u64 modifier, |
| 9855 | unsigned int rotation) |
| 9856 | { |
| 9857 | return plane->base.dev->mode_config.cursor_width * 4; |
| 9858 | } |
| 9859 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9860 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9861 | const struct intel_plane_state *plane_state) |
| 9862 | { |
| 9863 | struct drm_i915_private *dev_priv = |
| 9864 | to_i915(plane_state->base.plane->dev); |
| 9865 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9866 | u32 cntl = 0; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9867 | |
Ville Syrjälä | e876b78 | 2018-01-30 22:38:05 +0200 | [diff] [blame] | 9868 | if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
| 9869 | cntl |= MCURSOR_TRICKLE_FEED_DISABLE; |
| 9870 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9871 | if (INTEL_GEN(dev_priv) <= 10) { |
| 9872 | cntl |= MCURSOR_GAMMA_ENABLE; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9873 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9874 | if (HAS_DDI(dev_priv)) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9875 | cntl |= MCURSOR_PIPE_CSC_ENABLE; |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9876 | } |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9877 | |
Ville Syrjälä | 32ea06b | 2018-01-30 22:38:01 +0200 | [diff] [blame] | 9878 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 9879 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9880 | |
| 9881 | switch (plane_state->base.crtc_w) { |
| 9882 | case 64: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9883 | cntl |= MCURSOR_MODE_64_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9884 | break; |
| 9885 | case 128: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9886 | cntl |= MCURSOR_MODE_128_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9887 | break; |
| 9888 | case 256: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9889 | cntl |= MCURSOR_MODE_256_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9890 | break; |
| 9891 | default: |
| 9892 | MISSING_CASE(plane_state->base.crtc_w); |
| 9893 | return 0; |
| 9894 | } |
| 9895 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 9896 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9897 | cntl |= MCURSOR_ROTATE_180; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9898 | |
| 9899 | return cntl; |
| 9900 | } |
| 9901 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9902 | 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] | 9903 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9904 | struct drm_i915_private *dev_priv = |
| 9905 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9906 | int width = plane_state->base.crtc_w; |
| 9907 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9908 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9909 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9910 | return false; |
| 9911 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9912 | /* Cursor width is limited to a few power-of-two sizes */ |
| 9913 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9914 | case 256: |
| 9915 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9916 | case 64: |
| 9917 | break; |
| 9918 | default: |
| 9919 | return false; |
| 9920 | } |
| 9921 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9922 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9923 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 9924 | * height from 8 lines up to the cursor width, when the |
| 9925 | * cursor is not rotated. Everything else requires square |
| 9926 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9927 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9928 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9929 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9930 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9931 | return false; |
| 9932 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9933 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9934 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9935 | } |
| 9936 | |
| 9937 | return true; |
| 9938 | } |
| 9939 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9940 | static int i9xx_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9941 | struct intel_plane_state *plane_state) |
| 9942 | { |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9943 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9944 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9945 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9946 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9947 | int ret; |
| 9948 | |
| 9949 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9950 | if (ret) |
| 9951 | return ret; |
| 9952 | |
| 9953 | /* 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] | 9954 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9955 | return 0; |
| 9956 | |
| 9957 | /* Check for which cursor types we support */ |
| 9958 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 9959 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9960 | plane_state->base.crtc_w, |
| 9961 | plane_state->base.crtc_h); |
| 9962 | return -EINVAL; |
| 9963 | } |
| 9964 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9965 | WARN_ON(plane_state->base.visible && |
| 9966 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 9967 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9968 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 9969 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 9970 | fb->pitches[0], plane_state->base.crtc_w); |
| 9971 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9972 | } |
| 9973 | |
| 9974 | /* |
| 9975 | * There's something wrong with the cursor on CHV pipe C. |
| 9976 | * If it straddles the left edge of the screen then |
| 9977 | * moving it away from the edge or disabling it often |
| 9978 | * results in a pipe underrun, and often that can lead to |
| 9979 | * dead pipe (constant underrun reported, and it scans |
| 9980 | * out just a solid color). To recover from that, the |
| 9981 | * display power well must be turned off and on again. |
| 9982 | * Refuse the put the cursor into that compromised position. |
| 9983 | */ |
| 9984 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 9985 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 9986 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 9987 | return -EINVAL; |
| 9988 | } |
| 9989 | |
| 9990 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 9991 | |
| 9992 | return 0; |
| 9993 | } |
| 9994 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9995 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 9996 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 9997 | const struct intel_plane_state *plane_state) |
| 9998 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9999 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10000 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10001 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10002 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10003 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10004 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 10005 | cntl = plane_state->ctl; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10006 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10007 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 10008 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 10009 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10010 | base = intel_cursor_base(plane_state); |
| 10011 | pos = intel_cursor_position(plane_state); |
| 10012 | } |
| 10013 | |
| 10014 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10015 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10016 | /* |
| 10017 | * On some platforms writing CURCNTR first will also |
| 10018 | * cause CURPOS to be armed by the CURBASE write. |
| 10019 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10020 | * arm itself. Thus we always start the full update |
| 10021 | * with a CURCNTR write. |
| 10022 | * |
| 10023 | * On other platforms CURPOS always requires the |
| 10024 | * CURBASE write to arm the update. Additonally |
| 10025 | * a write to any of the cursor register will cancel |
| 10026 | * an already armed cursor update. Thus leaving out |
| 10027 | * the CURBASE write after CURPOS could lead to a |
| 10028 | * cursor that doesn't appear to move, or even change |
| 10029 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10030 | * |
| 10031 | * CURCNTR and CUR_FBC_CTL are always |
| 10032 | * armed by the CURBASE write only. |
| 10033 | */ |
| 10034 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10035 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10036 | plane->cursor.cntl != cntl) { |
| 10037 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
| 10038 | if (HAS_CUR_FBC(dev_priv)) |
| 10039 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
| 10040 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10041 | I915_WRITE_FW(CURBASE(pipe), base); |
| 10042 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10043 | plane->cursor.base = base; |
| 10044 | plane->cursor.size = fbc_ctl; |
| 10045 | plane->cursor.cntl = cntl; |
| 10046 | } else { |
| 10047 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10048 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10049 | } |
| 10050 | |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10051 | POSTING_READ_FW(CURBASE(pipe)); |
| 10052 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10053 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10054 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10055 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10056 | static void i9xx_disable_cursor(struct intel_plane *plane, |
| 10057 | struct intel_crtc *crtc) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10058 | { |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10059 | i9xx_update_cursor(plane, NULL, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10060 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 10061 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10062 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane, |
| 10063 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10064 | { |
| 10065 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10066 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10067 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10068 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10069 | |
| 10070 | /* |
| 10071 | * Not 100% correct for planes that can move between pipes, |
| 10072 | * but that's only the case for gen2-3 which don't have any |
| 10073 | * display power wells. |
| 10074 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10075 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10076 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10077 | return false; |
| 10078 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10079 | val = I915_READ(CURCNTR(plane->pipe)); |
| 10080 | |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10081 | ret = val & MCURSOR_MODE; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10082 | |
| 10083 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 10084 | *pipe = plane->pipe; |
| 10085 | else |
| 10086 | *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >> |
| 10087 | MCURSOR_PIPE_SELECT_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10088 | |
| 10089 | intel_display_power_put(dev_priv, power_domain); |
| 10090 | |
| 10091 | return ret; |
| 10092 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10093 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10094 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10095 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10096 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10097 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10098 | }; |
| 10099 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10100 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10101 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 10102 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10103 | { |
| 10104 | struct intel_framebuffer *intel_fb; |
| 10105 | int ret; |
| 10106 | |
| 10107 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10108 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10109 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10110 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10111 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10112 | if (ret) |
| 10113 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10114 | |
| 10115 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10116 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10117 | err: |
| 10118 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10119 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10120 | } |
| 10121 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10122 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 10123 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10124 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10125 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10126 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10127 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10128 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10129 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10130 | if (ret) |
| 10131 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10132 | |
| 10133 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 10134 | if (plane_state->crtc != crtc) |
| 10135 | continue; |
| 10136 | |
| 10137 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 10138 | if (ret) |
| 10139 | return ret; |
| 10140 | |
| 10141 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 10142 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10143 | |
| 10144 | return 0; |
| 10145 | } |
| 10146 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10147 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10148 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10149 | struct intel_load_detect_pipe *old, |
| 10150 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10151 | { |
| 10152 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10153 | struct intel_encoder *intel_encoder = |
| 10154 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10155 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10156 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10157 | struct drm_crtc *crtc = NULL; |
| 10158 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10159 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10160 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10161 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10162 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10163 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10164 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10165 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10166 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10167 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10168 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10169 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10170 | old->restore_state = NULL; |
| 10171 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10172 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10173 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10174 | /* |
| 10175 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10176 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10177 | * - if the connector already has an assigned crtc, use it (but make |
| 10178 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10179 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10180 | * - try to find the first unused crtc that can drive this connector, |
| 10181 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10182 | */ |
| 10183 | |
| 10184 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10185 | if (connector->state->crtc) { |
| 10186 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10187 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10188 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10189 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10190 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10191 | |
| 10192 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10193 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10194 | } |
| 10195 | |
| 10196 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10197 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10198 | i++; |
| 10199 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10200 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10201 | |
| 10202 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10203 | if (ret) |
| 10204 | goto fail; |
| 10205 | |
| 10206 | if (possible_crtc->state->enable) { |
| 10207 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10208 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10209 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10210 | |
| 10211 | crtc = possible_crtc; |
| 10212 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10213 | } |
| 10214 | |
| 10215 | /* |
| 10216 | * If we didn't find an unused CRTC, don't use any. |
| 10217 | */ |
| 10218 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10219 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10220 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10221 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10222 | } |
| 10223 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10224 | found: |
| 10225 | intel_crtc = to_intel_crtc(crtc); |
| 10226 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10227 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10228 | restore_state = drm_atomic_state_alloc(dev); |
| 10229 | if (!state || !restore_state) { |
| 10230 | ret = -ENOMEM; |
| 10231 | goto fail; |
| 10232 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10233 | |
| 10234 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10235 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10236 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10237 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10238 | if (IS_ERR(connector_state)) { |
| 10239 | ret = PTR_ERR(connector_state); |
| 10240 | goto fail; |
| 10241 | } |
| 10242 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10243 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10244 | if (ret) |
| 10245 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10246 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10247 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10248 | if (IS_ERR(crtc_state)) { |
| 10249 | ret = PTR_ERR(crtc_state); |
| 10250 | goto fail; |
| 10251 | } |
| 10252 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10253 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10254 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10255 | if (!mode) |
| 10256 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10257 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10258 | 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] | 10259 | if (ret) |
| 10260 | goto fail; |
| 10261 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10262 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10263 | if (ret) |
| 10264 | goto fail; |
| 10265 | |
| 10266 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10267 | if (!ret) |
| 10268 | 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] | 10269 | if (!ret) |
| 10270 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10271 | if (ret) { |
| 10272 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10273 | goto fail; |
| 10274 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10275 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10276 | ret = drm_atomic_commit(state); |
| 10277 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10278 | 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] | 10279 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10280 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10281 | |
| 10282 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10283 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10284 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10285 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10286 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10287 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10288 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10289 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10290 | if (state) { |
| 10291 | drm_atomic_state_put(state); |
| 10292 | state = NULL; |
| 10293 | } |
| 10294 | if (restore_state) { |
| 10295 | drm_atomic_state_put(restore_state); |
| 10296 | restore_state = NULL; |
| 10297 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10298 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10299 | if (ret == -EDEADLK) |
| 10300 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10301 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10302 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10303 | } |
| 10304 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10305 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10306 | struct intel_load_detect_pipe *old, |
| 10307 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10308 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10309 | struct intel_encoder *intel_encoder = |
| 10310 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10311 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10312 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10313 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10314 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10315 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10316 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10317 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10318 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10319 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10320 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10321 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10322 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10323 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10324 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10325 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10326 | } |
| 10327 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10328 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10329 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10330 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10331 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10332 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10333 | |
| 10334 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10335 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10336 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10337 | return 120000; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 10338 | else if (!IS_GEN2(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10339 | return 96000; |
| 10340 | else |
| 10341 | return 48000; |
| 10342 | } |
| 10343 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10344 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10345 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10346 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10347 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10348 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10349 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10350 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10351 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10352 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10353 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10354 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10355 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10356 | |
| 10357 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10358 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10359 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10360 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10361 | |
| 10362 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10363 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10364 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10365 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10366 | } else { |
| 10367 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10368 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10369 | } |
| 10370 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 10371 | if (!IS_GEN2(dev_priv)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10372 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10373 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10374 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10375 | else |
| 10376 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10377 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10378 | |
| 10379 | switch (dpll & DPLL_MODE_MASK) { |
| 10380 | case DPLLB_MODE_DAC_SERIAL: |
| 10381 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10382 | 5 : 10; |
| 10383 | break; |
| 10384 | case DPLLB_MODE_LVDS: |
| 10385 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10386 | 7 : 14; |
| 10387 | break; |
| 10388 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10389 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10390 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10391 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10392 | } |
| 10393 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10394 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10395 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10396 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10397 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10398 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10399 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10400 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10401 | |
| 10402 | if (is_lvds) { |
| 10403 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10404 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10405 | |
| 10406 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10407 | clock.p2 = 7; |
| 10408 | else |
| 10409 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10410 | } else { |
| 10411 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10412 | clock.p1 = 2; |
| 10413 | else { |
| 10414 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10415 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10416 | } |
| 10417 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10418 | clock.p2 = 4; |
| 10419 | else |
| 10420 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10421 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10422 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10423 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10424 | } |
| 10425 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10426 | /* |
| 10427 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10428 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10429 | * encoder's get_config() function. |
| 10430 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10431 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10432 | } |
| 10433 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10434 | int intel_dotclock_calculate(int link_freq, |
| 10435 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10436 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10437 | /* |
| 10438 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10439 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10440 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10441 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10442 | * |
| 10443 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10444 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10445 | */ |
| 10446 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10447 | if (!m_n->link_n) |
| 10448 | return 0; |
| 10449 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10450 | 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] | 10451 | } |
| 10452 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10453 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10454 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10455 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10456 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10457 | |
| 10458 | /* read out port_clock from the DPLL */ |
| 10459 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10460 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10461 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10462 | * In case there is an active pipe without active ports, |
| 10463 | * we may need some idea for the dotclock anyway. |
| 10464 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10465 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10466 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10467 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10468 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10469 | } |
| 10470 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10471 | /* Returns the currently programmed mode of the given encoder. */ |
| 10472 | struct drm_display_mode * |
| 10473 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10474 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10475 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10476 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10477 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10478 | struct intel_crtc *crtc; |
| 10479 | enum pipe pipe; |
| 10480 | |
| 10481 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10482 | return NULL; |
| 10483 | |
| 10484 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10485 | |
| 10486 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10487 | if (!mode) |
| 10488 | return NULL; |
| 10489 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10490 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10491 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10492 | kfree(mode); |
| 10493 | return NULL; |
| 10494 | } |
| 10495 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10496 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10497 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10498 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10499 | kfree(crtc_state); |
| 10500 | kfree(mode); |
| 10501 | return NULL; |
| 10502 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10503 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10504 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10505 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10506 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10507 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10508 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10509 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10510 | return mode; |
| 10511 | } |
| 10512 | |
| 10513 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10514 | { |
| 10515 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10516 | |
| 10517 | drm_crtc_cleanup(crtc); |
| 10518 | kfree(intel_crtc); |
| 10519 | } |
| 10520 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10521 | /** |
| 10522 | * intel_wm_need_update - Check whether watermarks need updating |
| 10523 | * @plane: drm plane |
| 10524 | * @state: new plane state |
| 10525 | * |
| 10526 | * Check current plane state versus the new one to determine whether |
| 10527 | * watermarks need to be recalculated. |
| 10528 | * |
| 10529 | * Returns true or false. |
| 10530 | */ |
| 10531 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 10532 | struct drm_plane_state *state) |
| 10533 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10534 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 10535 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 10536 | |
| 10537 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10538 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10539 | return true; |
| 10540 | |
| 10541 | if (!cur->base.fb || !new->base.fb) |
| 10542 | return false; |
| 10543 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10544 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10545 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10546 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10547 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10548 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10549 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10550 | return true; |
| 10551 | |
| 10552 | return false; |
| 10553 | } |
| 10554 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10555 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10556 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10557 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10558 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10559 | int dst_w = drm_rect_width(&state->base.dst); |
| 10560 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10561 | |
| 10562 | return (src_w != dst_w || src_h != dst_h); |
| 10563 | } |
| 10564 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10565 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10566 | struct drm_crtc_state *crtc_state, |
| 10567 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10568 | struct drm_plane_state *plane_state) |
| 10569 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10570 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10571 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10572 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10573 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10574 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10575 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10576 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10577 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10578 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10579 | bool turn_off, turn_on, visible, was_visible; |
| 10580 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10581 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10582 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10583 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10584 | ret = skl_update_scaler_plane( |
| 10585 | to_intel_crtc_state(crtc_state), |
| 10586 | to_intel_plane_state(plane_state)); |
| 10587 | if (ret) |
| 10588 | return ret; |
| 10589 | } |
| 10590 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10591 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10592 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10593 | |
| 10594 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10595 | was_visible = false; |
| 10596 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10597 | /* |
| 10598 | * Visibility is calculated as if the crtc was on, but |
| 10599 | * after scaler setup everything depends on it being off |
| 10600 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10601 | * |
| 10602 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10603 | * be computed as if the pipe would be active. Perhaps move |
| 10604 | * per-plane wm computation to the .check_plane() hook, and |
| 10605 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10606 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10607 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10608 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10609 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10610 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10611 | |
| 10612 | if (!was_visible && !visible) |
| 10613 | return 0; |
| 10614 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10615 | if (fb != old_plane_state->base.fb) |
| 10616 | pipe_config->fb_changed = true; |
| 10617 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10618 | turn_off = was_visible && (!visible || mode_changed); |
| 10619 | turn_on = visible && (!was_visible || mode_changed); |
| 10620 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10621 | 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] | 10622 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 10623 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10624 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10625 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10626 | 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] | 10627 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10628 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10629 | turn_off, turn_on, mode_changed); |
| 10630 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10631 | if (turn_on) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10632 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10633 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10634 | |
| 10635 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10636 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10637 | pipe_config->disable_cxsr = true; |
| 10638 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10639 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10640 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10641 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10642 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10643 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10644 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10645 | } else if (intel_wm_need_update(&plane->base, plane_state)) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10646 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10647 | /* FIXME bollocks */ |
| 10648 | pipe_config->update_wm_pre = true; |
| 10649 | pipe_config->update_wm_post = true; |
| 10650 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10651 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10652 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 10653 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10654 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10655 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10656 | /* |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10657 | * ILK/SNB DVSACNTR/Sprite Enable |
| 10658 | * IVB SPR_CTL/Sprite Enable |
| 10659 | * "When in Self Refresh Big FIFO mode, a write to enable the |
| 10660 | * plane will be internally buffered and delayed while Big FIFO |
| 10661 | * mode is exiting." |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10662 | * |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10663 | * Which means that enabling the sprite can take an extra frame |
| 10664 | * when we start in big FIFO mode (LP1+). Thus we need to drop |
| 10665 | * down to LP0 and wait for vblank in order to make sure the |
| 10666 | * sprite gets enabled on the next vblank after the register write. |
| 10667 | * Doing otherwise would risk enabling the sprite one frame after |
| 10668 | * we've already signalled flip completion. We can resume LP1+ |
| 10669 | * once the sprite has been enabled. |
| 10670 | * |
| 10671 | * |
| 10672 | * WaCxSRDisabledForSpriteScaling:ivb |
| 10673 | * IVB SPR_SCALE/Scaling Enable |
| 10674 | * "Low Power watermarks must be disabled for at least one |
| 10675 | * frame before enabling sprite scaling, and kept disabled |
| 10676 | * until sprite scaling is disabled." |
| 10677 | * |
| 10678 | * ILK/SNB DVSASCALE/Scaling Enable |
| 10679 | * "When in Self Refresh Big FIFO mode, scaling enable will be |
| 10680 | * masked off while Big FIFO mode is exiting." |
| 10681 | * |
| 10682 | * Despite the w/a only being listed for IVB we assume that |
| 10683 | * the ILK/SNB note has similar ramifications, hence we apply |
| 10684 | * the w/a on all three platforms. |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10685 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10686 | if (plane->id == PLANE_SPRITE0 && |
| 10687 | (IS_GEN5(dev_priv) || IS_GEN6(dev_priv) || |
| 10688 | IS_IVYBRIDGE(dev_priv)) && |
| 10689 | (turn_on || (!needs_scaling(old_plane_state) && |
| 10690 | needs_scaling(to_intel_plane_state(plane_state))))) |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10691 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10692 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10693 | return 0; |
| 10694 | } |
| 10695 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10696 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10697 | const struct intel_encoder *b) |
| 10698 | { |
| 10699 | /* masks could be asymmetric, so check both ways */ |
| 10700 | return a == b || (a->cloneable & (1 << b->type) && |
| 10701 | b->cloneable & (1 << a->type)); |
| 10702 | } |
| 10703 | |
| 10704 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 10705 | struct intel_crtc *crtc, |
| 10706 | struct intel_encoder *encoder) |
| 10707 | { |
| 10708 | struct intel_encoder *source_encoder; |
| 10709 | struct drm_connector *connector; |
| 10710 | struct drm_connector_state *connector_state; |
| 10711 | int i; |
| 10712 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10713 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10714 | if (connector_state->crtc != &crtc->base) |
| 10715 | continue; |
| 10716 | |
| 10717 | source_encoder = |
| 10718 | to_intel_encoder(connector_state->best_encoder); |
| 10719 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10720 | return false; |
| 10721 | } |
| 10722 | |
| 10723 | return true; |
| 10724 | } |
| 10725 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10726 | static int icl_add_linked_planes(struct intel_atomic_state *state) |
| 10727 | { |
| 10728 | struct intel_plane *plane, *linked; |
| 10729 | struct intel_plane_state *plane_state, *linked_plane_state; |
| 10730 | int i; |
| 10731 | |
| 10732 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10733 | linked = plane_state->linked_plane; |
| 10734 | |
| 10735 | if (!linked) |
| 10736 | continue; |
| 10737 | |
| 10738 | linked_plane_state = intel_atomic_get_plane_state(state, linked); |
| 10739 | if (IS_ERR(linked_plane_state)) |
| 10740 | return PTR_ERR(linked_plane_state); |
| 10741 | |
| 10742 | WARN_ON(linked_plane_state->linked_plane != plane); |
| 10743 | WARN_ON(linked_plane_state->slave == plane_state->slave); |
| 10744 | } |
| 10745 | |
| 10746 | return 0; |
| 10747 | } |
| 10748 | |
| 10749 | static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state) |
| 10750 | { |
| 10751 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 10752 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 10753 | struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state); |
| 10754 | struct intel_plane *plane, *linked; |
| 10755 | struct intel_plane_state *plane_state; |
| 10756 | int i; |
| 10757 | |
| 10758 | if (INTEL_GEN(dev_priv) < 11) |
| 10759 | return 0; |
| 10760 | |
| 10761 | /* |
| 10762 | * Destroy all old plane links and make the slave plane invisible |
| 10763 | * in the crtc_state->active_planes mask. |
| 10764 | */ |
| 10765 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10766 | if (plane->pipe != crtc->pipe || !plane_state->linked_plane) |
| 10767 | continue; |
| 10768 | |
| 10769 | plane_state->linked_plane = NULL; |
| 10770 | if (plane_state->slave && !plane_state->base.visible) |
| 10771 | crtc_state->active_planes &= ~BIT(plane->id); |
| 10772 | |
| 10773 | plane_state->slave = false; |
| 10774 | } |
| 10775 | |
| 10776 | if (!crtc_state->nv12_planes) |
| 10777 | return 0; |
| 10778 | |
| 10779 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10780 | struct intel_plane_state *linked_state = NULL; |
| 10781 | |
| 10782 | if (plane->pipe != crtc->pipe || |
| 10783 | !(crtc_state->nv12_planes & BIT(plane->id))) |
| 10784 | continue; |
| 10785 | |
| 10786 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) { |
| 10787 | if (!icl_is_nv12_y_plane(linked->id)) |
| 10788 | continue; |
| 10789 | |
| 10790 | if (crtc_state->active_planes & BIT(linked->id)) |
| 10791 | continue; |
| 10792 | |
| 10793 | linked_state = intel_atomic_get_plane_state(state, linked); |
| 10794 | if (IS_ERR(linked_state)) |
| 10795 | return PTR_ERR(linked_state); |
| 10796 | |
| 10797 | break; |
| 10798 | } |
| 10799 | |
| 10800 | if (!linked_state) { |
| 10801 | DRM_DEBUG_KMS("Need %d free Y planes for NV12\n", |
| 10802 | hweight8(crtc_state->nv12_planes)); |
| 10803 | |
| 10804 | return -EINVAL; |
| 10805 | } |
| 10806 | |
| 10807 | plane_state->linked_plane = linked; |
| 10808 | |
| 10809 | linked_state->slave = true; |
| 10810 | linked_state->linked_plane = plane; |
| 10811 | crtc_state->active_planes |= BIT(linked->id); |
| 10812 | DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name); |
| 10813 | } |
| 10814 | |
| 10815 | return 0; |
| 10816 | } |
| 10817 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10818 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 10819 | struct drm_crtc_state *crtc_state) |
| 10820 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10821 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10822 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10823 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10824 | struct intel_crtc_state *pipe_config = |
| 10825 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10826 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 10827 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10828 | bool mode_changed = needs_modeset(crtc_state); |
| 10829 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10830 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10831 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 10832 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10833 | if (mode_changed && crtc_state->enable && |
| 10834 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10835 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10836 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 10837 | pipe_config); |
| 10838 | if (ret) |
| 10839 | return ret; |
| 10840 | } |
| 10841 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10842 | if (crtc_state->color_mgmt_changed) { |
| 10843 | ret = intel_color_check(crtc, crtc_state); |
| 10844 | if (ret) |
| 10845 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 10846 | |
| 10847 | /* |
| 10848 | * Changing color management on Intel hardware is |
| 10849 | * handled as part of planes update. |
| 10850 | */ |
| 10851 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10852 | } |
| 10853 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10854 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10855 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 10856 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10857 | if (ret) { |
| 10858 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10859 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10860 | } |
| 10861 | } |
| 10862 | |
| 10863 | if (dev_priv->display.compute_intermediate_wm && |
| 10864 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 10865 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 10866 | return 0; |
| 10867 | |
| 10868 | /* |
| 10869 | * Calculate 'intermediate' watermarks that satisfy both the |
| 10870 | * old state and the new state. We can program these |
| 10871 | * immediately. |
| 10872 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10873 | ret = dev_priv->display.compute_intermediate_wm(dev, |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10874 | intel_crtc, |
| 10875 | pipe_config); |
| 10876 | if (ret) { |
| 10877 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 10878 | return ret; |
| 10879 | } |
Ville Syrjälä | e3d5457 | 2016-05-13 10:10:42 -0700 | [diff] [blame] | 10880 | } else if (dev_priv->display.compute_intermediate_wm) { |
| 10881 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) |
| 10882 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10883 | } |
| 10884 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10885 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10886 | if (mode_changed) |
| 10887 | ret = skl_update_scaler_crtc(pipe_config); |
| 10888 | |
| 10889 | if (!ret) |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10890 | ret = icl_check_nv12_planes(pipe_config); |
| 10891 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 10892 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 10893 | pipe_config); |
| 10894 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 10895 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10896 | pipe_config); |
| 10897 | } |
| 10898 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 10899 | if (HAS_IPS(dev_priv)) |
| 10900 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 10901 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10902 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10903 | } |
| 10904 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 10905 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10906 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10907 | }; |
| 10908 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10909 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 10910 | { |
| 10911 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10912 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10913 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10914 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 10915 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10916 | if (connector->base.state->crtc) |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 10917 | drm_connector_put(&connector->base); |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10918 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10919 | if (connector->base.encoder) { |
| 10920 | connector->base.state->best_encoder = |
| 10921 | connector->base.encoder; |
| 10922 | connector->base.state->crtc = |
| 10923 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10924 | |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 10925 | drm_connector_get(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10926 | } else { |
| 10927 | connector->base.state->best_encoder = NULL; |
| 10928 | connector->base.state->crtc = NULL; |
| 10929 | } |
| 10930 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10931 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10932 | } |
| 10933 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 10934 | static int |
| 10935 | connected_sink_max_bpp(const struct drm_connector_state *conn_state, |
| 10936 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10937 | { |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 10938 | int bpp; |
| 10939 | struct drm_display_info *info = &conn_state->connector->display_info; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10940 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 10941 | switch (conn_state->max_bpc) { |
| 10942 | case 6 ... 7: |
| 10943 | bpp = 6 * 3; |
| 10944 | break; |
| 10945 | case 8 ... 9: |
| 10946 | bpp = 8 * 3; |
| 10947 | break; |
| 10948 | case 10 ... 11: |
| 10949 | bpp = 10 * 3; |
| 10950 | break; |
| 10951 | case 12: |
| 10952 | bpp = 12 * 3; |
| 10953 | break; |
| 10954 | default: |
| 10955 | return -EINVAL; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10956 | } |
| 10957 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 10958 | if (bpp < pipe_config->pipe_bpp) { |
| 10959 | DRM_DEBUG_KMS("Limiting display bpp to %d instead of Edid bpp " |
| 10960 | "%d, requested bpp %d, max platform bpp %d\n", bpp, |
| 10961 | 3 * info->bpc, 3 * conn_state->max_requested_bpc, |
| 10962 | pipe_config->pipe_bpp); |
| 10963 | pipe_config->pipe_bpp = bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10964 | } |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 10965 | return 0; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10966 | } |
| 10967 | |
| 10968 | static int |
| 10969 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10970 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10971 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10972 | 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] | 10973 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10974 | struct drm_connector *connector; |
| 10975 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10976 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10977 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10978 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 10979 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10980 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10981 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 10982 | bpp = 12*3; |
| 10983 | else |
| 10984 | bpp = 8*3; |
| 10985 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10986 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10987 | pipe_config->pipe_bpp = bpp; |
| 10988 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10989 | state = pipe_config->base.state; |
| 10990 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10991 | /* Clamp display bpp to EDID value */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10992 | 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] | 10993 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10994 | continue; |
| 10995 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 10996 | if (connected_sink_max_bpp(connector_state, pipe_config) < 0) |
| 10997 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10998 | } |
| 10999 | |
| 11000 | return bpp; |
| 11001 | } |
| 11002 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11003 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11004 | { |
| 11005 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11006 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11007 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11008 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11009 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11010 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11011 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11012 | } |
| 11013 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11014 | static inline void |
| 11015 | 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] | 11016 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11017 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11018 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11019 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11020 | m_n->gmch_m, m_n->gmch_n, |
| 11021 | m_n->link_m, m_n->link_n, m_n->tu); |
| 11022 | } |
| 11023 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11024 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 11025 | |
| 11026 | static const char * const output_type_str[] = { |
| 11027 | OUTPUT_TYPE(UNUSED), |
| 11028 | OUTPUT_TYPE(ANALOG), |
| 11029 | OUTPUT_TYPE(DVO), |
| 11030 | OUTPUT_TYPE(SDVO), |
| 11031 | OUTPUT_TYPE(LVDS), |
| 11032 | OUTPUT_TYPE(TVOUT), |
| 11033 | OUTPUT_TYPE(HDMI), |
| 11034 | OUTPUT_TYPE(DP), |
| 11035 | OUTPUT_TYPE(EDP), |
| 11036 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11037 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11038 | OUTPUT_TYPE(DP_MST), |
| 11039 | }; |
| 11040 | |
| 11041 | #undef OUTPUT_TYPE |
| 11042 | |
| 11043 | static void snprintf_output_types(char *buf, size_t len, |
| 11044 | unsigned int output_types) |
| 11045 | { |
| 11046 | char *str = buf; |
| 11047 | int i; |
| 11048 | |
| 11049 | str[0] = '\0'; |
| 11050 | |
| 11051 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 11052 | int r; |
| 11053 | |
| 11054 | if ((output_types & BIT(i)) == 0) |
| 11055 | continue; |
| 11056 | |
| 11057 | r = snprintf(str, len, "%s%s", |
| 11058 | str != buf ? "," : "", output_type_str[i]); |
| 11059 | if (r >= len) |
| 11060 | break; |
| 11061 | str += r; |
| 11062 | len -= r; |
| 11063 | |
| 11064 | output_types &= ~BIT(i); |
| 11065 | } |
| 11066 | |
| 11067 | WARN_ON_ONCE(output_types != 0); |
| 11068 | } |
| 11069 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11070 | static const char * const output_format_str[] = { |
| 11071 | [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid", |
| 11072 | [INTEL_OUTPUT_FORMAT_RGB] = "RGB", |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11073 | [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0", |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 11074 | [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4", |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11075 | }; |
| 11076 | |
| 11077 | static const char *output_formats(enum intel_output_format format) |
| 11078 | { |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11079 | if (format >= ARRAY_SIZE(output_format_str)) |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11080 | format = INTEL_OUTPUT_FORMAT_INVALID; |
| 11081 | return output_format_str[format]; |
| 11082 | } |
| 11083 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11084 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11085 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11086 | const char *context) |
| 11087 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11088 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11089 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11090 | struct drm_plane *plane; |
| 11091 | struct intel_plane *intel_plane; |
| 11092 | struct intel_plane_state *state; |
| 11093 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11094 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11095 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 11096 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 11097 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11098 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11099 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 11100 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 11101 | buf, pipe_config->output_types); |
| 11102 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11103 | DRM_DEBUG_KMS("output format: %s\n", |
| 11104 | output_formats(pipe_config->output_format)); |
| 11105 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11106 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 11107 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11108 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11109 | |
| 11110 | if (pipe_config->has_pch_encoder) |
| 11111 | intel_dump_m_n_config(pipe_config, "fdi", |
| 11112 | pipe_config->fdi_lanes, |
| 11113 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11114 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11115 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11116 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 11117 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 11118 | if (pipe_config->has_drrs) |
| 11119 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 11120 | pipe_config->lane_count, |
| 11121 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11122 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11123 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11124 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11125 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11126 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11127 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11128 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11129 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11130 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11131 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11132 | 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] | 11133 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11134 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 11135 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11136 | |
| 11137 | if (INTEL_GEN(dev_priv) >= 9) |
| 11138 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11139 | crtc->num_scalers, |
| 11140 | pipe_config->scaler_state.scaler_users, |
| 11141 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11142 | |
| 11143 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 11144 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11145 | pipe_config->gmch_pfit.control, |
| 11146 | pipe_config->gmch_pfit.pgm_ratios, |
| 11147 | pipe_config->gmch_pfit.lvds_border_bits); |
| 11148 | else |
| 11149 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 11150 | pipe_config->pch_pfit.pos, |
| 11151 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 11152 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11153 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11154 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 11155 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11156 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 11157 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11158 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11159 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11160 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11161 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11162 | intel_plane = to_intel_plane(plane); |
| 11163 | if (intel_plane->pipe != crtc->pipe) |
| 11164 | continue; |
| 11165 | |
| 11166 | state = to_intel_plane_state(plane->state); |
| 11167 | fb = state->base.fb; |
| 11168 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 11169 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 11170 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11171 | continue; |
| 11172 | } |
| 11173 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11174 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 11175 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11176 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 11177 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11178 | if (INTEL_GEN(dev_priv) >= 9) |
| 11179 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 11180 | state->scaler_id, |
| 11181 | state->base.src.x1 >> 16, |
| 11182 | state->base.src.y1 >> 16, |
| 11183 | drm_rect_width(&state->base.src) >> 16, |
| 11184 | drm_rect_height(&state->base.src) >> 16, |
| 11185 | state->base.dst.x1, state->base.dst.y1, |
| 11186 | drm_rect_width(&state->base.dst), |
| 11187 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11188 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11189 | } |
| 11190 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11191 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11192 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11193 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11194 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11195 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11196 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11197 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11198 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11199 | |
| 11200 | /* |
| 11201 | * Walk the connector list instead of the encoder |
| 11202 | * list to detect the problem on ddi platforms |
| 11203 | * where there's just one encoder per digital port. |
| 11204 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11205 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11206 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11207 | struct drm_connector_state *connector_state; |
| 11208 | struct intel_encoder *encoder; |
| 11209 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 11210 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11211 | if (!connector_state) |
| 11212 | connector_state = connector->state; |
| 11213 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11214 | if (!connector_state->best_encoder) |
| 11215 | continue; |
| 11216 | |
| 11217 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11218 | |
| 11219 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11220 | |
| 11221 | switch (encoder->type) { |
| 11222 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11223 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11224 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11225 | break; |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 11226 | /* else: fall through */ |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 11227 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11228 | case INTEL_OUTPUT_HDMI: |
| 11229 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11230 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11231 | |
| 11232 | /* the same port mustn't appear more than once */ |
| 11233 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11234 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11235 | |
| 11236 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11237 | break; |
| 11238 | case INTEL_OUTPUT_DP_MST: |
| 11239 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11240 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11241 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11242 | default: |
| 11243 | break; |
| 11244 | } |
| 11245 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11246 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11247 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11248 | /* can't mix MST and SST/HDMI on the same port */ |
| 11249 | if (used_ports & used_mst_ports) |
| 11250 | return false; |
| 11251 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11252 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11253 | } |
| 11254 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11255 | static void |
| 11256 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11257 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11258 | struct drm_i915_private *dev_priv = |
| 11259 | to_i915(crtc_state->base.crtc->dev); |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11260 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11261 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11262 | struct intel_shared_dpll *shared_dpll; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11263 | struct intel_crtc_wm_state wm_state; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11264 | bool force_thru, ips_force_disable; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11265 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 11266 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 11267 | * kzalloc'd. Code that depends on any field being zero should be |
| 11268 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 11269 | * only fields that are know to not cause problems are preserved. */ |
| 11270 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11271 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11272 | shared_dpll = crtc_state->shared_dpll; |
| 11273 | dpll_hw_state = crtc_state->dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11274 | force_thru = crtc_state->pch_pfit.force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11275 | ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11276 | if (IS_G4X(dev_priv) || |
| 11277 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11278 | wm_state = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11279 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11280 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 11281 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
| 11282 | memset(&crtc_state->base + 1, 0, |
| 11283 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11284 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11285 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11286 | crtc_state->shared_dpll = shared_dpll; |
| 11287 | crtc_state->dpll_hw_state = dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11288 | crtc_state->pch_pfit.force_thru = force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11289 | crtc_state->ips_force_disable = ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11290 | if (IS_G4X(dev_priv) || |
| 11291 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11292 | crtc_state->wm = wm_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11293 | } |
| 11294 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11295 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11296 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11297 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11298 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11299 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11300 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11301 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11302 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11303 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11304 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11305 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11306 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11307 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11308 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11309 | pipe_config->cpu_transcoder = |
| 11310 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11311 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11312 | /* |
| 11313 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11314 | * positive or negative polarity is requested, treat this as meaning |
| 11315 | * negative polarity. |
| 11316 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11317 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11318 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11319 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11320 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11321 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11322 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11323 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11324 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11325 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11326 | pipe_config); |
| 11327 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11328 | goto fail; |
| 11329 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11330 | /* |
| 11331 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11332 | * increase the actual pipe size due to the frame doubling and |
| 11333 | * insertion of additional space for blanks between the frame. This |
| 11334 | * is stored in the crtc timings. We use the requested mode to do this |
| 11335 | * computation to clearly distinguish it from the adjusted mode, which |
| 11336 | * can be changed by the connectors in the below retry loop. |
| 11337 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 11338 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11339 | &pipe_config->pipe_src_w, |
| 11340 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11341 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11342 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11343 | if (connector_state->crtc != crtc) |
| 11344 | continue; |
| 11345 | |
| 11346 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11347 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11348 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11349 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 11350 | goto fail; |
| 11351 | } |
| 11352 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11353 | /* |
| 11354 | * Determine output_types before calling the .compute_config() |
| 11355 | * hooks so that the hooks can use this information safely. |
| 11356 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11357 | if (encoder->compute_output_type) |
| 11358 | pipe_config->output_types |= |
| 11359 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11360 | connector_state)); |
| 11361 | else |
| 11362 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11363 | } |
| 11364 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11365 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11366 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11367 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11368 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11369 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11370 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11371 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11372 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11373 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11374 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11375 | * adjust it according to limitations or connector properties, and also |
| 11376 | * a chance to reject the mode entirely. |
| 11377 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11378 | 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] | 11379 | if (connector_state->crtc != crtc) |
| 11380 | continue; |
| 11381 | |
| 11382 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11383 | |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 11384 | if (!(encoder->compute_config(encoder, pipe_config, connector_state))) { |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 11385 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11386 | goto fail; |
| 11387 | } |
| 11388 | } |
| 11389 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11390 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11391 | * done afterwards in case the encoder adjusts the mode. */ |
| 11392 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11393 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11394 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11395 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11396 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11397 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11398 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 11399 | goto fail; |
| 11400 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11401 | |
| 11402 | if (ret == RETRY) { |
| 11403 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 11404 | ret = -EINVAL; |
| 11405 | goto fail; |
| 11406 | } |
| 11407 | |
| 11408 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11409 | retry = false; |
| 11410 | goto encoder_retry; |
| 11411 | } |
| 11412 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11413 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11414 | * only enable it on 6bpc panels and when its not a compliance |
| 11415 | * test requesting 6bpc video pattern. |
| 11416 | */ |
| 11417 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11418 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11419 | 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] | 11420 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11421 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11422 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11423 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11424 | } |
| 11425 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11426 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11427 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11428 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11429 | |
| 11430 | if (clock1 == clock2) |
| 11431 | return true; |
| 11432 | |
| 11433 | if (!clock1 || !clock2) |
| 11434 | return false; |
| 11435 | |
| 11436 | diff = abs(clock1 - clock2); |
| 11437 | |
| 11438 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11439 | return true; |
| 11440 | |
| 11441 | return false; |
| 11442 | } |
| 11443 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11444 | static bool |
| 11445 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11446 | unsigned int m2, unsigned int n2, |
| 11447 | bool exact) |
| 11448 | { |
| 11449 | if (m == m2 && n == n2) |
| 11450 | return true; |
| 11451 | |
| 11452 | if (exact || !m || !n || !m2 || !n2) |
| 11453 | return false; |
| 11454 | |
| 11455 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11456 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11457 | if (n > n2) { |
| 11458 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11459 | m2 <<= 1; |
| 11460 | n2 <<= 1; |
| 11461 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11462 | } else if (n < n2) { |
| 11463 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11464 | m <<= 1; |
| 11465 | n <<= 1; |
| 11466 | } |
| 11467 | } |
| 11468 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11469 | if (n != n2) |
| 11470 | return false; |
| 11471 | |
| 11472 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11473 | } |
| 11474 | |
| 11475 | static bool |
| 11476 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11477 | struct intel_link_m_n *m2_n2, |
| 11478 | bool adjust) |
| 11479 | { |
| 11480 | if (m_n->tu == m2_n2->tu && |
| 11481 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11482 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11483 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11484 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11485 | if (adjust) |
| 11486 | *m2_n2 = *m_n; |
| 11487 | |
| 11488 | return true; |
| 11489 | } |
| 11490 | |
| 11491 | return false; |
| 11492 | } |
| 11493 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11494 | static void __printf(3, 4) |
| 11495 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11496 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11497 | struct va_format vaf; |
| 11498 | va_list args; |
| 11499 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11500 | va_start(args, format); |
| 11501 | vaf.fmt = format; |
| 11502 | vaf.va = &args; |
| 11503 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11504 | if (adjust) |
| 11505 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11506 | else |
| 11507 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11508 | |
| 11509 | va_end(args); |
| 11510 | } |
| 11511 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11512 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11513 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11514 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11515 | struct intel_crtc_state *pipe_config, |
| 11516 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11517 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11518 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11519 | bool fixup_inherited = adjust && |
| 11520 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11521 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11522 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11523 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11524 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11525 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11526 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11527 | current_config->name, \ |
| 11528 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11529 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11530 | } \ |
| 11531 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11532 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11533 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11534 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11535 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11536 | "(expected %i, found %i)\n", \ |
| 11537 | current_config->name, \ |
| 11538 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11539 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11540 | } \ |
| 11541 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11542 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11543 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11544 | if (current_config->name != pipe_config->name) { \ |
| 11545 | pipe_config_err(adjust, __stringify(name), \ |
| 11546 | "(expected %s, found %s)\n", \ |
| 11547 | yesno(current_config->name), \ |
| 11548 | yesno(pipe_config->name)); \ |
| 11549 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11550 | } \ |
| 11551 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11552 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11553 | /* |
| 11554 | * Checks state where we only read out the enabling, but not the entire |
| 11555 | * state itself (like full infoframes or ELD for audio). These states |
| 11556 | * require a full modeset on bootup to fix up. |
| 11557 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11558 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11559 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11560 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11561 | } else { \ |
| 11562 | pipe_config_err(adjust, __stringify(name), \ |
| 11563 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11564 | yesno(current_config->name), \ |
| 11565 | yesno(pipe_config->name)); \ |
| 11566 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11567 | } \ |
| 11568 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11569 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11570 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11571 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11572 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11573 | "(expected %p, found %p)\n", \ |
| 11574 | current_config->name, \ |
| 11575 | pipe_config->name); \ |
| 11576 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11577 | } \ |
| 11578 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11579 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11580 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11581 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11582 | &pipe_config->name,\ |
| 11583 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11584 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11585 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11586 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11587 | current_config->name.tu, \ |
| 11588 | current_config->name.gmch_m, \ |
| 11589 | current_config->name.gmch_n, \ |
| 11590 | current_config->name.link_m, \ |
| 11591 | current_config->name.link_n, \ |
| 11592 | pipe_config->name.tu, \ |
| 11593 | pipe_config->name.gmch_m, \ |
| 11594 | pipe_config->name.gmch_n, \ |
| 11595 | pipe_config->name.link_m, \ |
| 11596 | pipe_config->name.link_n); \ |
| 11597 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11598 | } \ |
| 11599 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11600 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 11601 | /* This is required for BDW+ where there is only one set of registers for |
| 11602 | * switching between high and low RR. |
| 11603 | * This macro can be used whenever a comparison has to be made between one |
| 11604 | * hw state and multiple sw state variables. |
| 11605 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11606 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11607 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11608 | &pipe_config->name, adjust) && \ |
| 11609 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 11610 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11611 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11612 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11613 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 11614 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11615 | current_config->name.tu, \ |
| 11616 | current_config->name.gmch_m, \ |
| 11617 | current_config->name.gmch_n, \ |
| 11618 | current_config->name.link_m, \ |
| 11619 | current_config->name.link_n, \ |
| 11620 | current_config->alt_name.tu, \ |
| 11621 | current_config->alt_name.gmch_m, \ |
| 11622 | current_config->alt_name.gmch_n, \ |
| 11623 | current_config->alt_name.link_m, \ |
| 11624 | current_config->alt_name.link_n, \ |
| 11625 | pipe_config->name.tu, \ |
| 11626 | pipe_config->name.gmch_m, \ |
| 11627 | pipe_config->name.gmch_n, \ |
| 11628 | pipe_config->name.link_m, \ |
| 11629 | pipe_config->name.link_n); \ |
| 11630 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11631 | } \ |
| 11632 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11633 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11634 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11635 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11636 | pipe_config_err(adjust, __stringify(name), \ |
| 11637 | "(%x) (expected %i, found %i)\n", \ |
| 11638 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11639 | current_config->name & (mask), \ |
| 11640 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11641 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11642 | } \ |
| 11643 | } while (0) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11644 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11645 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11646 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11647 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11648 | "(expected %i, found %i)\n", \ |
| 11649 | current_config->name, \ |
| 11650 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11651 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11652 | } \ |
| 11653 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11654 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11655 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11656 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11657 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11658 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11659 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11660 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11661 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11662 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11663 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11664 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 11665 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11666 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11667 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11668 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11669 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11670 | if (current_config->has_drrs) |
| 11671 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 11672 | } else |
| 11673 | 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] | 11674 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11675 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 11676 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11677 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11678 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11679 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11680 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11681 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11682 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11683 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11684 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11685 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11686 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11687 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11688 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11689 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11690 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11691 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11692 | PIPE_CONF_CHECK_I(output_format); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11693 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 11694 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 11695 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11696 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 11697 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11698 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 11699 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11700 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11701 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11702 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11703 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11704 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11705 | DRM_MODE_FLAG_INTERLACE); |
| 11706 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11707 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11708 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11709 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11710 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11711 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11712 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11713 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11714 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11715 | DRM_MODE_FLAG_NVSYNC); |
| 11716 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11717 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11718 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 11719 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11720 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 11721 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11722 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11723 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11724 | if (!adjust) { |
| 11725 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11726 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 11727 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11728 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11729 | if (current_config->pch_pfit.enabled) { |
| 11730 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 11731 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 11732 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11733 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11734 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11735 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11736 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 11737 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11738 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11739 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11740 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11741 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11742 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11743 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11744 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11745 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 11746 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11747 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11748 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11749 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 11750 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 11751 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 11752 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 11753 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 11754 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 11755 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 11756 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 11757 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 11758 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 11759 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 11760 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 11761 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 11762 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 11763 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 11764 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 11765 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 11766 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 11767 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 11768 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 11769 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 11770 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 11771 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11772 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 11773 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 11774 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 11775 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11776 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11777 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11778 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11779 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11780 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11781 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 11782 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 11783 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11784 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11785 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11786 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11787 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11788 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11789 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11790 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11791 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11792 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11793 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11794 | } |
| 11795 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11796 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 11797 | const struct intel_crtc_state *pipe_config) |
| 11798 | { |
| 11799 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 11800 | 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] | 11801 | &pipe_config->fdi_m_n); |
| 11802 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 11803 | |
| 11804 | /* |
| 11805 | * FDI already provided one idea for the dotclock. |
| 11806 | * Yell if the encoder disagrees. |
| 11807 | */ |
| 11808 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 11809 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 11810 | fdi_dotclock, dotclock); |
| 11811 | } |
| 11812 | } |
| 11813 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11814 | static void verify_wm_state(struct drm_crtc *crtc, |
| 11815 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11816 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11817 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11818 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11819 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 11820 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 11821 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11823 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11824 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11825 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11826 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11827 | return; |
| 11828 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11829 | skl_pipe_wm_get_hw_state(crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 11830 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11831 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11832 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11833 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11834 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 11835 | if (INTEL_GEN(dev_priv) >= 11) |
| 11836 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 11837 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 11838 | sw_ddb->enabled_slices, |
| 11839 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11840 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 11841 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11842 | hw_plane_wm = &hw_wm.planes[plane]; |
| 11843 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11844 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11845 | /* Watermarks */ |
| 11846 | for (level = 0; level <= max_level; level++) { |
| 11847 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 11848 | &sw_plane_wm->wm[level])) |
| 11849 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11850 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11851 | 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", |
| 11852 | pipe_name(pipe), plane + 1, level, |
| 11853 | sw_plane_wm->wm[level].plane_en, |
| 11854 | sw_plane_wm->wm[level].plane_res_b, |
| 11855 | sw_plane_wm->wm[level].plane_res_l, |
| 11856 | hw_plane_wm->wm[level].plane_en, |
| 11857 | hw_plane_wm->wm[level].plane_res_b, |
| 11858 | hw_plane_wm->wm[level].plane_res_l); |
| 11859 | } |
| 11860 | |
| 11861 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 11862 | &sw_plane_wm->trans_wm)) { |
| 11863 | 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", |
| 11864 | pipe_name(pipe), plane + 1, |
| 11865 | sw_plane_wm->trans_wm.plane_en, |
| 11866 | sw_plane_wm->trans_wm.plane_res_b, |
| 11867 | sw_plane_wm->trans_wm.plane_res_l, |
| 11868 | hw_plane_wm->trans_wm.plane_en, |
| 11869 | hw_plane_wm->trans_wm.plane_res_b, |
| 11870 | hw_plane_wm->trans_wm.plane_res_l); |
| 11871 | } |
| 11872 | |
| 11873 | /* DDB */ |
| 11874 | hw_ddb_entry = &hw_ddb.plane[pipe][plane]; |
| 11875 | sw_ddb_entry = &sw_ddb->plane[pipe][plane]; |
| 11876 | |
| 11877 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 11878 | 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] | 11879 | pipe_name(pipe), plane + 1, |
| 11880 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 11881 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 11882 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11883 | } |
| 11884 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 11885 | /* |
| 11886 | * cursor |
| 11887 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 11888 | * allocation. In that case since the ddb allocation will be updated |
| 11889 | * once the plane becomes visible, we can skip this check |
| 11890 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 11891 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11892 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 11893 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11894 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11895 | /* Watermarks */ |
| 11896 | for (level = 0; level <= max_level; level++) { |
| 11897 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 11898 | &sw_plane_wm->wm[level])) |
| 11899 | continue; |
| 11900 | |
| 11901 | 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", |
| 11902 | pipe_name(pipe), level, |
| 11903 | sw_plane_wm->wm[level].plane_en, |
| 11904 | sw_plane_wm->wm[level].plane_res_b, |
| 11905 | sw_plane_wm->wm[level].plane_res_l, |
| 11906 | hw_plane_wm->wm[level].plane_en, |
| 11907 | hw_plane_wm->wm[level].plane_res_b, |
| 11908 | hw_plane_wm->wm[level].plane_res_l); |
| 11909 | } |
| 11910 | |
| 11911 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 11912 | &sw_plane_wm->trans_wm)) { |
| 11913 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 11914 | pipe_name(pipe), |
| 11915 | sw_plane_wm->trans_wm.plane_en, |
| 11916 | sw_plane_wm->trans_wm.plane_res_b, |
| 11917 | sw_plane_wm->trans_wm.plane_res_l, |
| 11918 | hw_plane_wm->trans_wm.plane_en, |
| 11919 | hw_plane_wm->trans_wm.plane_res_b, |
| 11920 | hw_plane_wm->trans_wm.plane_res_l); |
| 11921 | } |
| 11922 | |
| 11923 | /* DDB */ |
| 11924 | hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 11925 | sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
| 11926 | |
| 11927 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 11928 | 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] | 11929 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11930 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 11931 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 11932 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11933 | } |
| 11934 | } |
| 11935 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11936 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11937 | verify_connector_state(struct drm_device *dev, |
| 11938 | struct drm_atomic_state *state, |
| 11939 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11940 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11941 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11942 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11943 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11944 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11945 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11946 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11947 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11948 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11949 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11950 | continue; |
| 11951 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11952 | if (crtc) |
| 11953 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 11954 | |
| 11955 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11956 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11957 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11958 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11959 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11960 | } |
| 11961 | |
| 11962 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11963 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11964 | { |
| 11965 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11966 | struct drm_connector *connector; |
| 11967 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 11968 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11969 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11970 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11971 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11972 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11973 | |
| 11974 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 11975 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11976 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11977 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11978 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 11979 | new_conn_state, i) { |
| 11980 | if (old_conn_state->best_encoder == &encoder->base) |
| 11981 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11982 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11983 | if (new_conn_state->best_encoder != &encoder->base) |
| 11984 | continue; |
| 11985 | found = enabled = true; |
| 11986 | |
| 11987 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11988 | encoder->base.crtc, |
| 11989 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11990 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11991 | |
| 11992 | if (!found) |
| 11993 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11994 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11995 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11996 | "encoder's enabled state mismatch " |
| 11997 | "(expected %i, found %i)\n", |
| 11998 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11999 | |
| 12000 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12001 | bool active; |
| 12002 | |
| 12003 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12004 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12005 | "encoder detached but still enabled on pipe %c.\n", |
| 12006 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12007 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12008 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12009 | } |
| 12010 | |
| 12011 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12012 | verify_crtc_state(struct drm_crtc *crtc, |
| 12013 | struct drm_crtc_state *old_crtc_state, |
| 12014 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12015 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12016 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12017 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12018 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12019 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12020 | struct intel_crtc_state *pipe_config, *sw_config; |
| 12021 | struct drm_atomic_state *old_state; |
| 12022 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12023 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12024 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 12025 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12026 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12027 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12028 | pipe_config->base.crtc = crtc; |
| 12029 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12030 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12031 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12032 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12033 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12034 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 12035 | /* we keep both pipes enabled on 830 */ |
| 12036 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12037 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12038 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12039 | I915_STATE_WARN(new_crtc_state->active != active, |
| 12040 | "crtc active state doesn't match with hw state " |
| 12041 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12042 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12043 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 12044 | "transitional active state does not match atomic hw state " |
| 12045 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12046 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12047 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12048 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12049 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12050 | active = encoder->get_hw_state(encoder, &pipe); |
| 12051 | I915_STATE_WARN(active != new_crtc_state->active, |
| 12052 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12053 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12054 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12055 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12056 | "Encoder connected to wrong pipe %c\n", |
| 12057 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12058 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 12059 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12060 | encoder->get_config(encoder, pipe_config); |
| 12061 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12062 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12063 | intel_crtc_compute_pixel_rate(pipe_config); |
| 12064 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12065 | if (!new_crtc_state->active) |
| 12066 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12067 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12068 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12069 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12070 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12071 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12072 | pipe_config, false)) { |
| 12073 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 12074 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 12075 | "[hw state]"); |
| 12076 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 12077 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12078 | } |
| 12079 | } |
| 12080 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12081 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12082 | intel_verify_planes(struct intel_atomic_state *state) |
| 12083 | { |
| 12084 | struct intel_plane *plane; |
| 12085 | const struct intel_plane_state *plane_state; |
| 12086 | int i; |
| 12087 | |
| 12088 | for_each_new_intel_plane_in_state(state, plane, |
| 12089 | plane_state, i) |
| 12090 | assert_plane(plane, plane_state->base.visible); |
| 12091 | } |
| 12092 | |
| 12093 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12094 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 12095 | struct intel_shared_dpll *pll, |
| 12096 | struct drm_crtc *crtc, |
| 12097 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12098 | { |
| 12099 | struct intel_dpll_hw_state dpll_hw_state; |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12100 | unsigned int crtc_mask; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12101 | bool active; |
| 12102 | |
| 12103 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12104 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 12105 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12106 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 12107 | 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] | 12108 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 12109 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12110 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12111 | "pll in active use but not on in sw tracking\n"); |
| 12112 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12113 | "pll is on but not used by any active crtc\n"); |
| 12114 | I915_STATE_WARN(pll->on != active, |
| 12115 | "pll on state mismatch (expected %i, found %i)\n", |
| 12116 | pll->on, active); |
| 12117 | } |
| 12118 | |
| 12119 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12120 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12121 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12122 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12123 | |
| 12124 | return; |
| 12125 | } |
| 12126 | |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12127 | crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12128 | |
| 12129 | if (new_state->active) |
| 12130 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 12131 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 12132 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12133 | else |
| 12134 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12135 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 12136 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12137 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12138 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12139 | "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] | 12140 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12141 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12142 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12143 | &dpll_hw_state, |
| 12144 | sizeof(dpll_hw_state)), |
| 12145 | "pll hw state mismatch\n"); |
| 12146 | } |
| 12147 | |
| 12148 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12149 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 12150 | struct drm_crtc_state *old_crtc_state, |
| 12151 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12152 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12153 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12154 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 12155 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 12156 | |
| 12157 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12158 | 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] | 12159 | |
| 12160 | if (old_state->shared_dpll && |
| 12161 | old_state->shared_dpll != new_state->shared_dpll) { |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12162 | unsigned int crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12163 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 12164 | |
| 12165 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12166 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 12167 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12168 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12169 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 12170 | pipe_name(drm_crtc_index(crtc))); |
| 12171 | } |
| 12172 | } |
| 12173 | |
| 12174 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12175 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12176 | struct drm_atomic_state *state, |
| 12177 | struct drm_crtc_state *old_state, |
| 12178 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12179 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12180 | if (!needs_modeset(new_state) && |
| 12181 | !to_intel_crtc_state(new_state)->update_pipe) |
| 12182 | return; |
| 12183 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12184 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12185 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12186 | verify_crtc_state(crtc, old_state, new_state); |
| 12187 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12188 | } |
| 12189 | |
| 12190 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12191 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12192 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12193 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12194 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12195 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12196 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12197 | 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] | 12198 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12199 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12200 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12201 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 12202 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12203 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12204 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12205 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12206 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12207 | } |
| 12208 | |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12209 | static void update_scanline_offset(const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12210 | { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12211 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12212 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12213 | |
| 12214 | /* |
| 12215 | * The scanline counter increments at the leading edge of hsync. |
| 12216 | * |
| 12217 | * On most platforms it starts counting from vtotal-1 on the |
| 12218 | * first active line. That means the scanline counter value is |
| 12219 | * always one less than what we would expect. Ie. just after |
| 12220 | * start of vblank, which also occurs at start of hsync (on the |
| 12221 | * last active line), the scanline counter will read vblank_start-1. |
| 12222 | * |
| 12223 | * On gen2 the scanline counter starts counting from 1 instead |
| 12224 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12225 | * to keep the value positive), instead of adding one. |
| 12226 | * |
| 12227 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12228 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12229 | * there's an extra 1 line difference. So we need to add two instead of |
| 12230 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 12231 | * |
| 12232 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 12233 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 12234 | * that means we can't tell whether we're in vblank or not while |
| 12235 | * we're on that particular line. We must still set scanline_offset |
| 12236 | * to 1 so that the vblank timestamps come out correct when we query |
| 12237 | * the scanline counter from within the vblank interrupt handler. |
| 12238 | * However if queried just before the start of vblank we'll get an |
| 12239 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12240 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12241 | if (IS_GEN2(dev_priv)) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12242 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12243 | int vtotal; |
| 12244 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12245 | vtotal = adjusted_mode->crtc_vtotal; |
| 12246 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12247 | vtotal /= 2; |
| 12248 | |
| 12249 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12250 | } else if (HAS_DDI(dev_priv) && |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12251 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12252 | crtc->scanline_offset = 2; |
| 12253 | } else |
| 12254 | crtc->scanline_offset = 1; |
| 12255 | } |
| 12256 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12257 | 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] | 12258 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12259 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12260 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12261 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12262 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12263 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12264 | |
| 12265 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12266 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12267 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12268 | 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] | 12269 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12270 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12271 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12272 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12273 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12274 | continue; |
| 12275 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12276 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12277 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12278 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12279 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12280 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 12281 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12282 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12283 | } |
| 12284 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12285 | /* |
| 12286 | * This implements the workaround described in the "notes" section of the mode |
| 12287 | * set sequence documentation. When going from no pipes or single pipe to |
| 12288 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12289 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12290 | */ |
| 12291 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12292 | { |
| 12293 | struct drm_crtc_state *crtc_state; |
| 12294 | struct intel_crtc *intel_crtc; |
| 12295 | struct drm_crtc *crtc; |
| 12296 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12297 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12298 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12299 | int i; |
| 12300 | |
| 12301 | /* 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] | 12302 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12303 | intel_crtc = to_intel_crtc(crtc); |
| 12304 | |
| 12305 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12306 | continue; |
| 12307 | |
| 12308 | if (first_crtc_state) { |
| 12309 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12310 | break; |
| 12311 | } else { |
| 12312 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12313 | first_pipe = intel_crtc->pipe; |
| 12314 | } |
| 12315 | } |
| 12316 | |
| 12317 | /* No workaround needed? */ |
| 12318 | if (!first_crtc_state) |
| 12319 | return 0; |
| 12320 | |
| 12321 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12322 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12323 | struct intel_crtc_state *pipe_config; |
| 12324 | |
| 12325 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12326 | if (IS_ERR(pipe_config)) |
| 12327 | return PTR_ERR(pipe_config); |
| 12328 | |
| 12329 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12330 | |
| 12331 | if (!pipe_config->base.active || |
| 12332 | needs_modeset(&pipe_config->base)) |
| 12333 | continue; |
| 12334 | |
| 12335 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12336 | if (enabled_pipe != INVALID_PIPE) |
| 12337 | return 0; |
| 12338 | |
| 12339 | enabled_pipe = intel_crtc->pipe; |
| 12340 | } |
| 12341 | |
| 12342 | if (enabled_pipe != INVALID_PIPE) |
| 12343 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12344 | else if (other_crtc_state) |
| 12345 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12346 | |
| 12347 | return 0; |
| 12348 | } |
| 12349 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12350 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12351 | { |
| 12352 | struct drm_crtc *crtc; |
| 12353 | |
| 12354 | /* Add all pipes to the state */ |
| 12355 | for_each_crtc(state->dev, crtc) { |
| 12356 | struct drm_crtc_state *crtc_state; |
| 12357 | |
| 12358 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12359 | if (IS_ERR(crtc_state)) |
| 12360 | return PTR_ERR(crtc_state); |
| 12361 | } |
| 12362 | |
| 12363 | return 0; |
| 12364 | } |
| 12365 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12366 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12367 | { |
| 12368 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12369 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12370 | /* |
| 12371 | * Add all pipes to the state, and force |
| 12372 | * a modeset on all the active ones. |
| 12373 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12374 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12375 | struct drm_crtc_state *crtc_state; |
| 12376 | int ret; |
| 12377 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12378 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12379 | if (IS_ERR(crtc_state)) |
| 12380 | return PTR_ERR(crtc_state); |
| 12381 | |
| 12382 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12383 | continue; |
| 12384 | |
| 12385 | crtc_state->mode_changed = true; |
| 12386 | |
| 12387 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12388 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12389 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12390 | |
| 12391 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12392 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12393 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12394 | } |
| 12395 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12396 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12397 | } |
| 12398 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12399 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12400 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12401 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12402 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12403 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12404 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12405 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12406 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12407 | if (!check_digital_port_conflicts(state)) { |
| 12408 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12409 | return -EINVAL; |
| 12410 | } |
| 12411 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12412 | intel_state->modeset = true; |
| 12413 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12414 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12415 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12416 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12417 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12418 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12419 | intel_state->active_crtcs |= 1 << i; |
| 12420 | else |
| 12421 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12422 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12423 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12424 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12425 | } |
| 12426 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12427 | /* |
| 12428 | * See if the config requires any additional preparation, e.g. |
| 12429 | * to adjust global state with pipes off. We need to do this |
| 12430 | * here so we can get the modeset_pipe updated config for the new |
| 12431 | * mode set on this crtc. For other crtcs we need to use the |
| 12432 | * adjusted_mode bits in the crtc directly. |
| 12433 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12434 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12435 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12436 | if (ret < 0) |
| 12437 | return ret; |
| 12438 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12439 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12440 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12441 | * holding all the crtc locks, even if we don't end up |
| 12442 | * touching the hardware |
| 12443 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12444 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12445 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12446 | ret = intel_lock_all_pipes(state); |
| 12447 | if (ret < 0) |
| 12448 | return ret; |
| 12449 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12450 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12451 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12452 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12453 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12454 | ret = intel_modeset_all_pipes(state); |
| 12455 | if (ret < 0) |
| 12456 | return ret; |
| 12457 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12458 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12459 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12460 | intel_state->cdclk.logical.cdclk, |
| 12461 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12462 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12463 | intel_state->cdclk.logical.voltage_level, |
| 12464 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12465 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12466 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12467 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12468 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12469 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12470 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12471 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12472 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12473 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12474 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12475 | } |
| 12476 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12477 | /* |
| 12478 | * Handle calculation of various watermark data at the end of the atomic check |
| 12479 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12480 | * handlers to ensure that all derived state has been updated. |
| 12481 | */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12482 | static int calc_watermark_data(struct drm_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12483 | { |
| 12484 | struct drm_device *dev = state->dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12485 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12486 | |
| 12487 | /* Is there platform-specific watermark information to calculate? */ |
| 12488 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12489 | return dev_priv->display.compute_global_watermarks(state); |
| 12490 | |
| 12491 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12492 | } |
| 12493 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12494 | /** |
| 12495 | * intel_atomic_check - validate state object |
| 12496 | * @dev: drm device |
| 12497 | * @state: state to validate |
| 12498 | */ |
| 12499 | static int intel_atomic_check(struct drm_device *dev, |
| 12500 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12501 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12502 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12503 | 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] | 12504 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12505 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12506 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12507 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12508 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12509 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12510 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12511 | crtc_state, i) { |
| 12512 | if (crtc_state->mode.private_flags != |
| 12513 | old_crtc_state->mode.private_flags) |
| 12514 | crtc_state->mode_changed = true; |
| 12515 | } |
| 12516 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12517 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12518 | if (ret) |
| 12519 | return ret; |
| 12520 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12521 | 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] | 12522 | struct intel_crtc_state *pipe_config = |
| 12523 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12524 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12525 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12526 | continue; |
| 12527 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12528 | if (!crtc_state->enable) { |
| 12529 | any_ms = true; |
| 12530 | continue; |
| 12531 | } |
| 12532 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12533 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12534 | if (ret) { |
| 12535 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12536 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12537 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12538 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12539 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 12540 | if (i915_modparams.fastboot && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12541 | intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12542 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12543 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12544 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12545 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12546 | } |
| 12547 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12548 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12549 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12550 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12551 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12552 | needs_modeset(crtc_state) ? |
| 12553 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12554 | } |
| 12555 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12556 | if (any_ms) { |
| 12557 | ret = intel_modeset_checks(state); |
| 12558 | |
| 12559 | if (ret) |
| 12560 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12561 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12562 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12563 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12564 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 12565 | ret = icl_add_linked_planes(intel_state); |
| 12566 | if (ret) |
| 12567 | return ret; |
| 12568 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12569 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12570 | if (ret) |
| 12571 | return ret; |
| 12572 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12573 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12574 | return calc_watermark_data(state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12575 | } |
| 12576 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12577 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12578 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12579 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12580 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12581 | } |
| 12582 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12583 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12584 | { |
| 12585 | struct drm_device *dev = crtc->base.dev; |
| 12586 | |
| 12587 | if (!dev->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 12588 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12589 | |
| 12590 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 12591 | } |
| 12592 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12593 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 12594 | struct drm_atomic_state *state, |
| 12595 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12596 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12597 | { |
| 12598 | struct drm_device *dev = crtc->dev; |
| 12599 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 12600 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12601 | struct intel_crtc_state *old_intel_cstate = to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12602 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 12603 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12604 | struct intel_plane_state *new_plane_state = |
| 12605 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 12606 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12607 | |
| 12608 | if (modeset) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12609 | update_scanline_offset(pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12610 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12611 | |
| 12612 | /* vblanks work again, re-enable pipe CRC. */ |
| 12613 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12614 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12615 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12616 | pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12617 | } |
| 12618 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12619 | if (new_plane_state) |
| 12620 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12621 | |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12622 | intel_begin_crtc_commit(crtc, old_crtc_state); |
| 12623 | |
| 12624 | intel_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc, |
| 12625 | old_intel_cstate, pipe_config); |
| 12626 | |
| 12627 | intel_finish_crtc_commit(crtc, old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12628 | } |
| 12629 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12630 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12631 | { |
| 12632 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12633 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12634 | int i; |
| 12635 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12636 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12637 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12638 | continue; |
| 12639 | |
| 12640 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12641 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12642 | } |
| 12643 | } |
| 12644 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12645 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12646 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12647 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12648 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 12649 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12650 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12651 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12652 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12653 | unsigned int updated = 0; |
| 12654 | bool progress; |
| 12655 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12656 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12657 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 12658 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12659 | |
| 12660 | const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {}; |
| 12661 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12662 | 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] | 12663 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12664 | if (new_crtc_state->active) |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12665 | entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12666 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12667 | /* If 2nd DBuf slice required, enable it here */ |
| 12668 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 12669 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 12670 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12671 | /* |
| 12672 | * Whenever the number of active pipes changes, we need to make sure we |
| 12673 | * update the pipes in the right order so that their ddb allocations |
| 12674 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 12675 | * cause pipe underruns and other bad stuff. |
| 12676 | */ |
| 12677 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12678 | progress = false; |
| 12679 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12680 | 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] | 12681 | bool vbl_wait = false; |
| 12682 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12683 | |
| 12684 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12685 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12686 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12687 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12688 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12689 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12690 | |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 12691 | if (skl_ddb_allocation_overlaps(dev_priv, |
| 12692 | entries, |
| 12693 | &cstate->wm.skl.ddb, |
| 12694 | i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12695 | continue; |
| 12696 | |
| 12697 | updated |= cmask; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12698 | entries[i] = &cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12699 | |
| 12700 | /* |
| 12701 | * If this is an already active pipe, it's DDB changed, |
| 12702 | * and this isn't the last pipe that needs updating |
| 12703 | * then we need to wait for a vblank to pass for the |
| 12704 | * new ddb allocation to take effect. |
| 12705 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12706 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 12707 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12708 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12709 | intel_state->wm_results.dirty_pipes != updated) |
| 12710 | vbl_wait = true; |
| 12711 | |
| 12712 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12713 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12714 | |
| 12715 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12716 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12717 | |
| 12718 | progress = true; |
| 12719 | } |
| 12720 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12721 | |
| 12722 | /* If 2nd DBuf slice is no more required disable it */ |
| 12723 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 12724 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12725 | } |
| 12726 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 12727 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 12728 | { |
| 12729 | struct intel_atomic_state *state, *next; |
| 12730 | struct llist_node *freed; |
| 12731 | |
| 12732 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 12733 | llist_for_each_entry_safe(state, next, freed, freed) |
| 12734 | drm_atomic_state_put(&state->base); |
| 12735 | } |
| 12736 | |
| 12737 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 12738 | { |
| 12739 | struct drm_i915_private *dev_priv = |
| 12740 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 12741 | |
| 12742 | intel_atomic_helper_free_state(dev_priv); |
| 12743 | } |
| 12744 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12745 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 12746 | { |
| 12747 | struct wait_queue_entry wait_fence, wait_reset; |
| 12748 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 12749 | |
| 12750 | init_wait_entry(&wait_fence, 0); |
| 12751 | init_wait_entry(&wait_reset, 0); |
| 12752 | for (;;) { |
| 12753 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 12754 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 12755 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 12756 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 12757 | |
| 12758 | |
| 12759 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 12760 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 12761 | break; |
| 12762 | |
| 12763 | schedule(); |
| 12764 | } |
| 12765 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 12766 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 12767 | } |
| 12768 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 12769 | static void intel_atomic_cleanup_work(struct work_struct *work) |
| 12770 | { |
| 12771 | struct drm_atomic_state *state = |
| 12772 | container_of(work, struct drm_atomic_state, commit_work); |
| 12773 | struct drm_i915_private *i915 = to_i915(state->dev); |
| 12774 | |
| 12775 | drm_atomic_helper_cleanup_planes(&i915->drm, state); |
| 12776 | drm_atomic_helper_commit_cleanup_done(state); |
| 12777 | drm_atomic_state_put(state); |
| 12778 | |
| 12779 | intel_atomic_helper_free_state(i915); |
| 12780 | } |
| 12781 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12782 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12783 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12784 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12785 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12786 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12787 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12788 | struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 12789 | struct drm_crtc *crtc; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12790 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 12791 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 12792 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12793 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12794 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12795 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 12796 | drm_atomic_helper_wait_for_dependencies(state); |
| 12797 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12798 | if (intel_state->modeset) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12799 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12800 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12801 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12802 | old_intel_crtc_state = to_intel_crtc_state(old_crtc_state); |
| 12803 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 12804 | intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12805 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12806 | if (needs_modeset(new_crtc_state) || |
| 12807 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12808 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12809 | put_domains[intel_crtc->pipe] = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12810 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12811 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12812 | } |
| 12813 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12814 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12815 | continue; |
| 12816 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12817 | intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 12818 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 12819 | if (old_crtc_state->active) { |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 12820 | intel_crtc_disable_planes(intel_crtc, old_intel_crtc_state->active_planes); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12821 | |
| 12822 | /* |
| 12823 | * We need to disable pipe CRC before disabling the pipe, |
| 12824 | * or we race against vblank off. |
| 12825 | */ |
| 12826 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 12827 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12828 | dev_priv->display.crtc_disable(old_intel_crtc_state, state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12829 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 12830 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 12831 | intel_disable_shared_dpll(old_intel_crtc_state); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 12832 | |
| 12833 | /* |
| 12834 | * Underruns don't always raise |
| 12835 | * interrupts, so check manually. |
| 12836 | */ |
| 12837 | intel_check_cpu_fifo_underruns(dev_priv); |
| 12838 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 12839 | |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 12840 | /* FIXME unify this for all platforms */ |
| 12841 | if (!new_crtc_state->active && |
| 12842 | !HAS_GMCH_DISPLAY(dev_priv) && |
| 12843 | dev_priv->display.initial_watermarks) |
| 12844 | dev_priv->display.initial_watermarks(intel_state, |
| 12845 | new_intel_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12846 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12847 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12848 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 12849 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 12850 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 12851 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12852 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12853 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12854 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 12855 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 12856 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 12857 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12858 | /* |
| 12859 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 12860 | * have more then one pipe enabled |
| 12861 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 12862 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 12863 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12864 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12865 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12866 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 12867 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12868 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12869 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 12870 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12871 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12872 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12873 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12874 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12875 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12876 | spin_unlock_irq(&dev->event_lock); |
| 12877 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12878 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12879 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12880 | } |
| 12881 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12882 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12883 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12884 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12885 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 12886 | * already, but still need the state for the delayed optimization. To |
| 12887 | * fix this: |
| 12888 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 12889 | * - schedule that vblank worker _before_ calling hw_done |
| 12890 | * - at the start of commit_tail, cancel it _synchrously |
| 12891 | * - switch over to the vblank wait helper in the core after that since |
| 12892 | * we don't need out special handling any more. |
| 12893 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12894 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12895 | |
| 12896 | /* |
| 12897 | * Now that the vblank has passed, we can go ahead and program the |
| 12898 | * optimal watermarks on platforms that need two-step watermark |
| 12899 | * programming. |
| 12900 | * |
| 12901 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 12902 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12903 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12904 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12905 | |
| 12906 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 12907 | dev_priv->display.optimize_watermarks(intel_state, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12908 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12909 | } |
| 12910 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12911 | 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] | 12912 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 12913 | |
| 12914 | if (put_domains[i]) |
| 12915 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 12916 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12917 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12918 | } |
| 12919 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12920 | if (intel_state->modeset) |
| 12921 | intel_verify_planes(intel_state); |
| 12922 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 12923 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 12924 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12925 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12926 | drm_atomic_helper_commit_hw_done(state); |
| 12927 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 12928 | if (intel_state->modeset) { |
| 12929 | /* As one of the primary mmio accessors, KMS has a high |
| 12930 | * likelihood of triggering bugs in unclaimed access. After we |
| 12931 | * finish modesetting, see if an error has been flagged, and if |
| 12932 | * so enable debugging for the next modeset - and hope we catch |
| 12933 | * the culprit. |
| 12934 | */ |
| 12935 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12936 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 12937 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12938 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 12939 | /* |
| 12940 | * Defer the cleanup of the old state to a separate worker to not |
| 12941 | * impede the current task (userspace for blocking modesets) that |
| 12942 | * are executed inline. For out-of-line asynchronous modesets/flips, |
| 12943 | * deferring to a new worker seems overkill, but we would place a |
| 12944 | * schedule point (cond_resched()) here anyway to keep latencies |
| 12945 | * down. |
| 12946 | */ |
| 12947 | INIT_WORK(&state->commit_work, intel_atomic_cleanup_work); |
Chris Wilson | 41db645 | 2018-07-12 12:57:29 +0100 | [diff] [blame] | 12948 | queue_work(system_highpri_wq, &state->commit_work); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12949 | } |
| 12950 | |
| 12951 | static void intel_atomic_commit_work(struct work_struct *work) |
| 12952 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12953 | struct drm_atomic_state *state = |
| 12954 | container_of(work, struct drm_atomic_state, commit_work); |
| 12955 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12956 | intel_atomic_commit_tail(state); |
| 12957 | } |
| 12958 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12959 | static int __i915_sw_fence_call |
| 12960 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 12961 | enum i915_sw_fence_notify notify) |
| 12962 | { |
| 12963 | struct intel_atomic_state *state = |
| 12964 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 12965 | |
| 12966 | switch (notify) { |
| 12967 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12968 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12969 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12970 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 12971 | { |
| 12972 | struct intel_atomic_helper *helper = |
| 12973 | &to_i915(state->base.dev)->atomic_helper; |
| 12974 | |
| 12975 | if (llist_add(&state->freed, &helper->free_list)) |
| 12976 | schedule_work(&helper->free_work); |
| 12977 | break; |
| 12978 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12979 | } |
| 12980 | |
| 12981 | return NOTIFY_DONE; |
| 12982 | } |
| 12983 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12984 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 12985 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12986 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12987 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12988 | int i; |
| 12989 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12990 | 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] | 12991 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12992 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 12993 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12994 | } |
| 12995 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12996 | /** |
| 12997 | * intel_atomic_commit - commit validated state object |
| 12998 | * @dev: DRM device |
| 12999 | * @state: the top-level driver state object |
| 13000 | * @nonblock: nonblocking commit |
| 13001 | * |
| 13002 | * This function commits a top-level state object that has been validated |
| 13003 | * with drm_atomic_helper_check(). |
| 13004 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13005 | * RETURNS |
| 13006 | * Zero for success or -errno. |
| 13007 | */ |
| 13008 | static int intel_atomic_commit(struct drm_device *dev, |
| 13009 | struct drm_atomic_state *state, |
| 13010 | bool nonblock) |
| 13011 | { |
| 13012 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13013 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13014 | int ret = 0; |
| 13015 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13016 | drm_atomic_state_get(state); |
| 13017 | i915_sw_fence_init(&intel_state->commit_ready, |
| 13018 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13019 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13020 | /* |
| 13021 | * The intel_legacy_cursor_update() fast path takes care |
| 13022 | * of avoiding the vblank waits for simple cursor |
| 13023 | * movement and flips. For cursor on/off and size changes, |
| 13024 | * we want to perform the vblank waits so that watermark |
| 13025 | * updates happen during the correct frames. Gen9+ have |
| 13026 | * double buffered watermarks and so shouldn't need this. |
| 13027 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13028 | * Unset state->legacy_cursor_update before the call to |
| 13029 | * drm_atomic_helper_setup_commit() because otherwise |
| 13030 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 13031 | * we get FIFO underruns because we didn't wait |
| 13032 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13033 | * |
| 13034 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 13035 | * (assuming we had any) would solve these problems. |
| 13036 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 13037 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 13038 | struct intel_crtc_state *new_crtc_state; |
| 13039 | struct intel_crtc *crtc; |
| 13040 | int i; |
| 13041 | |
| 13042 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 13043 | if (new_crtc_state->wm.need_postvbl_update || |
| 13044 | new_crtc_state->update_wm_post) |
| 13045 | state->legacy_cursor_update = false; |
| 13046 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13047 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13048 | ret = intel_atomic_prepare_commit(dev, state); |
| 13049 | if (ret) { |
| 13050 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 13051 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13052 | return ret; |
| 13053 | } |
| 13054 | |
| 13055 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 13056 | if (!ret) |
| 13057 | ret = drm_atomic_helper_swap_state(state, true); |
| 13058 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13059 | if (ret) { |
| 13060 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13061 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13062 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13063 | return ret; |
| 13064 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13065 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 13066 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13067 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13068 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13069 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 13070 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 13071 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 13072 | memcpy(dev_priv->min_voltage_level, |
| 13073 | intel_state->min_voltage_level, |
| 13074 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13075 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 13076 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 13077 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13078 | } |
| 13079 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 13080 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13081 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13082 | |
| 13083 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13084 | if (nonblock && intel_state->modeset) { |
| 13085 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 13086 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13087 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13088 | } else { |
| 13089 | if (intel_state->modeset) |
| 13090 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13091 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13092 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13093 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13094 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13095 | } |
| 13096 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13097 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 13098 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13099 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13100 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 13101 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13102 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13103 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 13104 | .set_crc_source = intel_crtc_set_crc_source, |
Mahesh Kumar | a8c2083 | 2018-07-13 19:29:38 +0530 | [diff] [blame] | 13105 | .verify_crc_source = intel_crtc_verify_crc_source, |
Mahesh Kumar | 260bc55 | 2018-07-13 19:29:39 +0530 | [diff] [blame] | 13106 | .get_crc_sources = intel_crtc_get_crc_sources, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13107 | }; |
| 13108 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13109 | struct wait_rps_boost { |
| 13110 | struct wait_queue_entry wait; |
| 13111 | |
| 13112 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13113 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13114 | }; |
| 13115 | |
| 13116 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 13117 | unsigned mode, int sync, void *key) |
| 13118 | { |
| 13119 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13120 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13121 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13122 | /* |
| 13123 | * If we missed the vblank, but the request is already running it |
| 13124 | * is reasonable to assume that it will complete before the next |
| 13125 | * vblank without our intervention, so leave RPS alone. |
| 13126 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13127 | if (!i915_request_started(rq)) |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13128 | gen6_rps_boost(rq, NULL); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13129 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13130 | |
| 13131 | drm_crtc_vblank_put(wait->crtc); |
| 13132 | |
| 13133 | list_del(&wait->wait.entry); |
| 13134 | kfree(wait); |
| 13135 | return 1; |
| 13136 | } |
| 13137 | |
| 13138 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 13139 | struct dma_fence *fence) |
| 13140 | { |
| 13141 | struct wait_rps_boost *wait; |
| 13142 | |
| 13143 | if (!dma_fence_is_i915(fence)) |
| 13144 | return; |
| 13145 | |
| 13146 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 13147 | return; |
| 13148 | |
| 13149 | if (drm_crtc_vblank_get(crtc)) |
| 13150 | return; |
| 13151 | |
| 13152 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 13153 | if (!wait) { |
| 13154 | drm_crtc_vblank_put(crtc); |
| 13155 | return; |
| 13156 | } |
| 13157 | |
| 13158 | wait->request = to_request(dma_fence_get(fence)); |
| 13159 | wait->crtc = crtc; |
| 13160 | |
| 13161 | wait->wait.func = do_rps_boost; |
| 13162 | wait->wait.flags = 0; |
| 13163 | |
| 13164 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 13165 | } |
| 13166 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13167 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 13168 | { |
| 13169 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 13170 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 13171 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 13172 | struct i915_vma *vma; |
| 13173 | |
| 13174 | if (plane->id == PLANE_CURSOR && |
| 13175 | INTEL_INFO(dev_priv)->cursor_needs_physical) { |
| 13176 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13177 | const int align = intel_cursor_alignment(dev_priv); |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13178 | int err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13179 | |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13180 | err = i915_gem_object_attach_phys(obj, align); |
| 13181 | if (err) |
| 13182 | return err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13183 | } |
| 13184 | |
| 13185 | vma = intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 13186 | &plane_state->view, |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13187 | intel_plane_uses_fence(plane_state), |
| 13188 | &plane_state->flags); |
| 13189 | if (IS_ERR(vma)) |
| 13190 | return PTR_ERR(vma); |
| 13191 | |
| 13192 | plane_state->vma = vma; |
| 13193 | |
| 13194 | return 0; |
| 13195 | } |
| 13196 | |
| 13197 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 13198 | { |
| 13199 | struct i915_vma *vma; |
| 13200 | |
| 13201 | vma = fetch_and_zero(&old_plane_state->vma); |
| 13202 | if (vma) |
| 13203 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 13204 | } |
| 13205 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 13206 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 13207 | { |
| 13208 | struct i915_sched_attr attr = { |
| 13209 | .priority = I915_PRIORITY_DISPLAY, |
| 13210 | }; |
| 13211 | |
| 13212 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 13213 | } |
| 13214 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13215 | /** |
| 13216 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13217 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13218 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13219 | * |
| 13220 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13221 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13222 | * bits. Some older platforms need special physical address handling for |
| 13223 | * cursor planes. |
| 13224 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13225 | * Must be called with struct_mutex held. |
| 13226 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13227 | * Returns 0 on success, negative error code on failure. |
| 13228 | */ |
| 13229 | int |
| 13230 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13231 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13232 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13233 | struct intel_atomic_state *intel_state = |
| 13234 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 13235 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13236 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13237 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13238 | 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] | 13239 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13240 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13241 | if (old_obj) { |
| 13242 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13243 | drm_atomic_get_new_crtc_state(new_state->state, |
| 13244 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13245 | |
| 13246 | /* Big Hammer, we also need to ensure that any pending |
| 13247 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13248 | * current scanout is retired before unpinning the old |
| 13249 | * framebuffer. Note that we rely on userspace rendering |
| 13250 | * into the buffer attached to the pipe they are waiting |
| 13251 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13252 | * point to the MI_WAIT_FOR_EVENT. |
| 13253 | * |
| 13254 | * This should only fail upon a hung GPU, in which case we |
| 13255 | * can safely continue. |
| 13256 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13257 | if (needs_modeset(crtc_state)) { |
| 13258 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13259 | old_obj->resv, NULL, |
| 13260 | false, 0, |
| 13261 | GFP_KERNEL); |
| 13262 | if (ret < 0) |
| 13263 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13264 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13265 | } |
| 13266 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13267 | if (new_state->fence) { /* explicit fencing */ |
| 13268 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 13269 | new_state->fence, |
| 13270 | I915_FENCE_TIMEOUT, |
| 13271 | GFP_KERNEL); |
| 13272 | if (ret < 0) |
| 13273 | return ret; |
| 13274 | } |
| 13275 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 13276 | if (!obj) |
| 13277 | return 0; |
| 13278 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13279 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13280 | if (ret) |
| 13281 | return ret; |
| 13282 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13283 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13284 | if (ret) { |
| 13285 | i915_gem_object_unpin_pages(obj); |
| 13286 | return ret; |
| 13287 | } |
| 13288 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13289 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13290 | |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13291 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13292 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13293 | if (ret) |
| 13294 | return ret; |
| 13295 | |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 13296 | fb_obj_bump_render_priority(obj); |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13297 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 13298 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13299 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13300 | struct dma_fence *fence; |
| 13301 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13302 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13303 | obj->resv, NULL, |
| 13304 | false, I915_FENCE_TIMEOUT, |
| 13305 | GFP_KERNEL); |
| 13306 | if (ret < 0) |
| 13307 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13308 | |
| 13309 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 13310 | if (fence) { |
| 13311 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 13312 | dma_fence_put(fence); |
| 13313 | } |
| 13314 | } else { |
| 13315 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13316 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13317 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13318 | /* |
| 13319 | * We declare pageflips to be interactive and so merit a small bias |
| 13320 | * towards upclocking to deliver the frame on time. By only changing |
| 13321 | * the RPS thresholds to sample more regularly and aim for higher |
| 13322 | * clocks we can hopefully deliver low power workloads (like kodi) |
| 13323 | * that are not quite steady state without resorting to forcing |
| 13324 | * maximum clocks following a vblank miss (see do_rps_boost()). |
| 13325 | */ |
| 13326 | if (!intel_state->rps_interactive) { |
| 13327 | intel_rps_mark_interactive(dev_priv, true); |
| 13328 | intel_state->rps_interactive = true; |
| 13329 | } |
| 13330 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 13331 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13332 | } |
| 13333 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13334 | /** |
| 13335 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13336 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13337 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13338 | * |
| 13339 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13340 | * |
| 13341 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13342 | */ |
| 13343 | void |
| 13344 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13345 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13346 | { |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13347 | struct intel_atomic_state *intel_state = |
| 13348 | to_intel_atomic_state(old_state->state); |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13349 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13350 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13351 | if (intel_state->rps_interactive) { |
| 13352 | intel_rps_mark_interactive(dev_priv, false); |
| 13353 | intel_state->rps_interactive = false; |
| 13354 | } |
| 13355 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 13356 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13357 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 13358 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 13359 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13360 | } |
| 13361 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13362 | int |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13363 | skl_max_scale(const struct intel_crtc_state *crtc_state, |
| 13364 | u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13365 | { |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13366 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 13367 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13368 | int max_scale, mult; |
| 13369 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13370 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13371 | if (!crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13372 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13373 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13374 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 13375 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 13376 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 13377 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13378 | max_dotclk *= 2; |
| 13379 | |
| 13380 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13381 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13382 | |
| 13383 | /* |
| 13384 | * skl max scale is lower of: |
| 13385 | * close to 3 but not 3, -1 is for that purpose |
| 13386 | * or |
| 13387 | * cdclk/crtc_clock |
| 13388 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13389 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 13390 | tmpclk1 = (1 << 16) * mult - 1; |
| 13391 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 13392 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13393 | |
| 13394 | return max_scale; |
| 13395 | } |
| 13396 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13397 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13398 | struct drm_crtc_state *old_crtc_state) |
| 13399 | { |
| 13400 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13401 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13402 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13403 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13404 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13405 | struct intel_atomic_state *old_intel_state = |
| 13406 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13407 | struct intel_crtc_state *intel_cstate = |
| 13408 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13409 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13410 | |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13411 | if (!modeset && |
| 13412 | (intel_cstate->base.color_mgmt_changed || |
| 13413 | intel_cstate->update_pipe)) { |
Ville Syrjälä | 5c857e6 | 2017-08-23 18:22:20 +0300 | [diff] [blame] | 13414 | intel_color_set_csc(&intel_cstate->base); |
| 13415 | intel_color_load_luts(&intel_cstate->base); |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13416 | } |
| 13417 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13418 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13419 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13420 | |
| 13421 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13422 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13423 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13424 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13425 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13426 | else if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 13427 | skl_detach_scalers(intel_cstate); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13428 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13429 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13430 | if (dev_priv->display.atomic_update_watermarks) |
| 13431 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13432 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13433 | } |
| 13434 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13435 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13436 | struct intel_crtc_state *crtc_state) |
| 13437 | { |
| 13438 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13439 | |
| 13440 | if (!IS_GEN2(dev_priv)) |
| 13441 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13442 | |
| 13443 | if (crtc_state->has_pch_encoder) { |
| 13444 | enum pipe pch_transcoder = |
| 13445 | intel_crtc_pch_transcoder(crtc); |
| 13446 | |
| 13447 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13448 | } |
| 13449 | } |
| 13450 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13451 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13452 | struct drm_crtc_state *old_crtc_state) |
| 13453 | { |
| 13454 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13455 | struct intel_atomic_state *old_intel_state = |
| 13456 | to_intel_atomic_state(old_crtc_state->state); |
| 13457 | struct intel_crtc_state *new_crtc_state = |
| 13458 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13459 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13460 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13461 | |
| 13462 | if (new_crtc_state->update_pipe && |
| 13463 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13464 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13465 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13466 | } |
| 13467 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13468 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13469 | * intel_plane_destroy - destroy a plane |
| 13470 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13471 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13472 | * Common destruction function for all types of planes (primary, cursor, |
| 13473 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13474 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13475 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13476 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13477 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13478 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13479 | } |
| 13480 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13481 | static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane, |
| 13482 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13483 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13484 | switch (modifier) { |
| 13485 | case DRM_FORMAT_MOD_LINEAR: |
| 13486 | case I915_FORMAT_MOD_X_TILED: |
| 13487 | break; |
| 13488 | default: |
| 13489 | return false; |
| 13490 | } |
| 13491 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13492 | switch (format) { |
| 13493 | case DRM_FORMAT_C8: |
| 13494 | case DRM_FORMAT_RGB565: |
| 13495 | case DRM_FORMAT_XRGB1555: |
| 13496 | case DRM_FORMAT_XRGB8888: |
| 13497 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13498 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13499 | default: |
| 13500 | return false; |
| 13501 | } |
| 13502 | } |
| 13503 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13504 | static bool i965_plane_format_mod_supported(struct drm_plane *_plane, |
| 13505 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13506 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13507 | switch (modifier) { |
| 13508 | case DRM_FORMAT_MOD_LINEAR: |
| 13509 | case I915_FORMAT_MOD_X_TILED: |
| 13510 | break; |
| 13511 | default: |
| 13512 | return false; |
| 13513 | } |
| 13514 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13515 | switch (format) { |
| 13516 | case DRM_FORMAT_C8: |
| 13517 | case DRM_FORMAT_RGB565: |
| 13518 | case DRM_FORMAT_XRGB8888: |
| 13519 | case DRM_FORMAT_XBGR8888: |
| 13520 | case DRM_FORMAT_XRGB2101010: |
| 13521 | case DRM_FORMAT_XBGR2101010: |
| 13522 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13523 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13524 | default: |
| 13525 | return false; |
| 13526 | } |
| 13527 | } |
| 13528 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13529 | static bool intel_cursor_format_mod_supported(struct drm_plane *_plane, |
| 13530 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13531 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13532 | return modifier == DRM_FORMAT_MOD_LINEAR && |
| 13533 | format == DRM_FORMAT_ARGB8888; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13534 | } |
| 13535 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13536 | static const struct drm_plane_funcs i965_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13537 | .update_plane = drm_atomic_helper_update_plane, |
| 13538 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13539 | .destroy = intel_plane_destroy, |
| 13540 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13541 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13542 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13543 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13544 | .format_mod_supported = i965_plane_format_mod_supported, |
| 13545 | }; |
| 13546 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13547 | static const struct drm_plane_funcs i8xx_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13548 | .update_plane = drm_atomic_helper_update_plane, |
| 13549 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13550 | .destroy = intel_plane_destroy, |
| 13551 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13552 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13553 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13554 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13555 | .format_mod_supported = i8xx_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13556 | }; |
| 13557 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13558 | static int |
| 13559 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13560 | struct drm_crtc *crtc, |
| 13561 | struct drm_framebuffer *fb, |
| 13562 | int crtc_x, int crtc_y, |
| 13563 | unsigned int crtc_w, unsigned int crtc_h, |
| 13564 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13565 | uint32_t src_w, uint32_t src_h, |
| 13566 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13567 | { |
| 13568 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13569 | int ret; |
| 13570 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13571 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13572 | struct drm_framebuffer *old_fb; |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13573 | struct intel_crtc_state *crtc_state = |
| 13574 | to_intel_crtc_state(crtc->state); |
| 13575 | struct intel_crtc_state *new_crtc_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13576 | |
| 13577 | /* |
| 13578 | * When crtc is inactive or there is a modeset pending, |
| 13579 | * wait for it to complete in the slowpath |
| 13580 | */ |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13581 | if (!crtc_state->base.active || needs_modeset(&crtc_state->base) || |
| 13582 | crtc_state->update_pipe) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13583 | goto slow; |
| 13584 | |
| 13585 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13586 | /* |
| 13587 | * Don't do an async update if there is an outstanding commit modifying |
| 13588 | * the plane. This prevents our async update's changes from getting |
| 13589 | * overridden by a previous synchronous update's state. |
| 13590 | */ |
| 13591 | if (old_plane_state->commit && |
| 13592 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 13593 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13594 | |
| 13595 | /* |
| 13596 | * If any parameters change that may affect watermarks, |
| 13597 | * take the slowpath. Only changing fb or position should be |
| 13598 | * in the fastpath. |
| 13599 | */ |
| 13600 | if (old_plane_state->crtc != crtc || |
| 13601 | old_plane_state->src_w != src_w || |
| 13602 | old_plane_state->src_h != src_h || |
| 13603 | old_plane_state->crtc_w != crtc_w || |
| 13604 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13605 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13606 | goto slow; |
| 13607 | |
| 13608 | new_plane_state = intel_plane_duplicate_state(plane); |
| 13609 | if (!new_plane_state) |
| 13610 | return -ENOMEM; |
| 13611 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13612 | new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc)); |
| 13613 | if (!new_crtc_state) { |
| 13614 | ret = -ENOMEM; |
| 13615 | goto out_free; |
| 13616 | } |
| 13617 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13618 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 13619 | |
| 13620 | new_plane_state->src_x = src_x; |
| 13621 | new_plane_state->src_y = src_y; |
| 13622 | new_plane_state->src_w = src_w; |
| 13623 | new_plane_state->src_h = src_h; |
| 13624 | new_plane_state->crtc_x = crtc_x; |
| 13625 | new_plane_state->crtc_y = crtc_y; |
| 13626 | new_plane_state->crtc_w = crtc_w; |
| 13627 | new_plane_state->crtc_h = crtc_h; |
| 13628 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13629 | ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state, |
| 13630 | to_intel_plane_state(old_plane_state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13631 | to_intel_plane_state(new_plane_state)); |
| 13632 | if (ret) |
| 13633 | goto out_free; |
| 13634 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13635 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13636 | if (ret) |
| 13637 | goto out_free; |
| 13638 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13639 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 13640 | if (ret) |
| 13641 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13642 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 13643 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13644 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13645 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13646 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 13647 | intel_plane->frontbuffer_bit); |
| 13648 | |
| 13649 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13650 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13651 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13652 | /* |
| 13653 | * We cannot swap crtc_state as it may be in use by an atomic commit or |
| 13654 | * page flip that's running simultaneously. If we swap crtc_state and |
| 13655 | * destroy the old state, we will cause a use-after-free there. |
| 13656 | * |
| 13657 | * Only update active_planes, which is needed for our internal |
| 13658 | * bookkeeping. Either value will do the right thing when updating |
| 13659 | * planes atomically. If the cursor was part of the atomic update then |
| 13660 | * we would have taken the slowpath. |
| 13661 | */ |
| 13662 | crtc_state->active_planes = new_crtc_state->active_planes; |
| 13663 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13664 | if (plane->state->visible) { |
| 13665 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13666 | intel_plane->update_plane(intel_plane, crtc_state, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13667 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13668 | } else { |
| 13669 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 13670 | intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13671 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13672 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13673 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13674 | |
| 13675 | out_unlock: |
| 13676 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 13677 | out_free: |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13678 | if (new_crtc_state) |
| 13679 | intel_crtc_destroy_state(crtc, &new_crtc_state->base); |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13680 | if (ret) |
| 13681 | intel_plane_destroy_state(plane, new_plane_state); |
| 13682 | else |
| 13683 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13684 | return ret; |
| 13685 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13686 | slow: |
| 13687 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 13688 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13689 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13690 | } |
| 13691 | |
| 13692 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 13693 | .update_plane = intel_legacy_cursor_update, |
| 13694 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13695 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13696 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13697 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13698 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13699 | .atomic_destroy_state = intel_plane_destroy_state, |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13700 | .format_mod_supported = intel_cursor_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13701 | }; |
| 13702 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13703 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 13704 | enum i9xx_plane_id i9xx_plane) |
| 13705 | { |
| 13706 | if (!HAS_FBC(dev_priv)) |
| 13707 | return false; |
| 13708 | |
| 13709 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 13710 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 13711 | else if (IS_IVYBRIDGE(dev_priv)) |
| 13712 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 13713 | i9xx_plane == PLANE_C; |
| 13714 | else if (INTEL_GEN(dev_priv) >= 4) |
| 13715 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 13716 | else |
| 13717 | return i9xx_plane == PLANE_A; |
| 13718 | } |
| 13719 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13720 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13721 | 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] | 13722 | { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13723 | struct intel_plane *plane; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13724 | const struct drm_plane_funcs *plane_funcs; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13725 | unsigned int supported_rotations; |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13726 | unsigned int possible_crtcs; |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13727 | const u64 *modifiers; |
| 13728 | const u32 *formats; |
| 13729 | int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13730 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13731 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13732 | if (INTEL_GEN(dev_priv) >= 9) |
| 13733 | return skl_universal_plane_create(dev_priv, pipe, |
| 13734 | PLANE_PRIMARY); |
| 13735 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13736 | plane = intel_plane_alloc(); |
| 13737 | if (IS_ERR(plane)) |
| 13738 | return plane; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13739 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13740 | plane->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13741 | /* |
| 13742 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 13743 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 13744 | */ |
| 13745 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13746 | plane->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13747 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13748 | plane->i9xx_plane = (enum i9xx_plane_id) pipe; |
| 13749 | plane->id = PLANE_PRIMARY; |
| 13750 | plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13751 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13752 | plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane); |
| 13753 | if (plane->has_fbc) { |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13754 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 13755 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13756 | fbc->possible_framebuffer_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13757 | } |
| 13758 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13759 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13760 | formats = i965_primary_formats; |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13761 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13762 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13763 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13764 | plane->max_stride = i9xx_plane_max_stride; |
| 13765 | plane->update_plane = i9xx_update_plane; |
| 13766 | plane->disable_plane = i9xx_disable_plane; |
| 13767 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13768 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13769 | |
| 13770 | plane_funcs = &i965_plane_funcs; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13771 | } else { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13772 | formats = i8xx_primary_formats; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13773 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13774 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13775 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13776 | plane->max_stride = i9xx_plane_max_stride; |
| 13777 | plane->update_plane = i9xx_update_plane; |
| 13778 | plane->disable_plane = i9xx_disable_plane; |
| 13779 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13780 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13781 | |
| 13782 | plane_funcs = &i8xx_plane_funcs; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13783 | } |
| 13784 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13785 | possible_crtcs = BIT(pipe); |
| 13786 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13787 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13788 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13789 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13790 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13791 | DRM_PLANE_TYPE_PRIMARY, |
| 13792 | "primary %c", pipe_name(pipe)); |
| 13793 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13794 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13795 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13796 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13797 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13798 | "plane %c", |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13799 | plane_name(plane->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13800 | if (ret) |
| 13801 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13802 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13803 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 13804 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13805 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 13806 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13807 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13808 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13809 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13810 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13811 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13812 | } |
| 13813 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13814 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13815 | drm_plane_create_rotation_property(&plane->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13816 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13817 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13818 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13819 | drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13820 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13821 | return plane; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13822 | |
| 13823 | fail: |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13824 | intel_plane_free(plane); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13825 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13826 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13827 | } |
| 13828 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13829 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13830 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 13831 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13832 | { |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13833 | unsigned int possible_crtcs; |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13834 | struct intel_plane *cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13835 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13836 | |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13837 | cursor = intel_plane_alloc(); |
| 13838 | if (IS_ERR(cursor)) |
| 13839 | return cursor; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13840 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13841 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13842 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 13843 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 13844 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13845 | |
| 13846 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 13847 | cursor->max_stride = i845_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13848 | cursor->update_plane = i845_update_cursor; |
| 13849 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13850 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 13851 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13852 | } else { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 13853 | cursor->max_stride = i9xx_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13854 | cursor->update_plane = i9xx_update_cursor; |
| 13855 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13856 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 13857 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13858 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13859 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 13860 | cursor->cursor.base = ~0; |
| 13861 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 13862 | |
| 13863 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 13864 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13865 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13866 | possible_crtcs = BIT(pipe); |
| 13867 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13868 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13869 | possible_crtcs, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13870 | intel_cursor_formats, |
| 13871 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13872 | cursor_format_modifiers, |
| 13873 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13874 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13875 | if (ret) |
| 13876 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13877 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13878 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13879 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13880 | DRM_MODE_ROTATE_0, |
| 13881 | DRM_MODE_ROTATE_0 | |
| 13882 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13883 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13884 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 13885 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13886 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13887 | |
| 13888 | fail: |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13889 | intel_plane_free(cursor); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13890 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13891 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13892 | } |
| 13893 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13894 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 13895 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13896 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 13897 | struct intel_crtc_scaler_state *scaler_state = |
| 13898 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13899 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13900 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13901 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13902 | crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe]; |
| 13903 | if (!crtc->num_scalers) |
| 13904 | return; |
| 13905 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 13906 | for (i = 0; i < crtc->num_scalers; i++) { |
| 13907 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 13908 | |
| 13909 | scaler->in_use = 0; |
Maarten Lankhorst | 0aaf29b | 2018-09-21 16:44:37 +0200 | [diff] [blame] | 13910 | scaler->mode = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13911 | } |
| 13912 | |
| 13913 | scaler_state->scaler_id = -1; |
| 13914 | } |
| 13915 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 13916 | 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] | 13917 | { |
| 13918 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13919 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13920 | struct intel_plane *primary = NULL; |
| 13921 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13922 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13923 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 13924 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13925 | if (!intel_crtc) |
| 13926 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13927 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13928 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13929 | if (!crtc_state) { |
| 13930 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13931 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13932 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 13933 | intel_crtc->config = crtc_state; |
| 13934 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 13935 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13936 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13937 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13938 | if (IS_ERR(primary)) { |
| 13939 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13940 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13941 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13942 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13943 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13944 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13945 | struct intel_plane *plane; |
| 13946 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13947 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 13948 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13949 | ret = PTR_ERR(plane); |
| 13950 | goto fail; |
| 13951 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13952 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13953 | } |
| 13954 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13955 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 13956 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13957 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13958 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13959 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13960 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13961 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 13962 | 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] | 13963 | &primary->base, &cursor->base, |
| 13964 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 13965 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13966 | if (ret) |
| 13967 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13968 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13969 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13970 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13971 | /* initialize shared scalers */ |
| 13972 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 13973 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 13974 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 13975 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 13976 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 13977 | |
| 13978 | if (INTEL_GEN(dev_priv) < 9) { |
| 13979 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 13980 | |
| 13981 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 13982 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 13983 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 13984 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 13985 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13986 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13987 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 13988 | intel_color_init(&intel_crtc->base); |
| 13989 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13990 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13991 | |
| 13992 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13993 | |
| 13994 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13995 | /* |
| 13996 | * drm_mode_config_cleanup() will free up any |
| 13997 | * crtcs/planes already initialized. |
| 13998 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13999 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14000 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14001 | |
| 14002 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14003 | } |
| 14004 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 14005 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 14006 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14007 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14008 | 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] | 14009 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14010 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14011 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 14012 | 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] | 14013 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14014 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14015 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14016 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14017 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14018 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14019 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14020 | } |
| 14021 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14022 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14023 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14024 | struct drm_device *dev = encoder->base.dev; |
| 14025 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14026 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14027 | int entry = 0; |
| 14028 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14029 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14030 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14031 | index_mask |= (1 << entry); |
| 14032 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14033 | entry++; |
| 14034 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14035 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14036 | return index_mask; |
| 14037 | } |
| 14038 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14039 | static bool has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14040 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14041 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14042 | return false; |
| 14043 | |
| 14044 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14045 | return false; |
| 14046 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14047 | 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] | 14048 | return false; |
| 14049 | |
| 14050 | return true; |
| 14051 | } |
| 14052 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14053 | static bool intel_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14054 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14055 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14056 | return false; |
| 14057 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 14058 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14059 | return false; |
| 14060 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14061 | if (IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14062 | return false; |
| 14063 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14064 | if (HAS_PCH_LPT_H(dev_priv) && |
| 14065 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14066 | return false; |
| 14067 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14068 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14069 | 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] | 14070 | return false; |
| 14071 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14072 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14073 | return false; |
| 14074 | |
| 14075 | return true; |
| 14076 | } |
| 14077 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14078 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 14079 | { |
| 14080 | int pps_num; |
| 14081 | int pps_idx; |
| 14082 | |
| 14083 | if (HAS_DDI(dev_priv)) |
| 14084 | return; |
| 14085 | /* |
| 14086 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 14087 | * everywhere where registers can be write protected. |
| 14088 | */ |
| 14089 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14090 | pps_num = 2; |
| 14091 | else |
| 14092 | pps_num = 1; |
| 14093 | |
| 14094 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 14095 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 14096 | |
| 14097 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 14098 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 14099 | } |
| 14100 | } |
| 14101 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14102 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 14103 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 14104 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14105 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 14106 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14107 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 14108 | else |
| 14109 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14110 | |
| 14111 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14112 | } |
| 14113 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14114 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14115 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14116 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14117 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14118 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14119 | intel_pps_init(dev_priv); |
| 14120 | |
Chris Wilson | fc0c5a9 | 2018-08-15 21:12:07 +0100 | [diff] [blame] | 14121 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
| 14122 | return; |
| 14123 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 14124 | /* |
| 14125 | * intel_edp_init_connector() depends on this completing first, to |
| 14126 | * prevent the registeration of both eDP and LVDS and the incorrect |
| 14127 | * sharing of the PPS. |
| 14128 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14129 | intel_lvds_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14130 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14131 | if (intel_crt_present(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14132 | intel_crt_init(dev_priv); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14133 | |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14134 | if (IS_ICELAKE(dev_priv)) { |
| 14135 | intel_ddi_init(dev_priv, PORT_A); |
| 14136 | intel_ddi_init(dev_priv, PORT_B); |
| 14137 | intel_ddi_init(dev_priv, PORT_C); |
| 14138 | intel_ddi_init(dev_priv, PORT_D); |
| 14139 | intel_ddi_init(dev_priv, PORT_E); |
| 14140 | intel_ddi_init(dev_priv, PORT_F); |
Madhav Chauhan | bf4d57f | 2018-10-30 13:56:23 +0200 | [diff] [blame] | 14141 | icl_dsi_init(dev_priv); |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14142 | } else if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14143 | /* |
| 14144 | * FIXME: Broxton doesn't support port detection via the |
| 14145 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14146 | * detect the ports. |
| 14147 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14148 | intel_ddi_init(dev_priv, PORT_A); |
| 14149 | intel_ddi_init(dev_priv, PORT_B); |
| 14150 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14151 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14152 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14153 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14154 | int found; |
| 14155 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14156 | /* |
| 14157 | * Haswell uses DDI functions to detect digital outputs. |
| 14158 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14159 | * it's there. |
| 14160 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14161 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14162 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14163 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14164 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14165 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14166 | /* 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] | 14167 | * register */ |
| 14168 | found = I915_READ(SFUSE_STRAP); |
| 14169 | |
| 14170 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14171 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14172 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14173 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14174 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14175 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14176 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 14177 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14178 | /* |
| 14179 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14180 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14181 | if (IS_GEN9_BC(dev_priv) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14182 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 14183 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 14184 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14185 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14186 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14187 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14188 | int found; |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14189 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14190 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14191 | if (has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14192 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14193 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14194 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14195 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14196 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14197 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14198 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14199 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14200 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14201 | } |
| 14202 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14203 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14204 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14205 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14206 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14207 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14208 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14209 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14210 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14211 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14212 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14213 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14214 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14215 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 14216 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14217 | /* |
| 14218 | * The DP_DETECTED bit is the latched state of the DDC |
| 14219 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14220 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14221 | * eDP ports may have been muxed to an alternate function. |
| 14222 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14223 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14224 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14225 | * |
| 14226 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 14227 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 14228 | * and VBT for the presence of the port. Additionally we can't |
| 14229 | * trust the port type the VBT declares as we've seen at least |
| 14230 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14231 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14232 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14233 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14234 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14235 | 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] | 14236 | 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] | 14237 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14238 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14239 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14240 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14241 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14242 | 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] | 14243 | 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] | 14244 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14245 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14246 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14247 | /* |
| 14248 | * eDP not supported on port D, |
| 14249 | * so no need to worry about it |
| 14250 | */ |
| 14251 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14252 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14253 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14254 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14255 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14256 | } |
| 14257 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14258 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14259 | } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14260 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14261 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14262 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14263 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14264 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14265 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14266 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14267 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14268 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14269 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14270 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14271 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14272 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14273 | |
| 14274 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14275 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14276 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14277 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14278 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14279 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14280 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14281 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14282 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14283 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14284 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14285 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14286 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14287 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14288 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14289 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14290 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14291 | 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] | 14292 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14293 | } else if (IS_GEN2(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14294 | intel_dvo_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14295 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 14296 | if (SUPPORTS_TV(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14297 | intel_tv_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14298 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14299 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14300 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14301 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14302 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14303 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14304 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14305 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14306 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14307 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14308 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14309 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14310 | } |
| 14311 | |
| 14312 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14313 | { |
| 14314 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14315 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14316 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14317 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14318 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14319 | i915_gem_object_lock(obj); |
| 14320 | WARN_ON(!obj->framebuffer_references--); |
| 14321 | i915_gem_object_unlock(obj); |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14322 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14323 | i915_gem_object_put(obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14324 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14325 | kfree(intel_fb); |
| 14326 | } |
| 14327 | |
| 14328 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14329 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14330 | unsigned int *handle) |
| 14331 | { |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14332 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14333 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14334 | if (obj->userptr.mm) { |
| 14335 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14336 | return -EINVAL; |
| 14337 | } |
| 14338 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14339 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14340 | } |
| 14341 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14342 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14343 | struct drm_file *file, |
| 14344 | unsigned flags, unsigned color, |
| 14345 | struct drm_clip_rect *clips, |
| 14346 | unsigned num_clips) |
| 14347 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14348 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14349 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14350 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14351 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14352 | |
| 14353 | return 0; |
| 14354 | } |
| 14355 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14356 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14357 | .destroy = intel_user_framebuffer_destroy, |
| 14358 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14359 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14360 | }; |
| 14361 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14362 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14363 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14364 | u32 pixel_format, u64 fb_modifier) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14365 | { |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14366 | struct intel_crtc *crtc; |
| 14367 | struct intel_plane *plane; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14368 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14369 | /* |
| 14370 | * We assume the primary plane for pipe A has |
| 14371 | * the highest stride limits of them all. |
| 14372 | */ |
| 14373 | crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A); |
| 14374 | plane = to_intel_plane(crtc->base.primary); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14375 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14376 | return plane->max_stride(plane, pixel_format, fb_modifier, |
| 14377 | DRM_MODE_ROTATE_0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14378 | } |
| 14379 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14380 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14381 | struct drm_i915_gem_object *obj, |
| 14382 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14383 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14384 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14385 | struct drm_framebuffer *fb = &intel_fb->base; |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 14386 | struct drm_format_name_buf format_name; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14387 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14388 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14389 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14390 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14391 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14392 | i915_gem_object_lock(obj); |
| 14393 | obj->framebuffer_references++; |
| 14394 | tiling = i915_gem_object_get_tiling(obj); |
| 14395 | stride = i915_gem_object_get_stride(obj); |
| 14396 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14397 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14398 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14399 | /* |
| 14400 | * If there's a fence, enforce that |
| 14401 | * the fb modifier and tiling mode match. |
| 14402 | */ |
| 14403 | if (tiling != I915_TILING_NONE && |
| 14404 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14405 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14406 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14407 | } |
| 14408 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14409 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14410 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14411 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14412 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14413 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14414 | } |
| 14415 | } |
| 14416 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14417 | /* Passed in modifier sanity checking. */ |
| 14418 | switch (mode_cmd->modifier[0]) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14419 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 14420 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 14421 | switch (mode_cmd->pixel_format) { |
| 14422 | case DRM_FORMAT_XBGR8888: |
| 14423 | case DRM_FORMAT_ABGR8888: |
| 14424 | case DRM_FORMAT_XRGB8888: |
| 14425 | case DRM_FORMAT_ARGB8888: |
| 14426 | break; |
| 14427 | default: |
| 14428 | DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n"); |
| 14429 | goto err; |
| 14430 | } |
| 14431 | /* fall through */ |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14432 | case I915_FORMAT_MOD_Yf_TILED: |
Paulo Zanoni | ef51e0a | 2018-09-24 17:19:11 -0700 | [diff] [blame] | 14433 | if (mode_cmd->pixel_format == DRM_FORMAT_C8) { |
| 14434 | DRM_DEBUG_KMS("Indexed format does not support Yf tiling\n"); |
| 14435 | goto err; |
| 14436 | } |
| 14437 | /* fall through */ |
| 14438 | case I915_FORMAT_MOD_Y_TILED: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14439 | if (INTEL_GEN(dev_priv) < 9) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14440 | DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n", |
| 14441 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14442 | goto err; |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14443 | } |
Paulo Zanoni | ef51e0a | 2018-09-24 17:19:11 -0700 | [diff] [blame] | 14444 | break; |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14445 | case DRM_FORMAT_MOD_LINEAR: |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14446 | case I915_FORMAT_MOD_X_TILED: |
| 14447 | break; |
| 14448 | default: |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14449 | DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n", |
| 14450 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14451 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14452 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14453 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14454 | /* |
| 14455 | * gen2/3 display engine uses the fence if present, |
| 14456 | * so the tiling mode must match the fb modifier exactly. |
| 14457 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14458 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14459 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14460 | 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] | 14461 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14462 | } |
| 14463 | |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14464 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format, |
| 14465 | mode_cmd->modifier[0]); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14466 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14467 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14468 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14469 | "tiled" : "linear", |
| 14470 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14471 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14472 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14473 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14474 | /* |
| 14475 | * If there's a fence, enforce that |
| 14476 | * the fb pitch and fence stride match. |
| 14477 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14478 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14479 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14480 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14481 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14482 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14483 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14484 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14485 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14486 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14487 | case DRM_FORMAT_RGB565: |
| 14488 | case DRM_FORMAT_XRGB8888: |
| 14489 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14490 | break; |
| 14491 | case DRM_FORMAT_XRGB1555: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14492 | if (INTEL_GEN(dev_priv) > 3) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14493 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14494 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14495 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14496 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14497 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14498 | case DRM_FORMAT_ABGR8888: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14499 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14500 | INTEL_GEN(dev_priv) < 9) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14501 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14502 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14503 | goto err; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14504 | } |
| 14505 | break; |
| 14506 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14507 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14508 | case DRM_FORMAT_XBGR2101010: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14509 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14510 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14511 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14512 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14513 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14514 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14515 | case DRM_FORMAT_ABGR2101010: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14516 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14517 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14518 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14519 | goto err; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14520 | } |
| 14521 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14522 | case DRM_FORMAT_YUYV: |
| 14523 | case DRM_FORMAT_UYVY: |
| 14524 | case DRM_FORMAT_YVYU: |
| 14525 | case DRM_FORMAT_VYUY: |
Ville Syrjälä | ab33081 | 2017-04-21 21:14:32 +0300 | [diff] [blame] | 14526 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14527 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14528 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14529 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14530 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14531 | break; |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14532 | case DRM_FORMAT_NV12: |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14533 | if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) || |
Maarten Lankhorst | 26ee5bc | 2018-10-22 15:45:14 +0200 | [diff] [blame] | 14534 | IS_BROXTON(dev_priv)) { |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14535 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14536 | drm_get_format_name(mode_cmd->pixel_format, |
| 14537 | &format_name)); |
| 14538 | goto err; |
| 14539 | } |
| 14540 | break; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14541 | default: |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14542 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14543 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14544 | goto err; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14545 | } |
| 14546 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14547 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14548 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14549 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14550 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14551 | 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] | 14552 | |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14553 | if (fb->format->format == DRM_FORMAT_NV12 && |
| 14554 | (fb->width < SKL_MIN_YUV_420_SRC_W || |
| 14555 | fb->height < SKL_MIN_YUV_420_SRC_H || |
| 14556 | (fb->width % 4) != 0 || (fb->height % 4) != 0)) { |
| 14557 | DRM_DEBUG_KMS("src dimensions not correct for NV12\n"); |
Ville Syrjälä | 3b90946 | 2018-10-29 16:00:31 +0200 | [diff] [blame] | 14558 | goto err; |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14559 | } |
| 14560 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14561 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14562 | u32 stride_alignment; |
| 14563 | |
| 14564 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14565 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14566 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14567 | } |
| 14568 | |
| 14569 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14570 | |
| 14571 | /* |
| 14572 | * Display WA #0531: skl,bxt,kbl,glk |
| 14573 | * |
| 14574 | * Render decompression and plane width > 3840 |
| 14575 | * combined with horizontal panning requires the |
| 14576 | * plane stride to be a multiple of 4. We'll just |
| 14577 | * require the entire fb to accommodate that to avoid |
| 14578 | * potential runtime errors at plane configuration time. |
| 14579 | */ |
| 14580 | if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 && |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 14581 | is_ccs_modifier(fb->modifier)) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14582 | stride_alignment *= 4; |
| 14583 | |
| 14584 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14585 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14586 | i, fb->pitches[i], stride_alignment); |
| 14587 | goto err; |
| 14588 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14589 | |
Daniel Stone | a268bcd | 2018-05-18 15:30:08 +0100 | [diff] [blame] | 14590 | fb->obj[i] = &obj->base; |
| 14591 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14592 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14593 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14594 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14595 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14596 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14597 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14598 | if (ret) { |
| 14599 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14600 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14601 | } |
| 14602 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14603 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14604 | |
| 14605 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14606 | i915_gem_object_lock(obj); |
| 14607 | obj->framebuffer_references--; |
| 14608 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14609 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14610 | } |
| 14611 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14612 | static struct drm_framebuffer * |
| 14613 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14614 | struct drm_file *filp, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14615 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14616 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14617 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14618 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14619 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14620 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14621 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14622 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14623 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14624 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14625 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14626 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14627 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14628 | |
| 14629 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14630 | } |
| 14631 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14632 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14633 | { |
| 14634 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14635 | |
| 14636 | drm_atomic_state_default_release(state); |
| 14637 | |
| 14638 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14639 | |
| 14640 | kfree(state); |
| 14641 | } |
| 14642 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14643 | static enum drm_mode_status |
| 14644 | intel_mode_valid(struct drm_device *dev, |
| 14645 | const struct drm_display_mode *mode) |
| 14646 | { |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14647 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14648 | int hdisplay_max, htotal_max; |
| 14649 | int vdisplay_max, vtotal_max; |
| 14650 | |
Ville Syrjälä | e4dd27a | 2018-05-24 15:54:03 +0300 | [diff] [blame] | 14651 | /* |
| 14652 | * Can't reject DBLSCAN here because Xorg ddxen can add piles |
| 14653 | * of DBLSCAN modes to the output's mode list when they detect |
| 14654 | * the scaling mode property on the connector. And they don't |
| 14655 | * ask the kernel to validate those modes in any way until |
| 14656 | * modeset time at which point the client gets a protocol error. |
| 14657 | * So in order to not upset those clients we silently ignore the |
| 14658 | * DBLSCAN flag on such connectors. For other connectors we will |
| 14659 | * reject modes with the DBLSCAN flag in encoder->compute_config(). |
| 14660 | * And we always reject DBLSCAN modes in connector->mode_valid() |
| 14661 | * as we never want such modes on the connector's mode list. |
| 14662 | */ |
| 14663 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14664 | if (mode->vscan > 1) |
| 14665 | return MODE_NO_VSCAN; |
| 14666 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14667 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 14668 | return MODE_H_ILLEGAL; |
| 14669 | |
| 14670 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 14671 | DRM_MODE_FLAG_NCSYNC | |
| 14672 | DRM_MODE_FLAG_PCSYNC)) |
| 14673 | return MODE_HSYNC; |
| 14674 | |
| 14675 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 14676 | DRM_MODE_FLAG_PIXMUX | |
| 14677 | DRM_MODE_FLAG_CLKDIV2)) |
| 14678 | return MODE_BAD; |
| 14679 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14680 | if (INTEL_GEN(dev_priv) >= 9 || |
| 14681 | IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { |
| 14682 | hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ |
| 14683 | vdisplay_max = 4096; |
| 14684 | htotal_max = 8192; |
| 14685 | vtotal_max = 8192; |
| 14686 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 14687 | hdisplay_max = 4096; |
| 14688 | vdisplay_max = 4096; |
| 14689 | htotal_max = 8192; |
| 14690 | vtotal_max = 8192; |
| 14691 | } else { |
| 14692 | hdisplay_max = 2048; |
| 14693 | vdisplay_max = 2048; |
| 14694 | htotal_max = 4096; |
| 14695 | vtotal_max = 4096; |
| 14696 | } |
| 14697 | |
| 14698 | if (mode->hdisplay > hdisplay_max || |
| 14699 | mode->hsync_start > htotal_max || |
| 14700 | mode->hsync_end > htotal_max || |
| 14701 | mode->htotal > htotal_max) |
| 14702 | return MODE_H_ILLEGAL; |
| 14703 | |
| 14704 | if (mode->vdisplay > vdisplay_max || |
| 14705 | mode->vsync_start > vtotal_max || |
| 14706 | mode->vsync_end > vtotal_max || |
| 14707 | mode->vtotal > vtotal_max) |
| 14708 | return MODE_V_ILLEGAL; |
| 14709 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14710 | return MODE_OK; |
| 14711 | } |
| 14712 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14713 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14714 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 14715 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14716 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14717 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14718 | .atomic_check = intel_atomic_check, |
| 14719 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14720 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14721 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14722 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14723 | }; |
| 14724 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14725 | /** |
| 14726 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14727 | * @dev_priv: device private |
| 14728 | */ |
| 14729 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14730 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 14731 | intel_init_cdclk_hooks(dev_priv); |
| 14732 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14733 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14734 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14735 | dev_priv->display.get_initial_plane_config = |
| 14736 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14737 | dev_priv->display.crtc_compute_clock = |
| 14738 | haswell_crtc_compute_clock; |
| 14739 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14740 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14741 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14742 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14743 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14744 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14745 | dev_priv->display.crtc_compute_clock = |
| 14746 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14747 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14748 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14749 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14750 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14751 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14752 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14753 | dev_priv->display.crtc_compute_clock = |
| 14754 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14755 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14756 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14757 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14758 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14759 | dev_priv->display.get_initial_plane_config = |
| 14760 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14761 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 14762 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14763 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14764 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 14765 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14766 | dev_priv->display.get_initial_plane_config = |
| 14767 | i9xx_get_initial_plane_config; |
| 14768 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14769 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14770 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 14771 | } else if (IS_G4X(dev_priv)) { |
| 14772 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14773 | dev_priv->display.get_initial_plane_config = |
| 14774 | i9xx_get_initial_plane_config; |
| 14775 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 14776 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14777 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 14778 | } else if (IS_PINEVIEW(dev_priv)) { |
| 14779 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14780 | dev_priv->display.get_initial_plane_config = |
| 14781 | i9xx_get_initial_plane_config; |
| 14782 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 14783 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14784 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14785 | } else if (!IS_GEN2(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14786 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14787 | dev_priv->display.get_initial_plane_config = |
| 14788 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14789 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14790 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14791 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14792 | } else { |
| 14793 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14794 | dev_priv->display.get_initial_plane_config = |
| 14795 | i9xx_get_initial_plane_config; |
| 14796 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 14797 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14798 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14799 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14800 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14801 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14802 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14803 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14804 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14805 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14806 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14807 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14808 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14809 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 14810 | } |
| 14811 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 14812 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14813 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 14814 | else |
| 14815 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14816 | } |
| 14817 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14818 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 14819 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14820 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14821 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14822 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14823 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14824 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14825 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14826 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14827 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14828 | sr1 = inb(VGA_SR_DATA); |
| 14829 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14830 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14831 | udelay(300); |
| 14832 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14833 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14834 | POSTING_READ(vga_reg); |
| 14835 | } |
| 14836 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14837 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14838 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14839 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 14840 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 14841 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 14842 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 14843 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14844 | } |
| 14845 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14846 | /* |
| 14847 | * Calculate what we think the watermarks should be for the state we've read |
| 14848 | * out of the hardware and then immediately program those watermarks so that |
| 14849 | * we ensure the hardware settings match our internal state. |
| 14850 | * |
| 14851 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 14852 | * current state (which was constructed during hardware readout) and running it |
| 14853 | * through the atomic check code to calculate new watermark values in the |
| 14854 | * state object. |
| 14855 | */ |
| 14856 | static void sanitize_watermarks(struct drm_device *dev) |
| 14857 | { |
| 14858 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14859 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14860 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14861 | struct drm_crtc *crtc; |
| 14862 | struct drm_crtc_state *cstate; |
| 14863 | struct drm_modeset_acquire_ctx ctx; |
| 14864 | int ret; |
| 14865 | int i; |
| 14866 | |
| 14867 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14868 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14869 | return; |
| 14870 | |
| 14871 | /* |
| 14872 | * We need to hold connection_mutex before calling duplicate_state so |
| 14873 | * that the connector loop is protected. |
| 14874 | */ |
| 14875 | drm_modeset_acquire_init(&ctx, 0); |
| 14876 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14877 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14878 | if (ret == -EDEADLK) { |
| 14879 | drm_modeset_backoff(&ctx); |
| 14880 | goto retry; |
| 14881 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14882 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14883 | } |
| 14884 | |
| 14885 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 14886 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14887 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14888 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14889 | intel_state = to_intel_atomic_state(state); |
| 14890 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14891 | /* |
| 14892 | * Hardware readout is the only time we don't want to calculate |
| 14893 | * intermediate watermarks (since we don't trust the current |
| 14894 | * watermarks). |
| 14895 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 14896 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 14897 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14898 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14899 | ret = intel_atomic_check(dev, state); |
| 14900 | if (ret) { |
| 14901 | /* |
| 14902 | * If we fail here, it means that the hardware appears to be |
| 14903 | * programmed in a way that shouldn't be possible, given our |
| 14904 | * understanding of watermark requirements. This might mean a |
| 14905 | * mistake in the hardware readout code or a mistake in the |
| 14906 | * watermark calculations for a given platform. Raise a WARN |
| 14907 | * so that this is noticeable. |
| 14908 | * |
| 14909 | * If this actually happens, we'll have to just leave the |
| 14910 | * BIOS-programmed watermarks untouched and hope for the best. |
| 14911 | */ |
| 14912 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14913 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14914 | } |
| 14915 | |
| 14916 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 14917 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14918 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 14919 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14920 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14921 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 14922 | |
| 14923 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14924 | } |
| 14925 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14926 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14927 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14928 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14929 | drm_modeset_drop_locks(&ctx); |
| 14930 | drm_modeset_acquire_fini(&ctx); |
| 14931 | } |
| 14932 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 14933 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 14934 | { |
| 14935 | if (IS_GEN5(dev_priv)) { |
| 14936 | u32 fdi_pll_clk = |
| 14937 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 14938 | |
| 14939 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
| 14940 | } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) { |
| 14941 | dev_priv->fdi_pll_freq = 270000; |
| 14942 | } else { |
| 14943 | return; |
| 14944 | } |
| 14945 | |
| 14946 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 14947 | } |
| 14948 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 14949 | static int intel_initial_commit(struct drm_device *dev) |
| 14950 | { |
| 14951 | struct drm_atomic_state *state = NULL; |
| 14952 | struct drm_modeset_acquire_ctx ctx; |
| 14953 | struct drm_crtc *crtc; |
| 14954 | struct drm_crtc_state *crtc_state; |
| 14955 | int ret = 0; |
| 14956 | |
| 14957 | state = drm_atomic_state_alloc(dev); |
| 14958 | if (!state) |
| 14959 | return -ENOMEM; |
| 14960 | |
| 14961 | drm_modeset_acquire_init(&ctx, 0); |
| 14962 | |
| 14963 | retry: |
| 14964 | state->acquire_ctx = &ctx; |
| 14965 | |
| 14966 | drm_for_each_crtc(crtc, dev) { |
| 14967 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 14968 | if (IS_ERR(crtc_state)) { |
| 14969 | ret = PTR_ERR(crtc_state); |
| 14970 | goto out; |
| 14971 | } |
| 14972 | |
| 14973 | if (crtc_state->active) { |
| 14974 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 14975 | if (ret) |
| 14976 | goto out; |
| 14977 | } |
| 14978 | } |
| 14979 | |
| 14980 | ret = drm_atomic_commit(state); |
| 14981 | |
| 14982 | out: |
| 14983 | if (ret == -EDEADLK) { |
| 14984 | drm_atomic_state_clear(state); |
| 14985 | drm_modeset_backoff(&ctx); |
| 14986 | goto retry; |
| 14987 | } |
| 14988 | |
| 14989 | drm_atomic_state_put(state); |
| 14990 | |
| 14991 | drm_modeset_drop_locks(&ctx); |
| 14992 | drm_modeset_acquire_fini(&ctx); |
| 14993 | |
| 14994 | return ret; |
| 14995 | } |
| 14996 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14997 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14998 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 14999 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15000 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15001 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15002 | struct intel_crtc *crtc; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15003 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15004 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15005 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 15006 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15007 | drm_mode_config_init(dev); |
| 15008 | |
| 15009 | dev->mode_config.min_width = 0; |
| 15010 | dev->mode_config.min_height = 0; |
| 15011 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15012 | dev->mode_config.preferred_depth = 24; |
| 15013 | dev->mode_config.prefer_shadow = 1; |
| 15014 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15015 | dev->mode_config.allow_fb_modifiers = true; |
| 15016 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15017 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15018 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 15019 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15020 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 15021 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15022 | |
Jani Nikula | 27a981b | 2018-10-17 12:35:39 +0300 | [diff] [blame] | 15023 | intel_init_quirks(dev_priv); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15024 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 15025 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15026 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15027 | /* |
| 15028 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15029 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15030 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15031 | * indicates as much. |
| 15032 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15033 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15034 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15035 | DREF_SSC1_ENABLE); |
| 15036 | |
| 15037 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15038 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15039 | bios_lvds_use_ssc ? "en" : "dis", |
| 15040 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15041 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15042 | } |
| 15043 | } |
| 15044 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15045 | /* maximum framebuffer dimensions */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15046 | if (IS_GEN2(dev_priv)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15047 | dev->mode_config.max_width = 2048; |
| 15048 | dev->mode_config.max_height = 2048; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15049 | } else if (IS_GEN3(dev_priv)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15050 | dev->mode_config.max_width = 4096; |
| 15051 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15052 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15053 | dev->mode_config.max_width = 8192; |
| 15054 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15055 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15056 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 15057 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 15058 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15059 | dev->mode_config.cursor_height = 1023; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15060 | } else if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15061 | dev->mode_config.cursor_width = 64; |
| 15062 | dev->mode_config.cursor_height = 64; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15063 | } else { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15064 | dev->mode_config.cursor_width = 256; |
| 15065 | dev->mode_config.cursor_height = 256; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15066 | } |
| 15067 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 15068 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15069 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15070 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15071 | INTEL_INFO(dev_priv)->num_pipes, |
| 15072 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15073 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15074 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15075 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15076 | if (ret) { |
| 15077 | drm_mode_config_cleanup(dev); |
| 15078 | return ret; |
| 15079 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15080 | } |
| 15081 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15082 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15083 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15084 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 15085 | intel_update_czclk(dev_priv); |
| 15086 | intel_modeset_init_hw(dev); |
| 15087 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15088 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15089 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15090 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15091 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15092 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15093 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15094 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15095 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15096 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15097 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15098 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15099 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15100 | struct intel_initial_plane_config plane_config = {}; |
| 15101 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15102 | if (!crtc->active) |
| 15103 | continue; |
| 15104 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15105 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15106 | * Note that reserving the BIOS fb up front prevents us |
| 15107 | * from stuffing other stolen allocations like the ring |
| 15108 | * on top. This prevents some ugliness at boot time, and |
| 15109 | * can even allow for smooth boot transitions if the BIOS |
| 15110 | * fb is large enough for the active pipe configuration. |
| 15111 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15112 | dev_priv->display.get_initial_plane_config(crtc, |
| 15113 | &plane_config); |
| 15114 | |
| 15115 | /* |
| 15116 | * If the fb is shared between multiple heads, we'll |
| 15117 | * just get the first one. |
| 15118 | */ |
| 15119 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15120 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15121 | |
| 15122 | /* |
| 15123 | * Make sure hardware watermarks really match the state we read out. |
| 15124 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15125 | * since the watermark calculation done here will use pstate->fb. |
| 15126 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15127 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 15128 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15129 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15130 | /* |
| 15131 | * Force all active planes to recompute their states. So that on |
| 15132 | * mode_setcrtc after probe, all the intel_plane_state variables |
| 15133 | * are already calculated and there is no assert_plane warnings |
| 15134 | * during bootup. |
| 15135 | */ |
| 15136 | ret = intel_initial_commit(dev); |
| 15137 | if (ret) |
| 15138 | DRM_DEBUG_KMS("Initial commit in probe failed.\n"); |
| 15139 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15140 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15141 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15142 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15143 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15144 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15145 | 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] | 15146 | /* 640x480@60Hz, ~25175 kHz */ |
| 15147 | struct dpll clock = { |
| 15148 | .m1 = 18, |
| 15149 | .m2 = 7, |
| 15150 | .p1 = 13, |
| 15151 | .p2 = 4, |
| 15152 | .n = 2, |
| 15153 | }; |
| 15154 | u32 dpll, fp; |
| 15155 | int i; |
| 15156 | |
| 15157 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 15158 | |
| 15159 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 15160 | pipe_name(pipe), clock.vco, clock.dot); |
| 15161 | |
| 15162 | fp = i9xx_dpll_compute_fp(&clock); |
| 15163 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 15164 | DPLL_VGA_MODE_DIS | |
| 15165 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 15166 | PLL_P2_DIVIDE_BY_4 | |
| 15167 | PLL_REF_INPUT_DREFCLK | |
| 15168 | DPLL_VCO_ENABLE; |
| 15169 | |
| 15170 | I915_WRITE(FP0(pipe), fp); |
| 15171 | I915_WRITE(FP1(pipe), fp); |
| 15172 | |
| 15173 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15174 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15175 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15176 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15177 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15178 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15179 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15180 | |
| 15181 | /* |
| 15182 | * Apparently we need to have VGA mode enabled prior to changing |
| 15183 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15184 | * dividers, even though the register value does change. |
| 15185 | */ |
| 15186 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15187 | I915_WRITE(DPLL(pipe), dpll); |
| 15188 | |
| 15189 | /* Wait for the clocks to stabilize. */ |
| 15190 | POSTING_READ(DPLL(pipe)); |
| 15191 | udelay(150); |
| 15192 | |
| 15193 | /* The pixel multiplier can only be updated once the |
| 15194 | * DPLL is enabled and the clocks are stable. |
| 15195 | * |
| 15196 | * So write it again. |
| 15197 | */ |
| 15198 | I915_WRITE(DPLL(pipe), dpll); |
| 15199 | |
| 15200 | /* We do this three times for luck */ |
| 15201 | for (i = 0; i < 3 ; i++) { |
| 15202 | I915_WRITE(DPLL(pipe), dpll); |
| 15203 | POSTING_READ(DPLL(pipe)); |
| 15204 | udelay(150); /* wait for warmup */ |
| 15205 | } |
| 15206 | |
| 15207 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15208 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15209 | |
| 15210 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15211 | } |
| 15212 | |
| 15213 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15214 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15215 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15216 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15217 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15218 | pipe_name(pipe)); |
| 15219 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15220 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15221 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15222 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 15223 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE); |
| 15224 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15225 | |
| 15226 | I915_WRITE(PIPECONF(pipe), 0); |
| 15227 | POSTING_READ(PIPECONF(pipe)); |
| 15228 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15229 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15230 | |
| 15231 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15232 | POSTING_READ(DPLL(pipe)); |
| 15233 | } |
| 15234 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15235 | static void |
| 15236 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15237 | { |
| 15238 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15239 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15240 | if (INTEL_GEN(dev_priv) >= 4) |
| 15241 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15242 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15243 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15244 | struct intel_plane *plane = |
| 15245 | to_intel_plane(crtc->base.primary); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15246 | struct intel_crtc *plane_crtc; |
| 15247 | enum pipe pipe; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15248 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15249 | if (!plane->get_hw_state(plane, &pipe)) |
| 15250 | continue; |
| 15251 | |
| 15252 | if (pipe == crtc->pipe) |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15253 | continue; |
| 15254 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15255 | DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", |
| 15256 | plane->base.base.id, plane->base.name); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15257 | |
| 15258 | plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15259 | intel_plane_disable_noatomic(plane_crtc, plane); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15260 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15261 | } |
| 15262 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15263 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15264 | { |
| 15265 | struct drm_device *dev = crtc->base.dev; |
| 15266 | struct intel_encoder *encoder; |
| 15267 | |
| 15268 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15269 | return true; |
| 15270 | |
| 15271 | return false; |
| 15272 | } |
| 15273 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15274 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15275 | { |
| 15276 | struct drm_device *dev = encoder->base.dev; |
| 15277 | struct intel_connector *connector; |
| 15278 | |
| 15279 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15280 | return connector; |
| 15281 | |
| 15282 | return NULL; |
| 15283 | } |
| 15284 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15285 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15286 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15287 | { |
| 15288 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15289 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15290 | } |
| 15291 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15292 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15293 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15294 | { |
| 15295 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15296 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15297 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15298 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15299 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15300 | /* 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] | 15301 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15302 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15303 | |
| 15304 | I915_WRITE(reg, |
| 15305 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15306 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15307 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15308 | if (crtc_state->base.active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15309 | struct intel_plane *plane; |
| 15310 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15311 | /* Disable everything but the primary plane */ |
| 15312 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15313 | const struct intel_plane_state *plane_state = |
| 15314 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15315 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15316 | if (plane_state->base.visible && |
| 15317 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15318 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15319 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15320 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15321 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15322 | /* Adjust the state of the output pipe according to whether we |
| 15323 | * have active connectors/encoders. */ |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15324 | if (crtc_state->base.active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15325 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15326 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15327 | if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15328 | /* |
| 15329 | * We start out with underrun reporting disabled to avoid races. |
| 15330 | * For correct bookkeeping mark this on active crtcs. |
| 15331 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15332 | * Also on gmch platforms we dont have any hardware bits to |
| 15333 | * disable the underrun reporting. Which means we need to start |
| 15334 | * out with underrun reporting disabled also on inactive pipes, |
| 15335 | * since otherwise we'll complain about the garbage we read when |
| 15336 | * e.g. coming up after runtime pm. |
| 15337 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15338 | * No protection against concurrent access is required - at |
| 15339 | * worst a fifo underrun happens which also sets this to false. |
| 15340 | */ |
| 15341 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15342 | /* |
| 15343 | * We track the PCH trancoder underrun reporting state |
| 15344 | * within the crtc. With crtc for pipe A housing the underrun |
| 15345 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15346 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15347 | * and marking underrun reporting as disabled for the non-existing |
| 15348 | * PCH transcoders B and C would prevent enabling the south |
| 15349 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15350 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15351 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15352 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15353 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15354 | } |
| 15355 | |
| 15356 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15357 | { |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15358 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15359 | struct intel_connector *connector; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15360 | |
| 15361 | /* We need to check both for a crtc link (meaning that the |
| 15362 | * encoder is active and trying to read from a pipe) and the |
| 15363 | * pipe itself being active. */ |
| 15364 | bool has_active_crtc = encoder->base.crtc && |
| 15365 | to_intel_crtc(encoder->base.crtc)->active; |
| 15366 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15367 | connector = intel_encoder_find_connector(encoder); |
| 15368 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15369 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15370 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15371 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15372 | |
| 15373 | /* Connector is active, but has no active pipe. This is |
| 15374 | * fallout from our resume register restoring. Disable |
| 15375 | * the encoder manually again. */ |
| 15376 | if (encoder->base.crtc) { |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15377 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
| 15378 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15379 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15380 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15381 | encoder->base.name); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 15382 | if (encoder->disable) |
| 15383 | 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] | 15384 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15385 | 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] | 15386 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15387 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15388 | |
| 15389 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15390 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15391 | * in our code, like the register restore mess on resume. Clamp |
| 15392 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15393 | |
| 15394 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15395 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15396 | } |
Maarten Lankhorst | d6cae4a | 2018-05-16 10:50:38 +0200 | [diff] [blame] | 15397 | |
| 15398 | /* notify opregion of the sanitized encoder state */ |
| 15399 | intel_opregion_notify_encoder(encoder, connector && has_active_crtc); |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15400 | |
| 15401 | if (INTEL_GEN(dev_priv) >= 11) |
| 15402 | icl_sanitize_encoder_pll_mapping(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15403 | } |
| 15404 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15405 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15406 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15407 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15408 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15409 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15410 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15411 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15412 | } |
| 15413 | } |
| 15414 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15415 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15416 | { |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15417 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15418 | * at a very early point in our resume sequence, where the power well |
| 15419 | * structures are not yet restored. Since this function is at a very |
| 15420 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15421 | * level, just check if the power well is enabled instead of trying to |
| 15422 | * follow the "don't touch the power well if we don't need it" policy |
| 15423 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15424 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15425 | return; |
| 15426 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15427 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15428 | |
| 15429 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15430 | } |
| 15431 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15432 | /* FIXME read out full plane state for all planes */ |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15433 | static void readout_plane_state(struct drm_i915_private *dev_priv) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15434 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15435 | struct intel_plane *plane; |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15436 | struct intel_crtc *crtc; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15437 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15438 | for_each_intel_plane(&dev_priv->drm, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15439 | struct intel_plane_state *plane_state = |
| 15440 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15441 | struct intel_crtc_state *crtc_state; |
| 15442 | enum pipe pipe = PIPE_A; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 15443 | bool visible; |
| 15444 | |
| 15445 | visible = plane->get_hw_state(plane, &pipe); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15446 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15447 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15448 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15449 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15450 | intel_set_plane_visible(crtc_state, plane_state, visible); |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15451 | |
| 15452 | DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n", |
| 15453 | plane->base.base.id, plane->base.name, |
| 15454 | enableddisabled(visible), pipe_name(pipe)); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15455 | } |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15456 | |
| 15457 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15458 | struct intel_crtc_state *crtc_state = |
| 15459 | to_intel_crtc_state(crtc->base.state); |
| 15460 | |
| 15461 | fixup_active_planes(crtc_state); |
| 15462 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15463 | } |
| 15464 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15465 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15466 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15467 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15468 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15469 | struct intel_crtc *crtc; |
| 15470 | struct intel_encoder *encoder; |
| 15471 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15472 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15473 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15474 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15475 | dev_priv->active_crtcs = 0; |
| 15476 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15477 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15478 | struct intel_crtc_state *crtc_state = |
| 15479 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15480 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15481 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15482 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15483 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15484 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15485 | crtc_state->base.active = crtc_state->base.enable = |
| 15486 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15487 | |
| 15488 | crtc->base.enabled = crtc_state->base.enable; |
| 15489 | crtc->active = crtc_state->base.active; |
| 15490 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15491 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15492 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15493 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15494 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15495 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15496 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15497 | } |
| 15498 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15499 | readout_plane_state(dev_priv); |
| 15500 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15501 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15502 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15503 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15504 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15505 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15506 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15507 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15508 | struct intel_crtc_state *crtc_state = |
| 15509 | to_intel_crtc_state(crtc->base.state); |
| 15510 | |
| 15511 | if (crtc_state->base.active && |
| 15512 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15513 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15514 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15515 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15516 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15517 | 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] | 15518 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15519 | } |
| 15520 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15521 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15522 | pipe = 0; |
| 15523 | |
| 15524 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15525 | struct intel_crtc_state *crtc_state; |
| 15526 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15527 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15528 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15529 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15530 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15531 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15532 | } else { |
| 15533 | encoder->base.crtc = NULL; |
| 15534 | } |
| 15535 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15536 | 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] | 15537 | encoder->base.base.id, encoder->base.name, |
| 15538 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15539 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15540 | } |
| 15541 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15542 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15543 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15544 | if (connector->get_hw_state(connector)) { |
| 15545 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15546 | |
| 15547 | encoder = connector->encoder; |
| 15548 | connector->base.encoder = &encoder->base; |
| 15549 | |
| 15550 | if (encoder->base.crtc && |
| 15551 | encoder->base.crtc->state->active) { |
| 15552 | /* |
| 15553 | * This has to be done during hardware readout |
| 15554 | * because anything calling .crtc_disable may |
| 15555 | * rely on the connector_mask being accurate. |
| 15556 | */ |
| 15557 | encoder->base.crtc->state->connector_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15558 | drm_connector_mask(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15559 | encoder->base.crtc->state->encoder_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15560 | drm_encoder_mask(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15561 | } |
| 15562 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15563 | } else { |
| 15564 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15565 | connector->base.encoder = NULL; |
| 15566 | } |
| 15567 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15568 | connector->base.base.id, connector->base.name, |
| 15569 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15570 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15571 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15572 | |
| 15573 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15574 | struct intel_crtc_state *crtc_state = |
| 15575 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15576 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15577 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15578 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15579 | if (crtc_state->base.active) { |
| 15580 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15581 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15582 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15583 | 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] | 15584 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15585 | |
| 15586 | /* |
| 15587 | * The initial mode needs to be set in order to keep |
| 15588 | * the atomic core happy. It wants a valid mode if the |
| 15589 | * crtc's enabled, so we do the above call. |
| 15590 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 15591 | * But we don't set all the derived state fully, hence |
| 15592 | * set a flag to indicate that a full recalculation is |
| 15593 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15594 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15595 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15596 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 15597 | intel_crtc_compute_pixel_rate(crtc_state); |
| 15598 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15599 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15600 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15601 | if (WARN_ON(min_cdclk < 0)) |
| 15602 | min_cdclk = 0; |
| 15603 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15604 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 15605 | drm_calc_timestamping_constants(&crtc->base, |
| 15606 | &crtc_state->base.adjusted_mode); |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 15607 | update_scanline_offset(crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15608 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15609 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15610 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 15611 | dev_priv->min_voltage_level[crtc->pipe] = |
| 15612 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15613 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15614 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15615 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15616 | } |
| 15617 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15618 | static void |
| 15619 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 15620 | { |
| 15621 | struct intel_encoder *encoder; |
| 15622 | |
| 15623 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 15624 | u64 get_domains; |
| 15625 | enum intel_display_power_domain domain; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15626 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15627 | |
| 15628 | if (!encoder->get_power_domains) |
| 15629 | continue; |
| 15630 | |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15631 | /* |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15632 | * MST-primary and inactive encoders don't have a crtc state |
| 15633 | * and neither of these require any power domain references. |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15634 | */ |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15635 | if (!encoder->base.crtc) |
| 15636 | continue; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15637 | |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15638 | crtc_state = to_intel_crtc_state(encoder->base.crtc->state); |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15639 | get_domains = encoder->get_power_domains(encoder, crtc_state); |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15640 | for_each_power_domain(domain, get_domains) |
| 15641 | intel_display_power_get(dev_priv, domain); |
| 15642 | } |
| 15643 | } |
| 15644 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15645 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 15646 | { |
| 15647 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 15648 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 15649 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 15650 | DARBF_GATING_DIS); |
| 15651 | |
| 15652 | if (IS_HASWELL(dev_priv)) { |
| 15653 | /* |
| 15654 | * WaRsPkgCStateDisplayPMReq:hsw |
| 15655 | * System hang if this isn't done before disabling all planes! |
| 15656 | */ |
| 15657 | I915_WRITE(CHICKEN_PAR1_1, |
| 15658 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 15659 | } |
| 15660 | } |
| 15661 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15662 | /* Scan out the current hw modeset state, |
| 15663 | * and sanitizes it to the current state |
| 15664 | */ |
| 15665 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15666 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 15667 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15668 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15669 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15670 | struct intel_crtc *crtc; |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15671 | struct intel_crtc_state *crtc_state; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15672 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15673 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15674 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15675 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
| 15676 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15677 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15678 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15679 | |
| 15680 | /* 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] | 15681 | get_encoder_power_domains(dev_priv); |
| 15682 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15683 | /* |
| 15684 | * intel_sanitize_plane_mapping() may need to do vblank |
| 15685 | * waits, so we need vblank interrupts restored beforehand. |
| 15686 | */ |
| 15687 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15688 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15689 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15690 | if (crtc->base.state->active) |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15691 | drm_crtc_vblank_on(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15692 | } |
| 15693 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15694 | intel_sanitize_plane_mapping(dev_priv); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15695 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15696 | for_each_intel_encoder(dev, encoder) |
| 15697 | intel_sanitize_encoder(encoder); |
| 15698 | |
| 15699 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15700 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15701 | intel_sanitize_crtc(crtc, ctx); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15702 | intel_dump_pipe_config(crtc, crtc_state, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15703 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15704 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15705 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15706 | intel_modeset_update_connector_atomic_state(dev); |
| 15707 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15708 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15709 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15710 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15711 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15712 | continue; |
| 15713 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 15714 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 15715 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15716 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15717 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15718 | pll->on = false; |
| 15719 | } |
| 15720 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15721 | if (IS_G4X(dev_priv)) { |
| 15722 | g4x_wm_get_hw_state(dev); |
| 15723 | g4x_wm_sanitize(dev_priv); |
| 15724 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 15725 | vlv_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15726 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 15727 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 15728 | skl_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15729 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 15730 | ilk_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15731 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15732 | |
| 15733 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 15734 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15735 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15736 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15737 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15738 | if (WARN_ON(put_domains)) |
| 15739 | modeset_put_power_domains(dev_priv, put_domains); |
| 15740 | } |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15741 | |
| 15742 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15743 | |
| 15744 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15745 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15746 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15747 | void intel_display_resume(struct drm_device *dev) |
| 15748 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15749 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15750 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15751 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15752 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15753 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15754 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15755 | if (state) |
| 15756 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15757 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15758 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15759 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15760 | while (1) { |
| 15761 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 15762 | if (ret != -EDEADLK) |
| 15763 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15764 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15765 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15766 | } |
| 15767 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15768 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 15769 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15770 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 15771 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15772 | drm_modeset_drop_locks(&ctx); |
| 15773 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15774 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15775 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15776 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 15777 | if (state) |
| 15778 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15779 | } |
| 15780 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15781 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 15782 | { |
| 15783 | struct intel_connector *connector; |
| 15784 | struct drm_connector_list_iter conn_iter; |
| 15785 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 15786 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15787 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15788 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 15789 | if (connector->modeset_retry_work.func) |
| 15790 | cancel_work_sync(&connector->modeset_retry_work); |
Ramalingam C | d3dacc7 | 2018-10-29 15:15:46 +0530 | [diff] [blame] | 15791 | if (connector->hdcp.shim) { |
| 15792 | cancel_delayed_work_sync(&connector->hdcp.check_work); |
| 15793 | cancel_work_sync(&connector->hdcp.prop_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 15794 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15795 | } |
| 15796 | drm_connector_list_iter_end(&conn_iter); |
| 15797 | } |
| 15798 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15799 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15800 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15801 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15802 | |
Chris Wilson | 8bcf9f7 | 2018-07-10 10:44:20 +0100 | [diff] [blame] | 15803 | flush_workqueue(dev_priv->modeset_wq); |
| 15804 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15805 | flush_work(&dev_priv->atomic_helper.free_work); |
| 15806 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 15807 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15808 | /* |
| 15809 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15810 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15811 | * experience fancy races otherwise. |
| 15812 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15813 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15814 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15815 | /* |
| 15816 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15817 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15818 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15819 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15820 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 15821 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 15822 | intel_fbdev_fini(dev_priv); |
| 15823 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15824 | intel_unregister_dsm_handler(); |
| 15825 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 15826 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 15827 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15828 | /* flush any delayed tasks or pending work */ |
| 15829 | flush_scheduled_work(); |
| 15830 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15831 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15832 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 15833 | intel_cleanup_overlay(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15834 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 15835 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15836 | |
| 15837 | destroy_workqueue(dev_priv->modeset_wq); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15838 | } |
| 15839 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15840 | /* |
| 15841 | * set vga decode state - true == enable VGA decode |
| 15842 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15843 | 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] | 15844 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15845 | 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] | 15846 | u16 gmch_ctrl; |
| 15847 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15848 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15849 | DRM_ERROR("failed to read control word\n"); |
| 15850 | return -EIO; |
| 15851 | } |
| 15852 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15853 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 15854 | return 0; |
| 15855 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15856 | if (state) |
| 15857 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 15858 | else |
| 15859 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15860 | |
| 15861 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 15862 | DRM_ERROR("failed to write control word\n"); |
| 15863 | return -EIO; |
| 15864 | } |
| 15865 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15866 | return 0; |
| 15867 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15868 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 15869 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 15870 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15871 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15872 | |
| 15873 | u32 power_well_driver; |
| 15874 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15875 | int num_transcoders; |
| 15876 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15877 | struct intel_cursor_error_state { |
| 15878 | u32 control; |
| 15879 | u32 position; |
| 15880 | u32 base; |
| 15881 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15882 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15883 | |
| 15884 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15885 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15886 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15887 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15888 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15889 | |
| 15890 | struct intel_plane_error_state { |
| 15891 | u32 control; |
| 15892 | u32 stride; |
| 15893 | u32 size; |
| 15894 | u32 pos; |
| 15895 | u32 addr; |
| 15896 | u32 surface; |
| 15897 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15898 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15899 | |
| 15900 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15901 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15902 | enum transcoder cpu_transcoder; |
| 15903 | |
| 15904 | u32 conf; |
| 15905 | |
| 15906 | u32 htotal; |
| 15907 | u32 hblank; |
| 15908 | u32 hsync; |
| 15909 | u32 vtotal; |
| 15910 | u32 vblank; |
| 15911 | u32 vsync; |
| 15912 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15913 | }; |
| 15914 | |
| 15915 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15916 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15917 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15918 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15919 | int transcoders[] = { |
| 15920 | TRANSCODER_A, |
| 15921 | TRANSCODER_B, |
| 15922 | TRANSCODER_C, |
| 15923 | TRANSCODER_EDP, |
| 15924 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15925 | int i; |
| 15926 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15927 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15928 | return NULL; |
| 15929 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15930 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15931 | if (error == NULL) |
| 15932 | return NULL; |
| 15933 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15934 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 15935 | error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15936 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15937 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15938 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15939 | __intel_display_power_is_enabled(dev_priv, |
| 15940 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15941 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15942 | continue; |
| 15943 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 15944 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 15945 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 15946 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15947 | |
| 15948 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 15949 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15950 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 15951 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 15952 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 15953 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15954 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 15955 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15956 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15957 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 15958 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 15959 | } |
| 15960 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15961 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15962 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15963 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15964 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15965 | } |
| 15966 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15967 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 15968 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 15969 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15970 | error->num_transcoders++; /* Account for eDP. */ |
| 15971 | |
| 15972 | for (i = 0; i < error->num_transcoders; i++) { |
| 15973 | enum transcoder cpu_transcoder = transcoders[i]; |
| 15974 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15975 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 15976 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 15977 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15978 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 15979 | continue; |
| 15980 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15981 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 15982 | |
| 15983 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 15984 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 15985 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 15986 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 15987 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 15988 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 15989 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15990 | } |
| 15991 | |
| 15992 | return error; |
| 15993 | } |
| 15994 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15995 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 15996 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15997 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 15998 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15999 | struct intel_display_error_state *error) |
| 16000 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 16001 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16002 | int i; |
| 16003 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16004 | if (!error) |
| 16005 | return; |
| 16006 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16007 | 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] | 16008 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16009 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16010 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16011 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16012 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16013 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16014 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16015 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16016 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16017 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16018 | err_printf(m, "Plane [%d]:\n", i); |
| 16019 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16020 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16021 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16022 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16023 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16024 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 16025 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16026 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16027 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16028 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16029 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16030 | } |
| 16031 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16032 | err_printf(m, "Cursor [%d]:\n", i); |
| 16033 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16034 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16035 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16036 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16037 | |
| 16038 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16039 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16040 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16041 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16042 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16043 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16044 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16045 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16046 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16047 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16048 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16049 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16050 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16051 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16052 | |
| 16053 | #endif |