Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Daniel Vetter | 618563e | 2012-04-01 13:38:50 +0200 | [diff] [blame] | 27 | #include <linux/dmi.h> |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 30 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 34 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
Chris Wilson | 5d723d7 | 2016-08-04 16:32:35 +0100 | [diff] [blame] | 37 | #include "intel_frontbuffer.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 38 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 39 | #include "i915_drv.h" |
Chris Wilson | 57822dc | 2017-02-22 11:40:48 +0000 | [diff] [blame] | 40 | #include "i915_gem_clflush.h" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 41 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 42 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 43 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 44 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 45 | #include <drm/drm_dp_helper.h> |
| 46 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 47 | #include <drm/drm_plane_helper.h> |
| 48 | #include <drm/drm_rect.h> |
Daniel Vetter | 72fdb40c | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 49 | #include <drm/drm_atomic_uapi.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 50 | #include <linux/dma_remapping.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 51 | #include <linux/reservation.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 52 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 53 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 54 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 55 | DRM_FORMAT_C8, |
| 56 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 57 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 58 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 62 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 63 | DRM_FORMAT_C8, |
| 64 | DRM_FORMAT_RGB565, |
| 65 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 66 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 67 | DRM_FORMAT_XRGB2101010, |
| 68 | DRM_FORMAT_XBGR2101010, |
| 69 | }; |
| 70 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 71 | static const uint64_t i9xx_format_modifiers[] = { |
| 72 | I915_FORMAT_MOD_X_TILED, |
| 73 | DRM_FORMAT_MOD_LINEAR, |
| 74 | DRM_FORMAT_MOD_INVALID |
| 75 | }; |
| 76 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 77 | /* Cursor formats */ |
| 78 | static const uint32_t intel_cursor_formats[] = { |
| 79 | DRM_FORMAT_ARGB8888, |
| 80 | }; |
| 81 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 82 | static const uint64_t cursor_format_modifiers[] = { |
| 83 | DRM_FORMAT_MOD_LINEAR, |
| 84 | DRM_FORMAT_MOD_INVALID |
| 85 | }; |
| 86 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 87 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 88 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 89 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 90 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 91 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 92 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
| 93 | struct drm_i915_gem_object *obj, |
| 94 | struct drm_mode_fb_cmd2 *mode_cmd); |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 95 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state); |
| 96 | static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 97 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 98 | struct intel_link_m_n *m_n, |
| 99 | struct intel_link_m_n *m2_n2); |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 100 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 101 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 102 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 103 | 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] | 104 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 105 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 106 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 107 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 108 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 109 | 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] | 110 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 111 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 112 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state); |
| 113 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state); |
| 114 | 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] | 115 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 116 | struct drm_modeset_acquire_ctx *ctx); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 117 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 118 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 119 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 120 | struct { |
| 121 | int min, max; |
| 122 | } dot, vco, n, m, m1, m2, p, p1; |
| 123 | |
| 124 | struct { |
| 125 | int dot_limit; |
| 126 | int p2_slow, p2_fast; |
| 127 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 128 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 129 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 130 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 131 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 132 | { |
| 133 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 134 | |
| 135 | /* Obtain SKU information */ |
| 136 | mutex_lock(&dev_priv->sb_lock); |
| 137 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 138 | CCK_FUSE_HPLL_FREQ_MASK; |
| 139 | mutex_unlock(&dev_priv->sb_lock); |
| 140 | |
| 141 | return vco_freq[hpll_freq] * 1000; |
| 142 | } |
| 143 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 144 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 145 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 146 | { |
| 147 | u32 val; |
| 148 | int divider; |
| 149 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 150 | mutex_lock(&dev_priv->sb_lock); |
| 151 | val = vlv_cck_read(dev_priv, reg); |
| 152 | mutex_unlock(&dev_priv->sb_lock); |
| 153 | |
| 154 | divider = val & CCK_FREQUENCY_VALUES; |
| 155 | |
| 156 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 157 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 158 | "%s change in progress\n", name); |
| 159 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 160 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 161 | } |
| 162 | |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 163 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 164 | const char *name, u32 reg) |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 165 | { |
| 166 | if (dev_priv->hpll_freq == 0) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 167 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 168 | |
| 169 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 170 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 171 | } |
| 172 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 173 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 174 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 175 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 176 | return; |
| 177 | |
| 178 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 179 | CCK_CZ_CLOCK_CONTROL); |
| 180 | |
| 181 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 182 | } |
| 183 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 184 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 185 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 186 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 187 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 188 | if (HAS_DDI(dev_priv)) |
| 189 | return pipe_config->port_clock; /* SPLL */ |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 190 | else |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 191 | return dev_priv->fdi_pll_freq; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 194 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 195 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 196 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 197 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 198 | .m = { .min = 96, .max = 140 }, |
| 199 | .m1 = { .min = 18, .max = 26 }, |
| 200 | .m2 = { .min = 6, .max = 16 }, |
| 201 | .p = { .min = 4, .max = 128 }, |
| 202 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 203 | .p2 = { .dot_limit = 165000, |
| 204 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 207 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 208 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 209 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 210 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 211 | .m = { .min = 96, .max = 140 }, |
| 212 | .m1 = { .min = 18, .max = 26 }, |
| 213 | .m2 = { .min = 6, .max = 16 }, |
| 214 | .p = { .min = 4, .max = 128 }, |
| 215 | .p1 = { .min = 2, .max = 33 }, |
| 216 | .p2 = { .dot_limit = 165000, |
| 217 | .p2_slow = 4, .p2_fast = 4 }, |
| 218 | }; |
| 219 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 220 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 221 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 222 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 223 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 224 | .m = { .min = 96, .max = 140 }, |
| 225 | .m1 = { .min = 18, .max = 26 }, |
| 226 | .m2 = { .min = 6, .max = 16 }, |
| 227 | .p = { .min = 4, .max = 128 }, |
| 228 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 229 | .p2 = { .dot_limit = 165000, |
| 230 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 231 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 232 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 233 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 234 | .dot = { .min = 20000, .max = 400000 }, |
| 235 | .vco = { .min = 1400000, .max = 2800000 }, |
| 236 | .n = { .min = 1, .max = 6 }, |
| 237 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 238 | .m1 = { .min = 8, .max = 18 }, |
| 239 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 240 | .p = { .min = 5, .max = 80 }, |
| 241 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 242 | .p2 = { .dot_limit = 200000, |
| 243 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 246 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 247 | .dot = { .min = 20000, .max = 400000 }, |
| 248 | .vco = { .min = 1400000, .max = 2800000 }, |
| 249 | .n = { .min = 1, .max = 6 }, |
| 250 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 251 | .m1 = { .min = 8, .max = 18 }, |
| 252 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 253 | .p = { .min = 7, .max = 98 }, |
| 254 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 255 | .p2 = { .dot_limit = 112000, |
| 256 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 259 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 260 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 261 | .dot = { .min = 25000, .max = 270000 }, |
| 262 | .vco = { .min = 1750000, .max = 3500000}, |
| 263 | .n = { .min = 1, .max = 4 }, |
| 264 | .m = { .min = 104, .max = 138 }, |
| 265 | .m1 = { .min = 17, .max = 23 }, |
| 266 | .m2 = { .min = 5, .max = 11 }, |
| 267 | .p = { .min = 10, .max = 30 }, |
| 268 | .p1 = { .min = 1, .max = 3}, |
| 269 | .p2 = { .dot_limit = 270000, |
| 270 | .p2_slow = 10, |
| 271 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 272 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 273 | }; |
| 274 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 275 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 276 | .dot = { .min = 22000, .max = 400000 }, |
| 277 | .vco = { .min = 1750000, .max = 3500000}, |
| 278 | .n = { .min = 1, .max = 4 }, |
| 279 | .m = { .min = 104, .max = 138 }, |
| 280 | .m1 = { .min = 16, .max = 23 }, |
| 281 | .m2 = { .min = 5, .max = 11 }, |
| 282 | .p = { .min = 5, .max = 80 }, |
| 283 | .p1 = { .min = 1, .max = 8}, |
| 284 | .p2 = { .dot_limit = 165000, |
| 285 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 288 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 289 | .dot = { .min = 20000, .max = 115000 }, |
| 290 | .vco = { .min = 1750000, .max = 3500000 }, |
| 291 | .n = { .min = 1, .max = 3 }, |
| 292 | .m = { .min = 104, .max = 138 }, |
| 293 | .m1 = { .min = 17, .max = 23 }, |
| 294 | .m2 = { .min = 5, .max = 11 }, |
| 295 | .p = { .min = 28, .max = 112 }, |
| 296 | .p1 = { .min = 2, .max = 8 }, |
| 297 | .p2 = { .dot_limit = 0, |
| 298 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 299 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 302 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 303 | .dot = { .min = 80000, .max = 224000 }, |
| 304 | .vco = { .min = 1750000, .max = 3500000 }, |
| 305 | .n = { .min = 1, .max = 3 }, |
| 306 | .m = { .min = 104, .max = 138 }, |
| 307 | .m1 = { .min = 17, .max = 23 }, |
| 308 | .m2 = { .min = 5, .max = 11 }, |
| 309 | .p = { .min = 14, .max = 42 }, |
| 310 | .p1 = { .min = 2, .max = 6 }, |
| 311 | .p2 = { .dot_limit = 0, |
| 312 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 313 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 316 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 317 | .dot = { .min = 20000, .max = 400000}, |
| 318 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 319 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 320 | .n = { .min = 3, .max = 6 }, |
| 321 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 322 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 323 | .m1 = { .min = 0, .max = 0 }, |
| 324 | .m2 = { .min = 0, .max = 254 }, |
| 325 | .p = { .min = 5, .max = 80 }, |
| 326 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 327 | .p2 = { .dot_limit = 200000, |
| 328 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 329 | }; |
| 330 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 331 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 332 | .dot = { .min = 20000, .max = 400000 }, |
| 333 | .vco = { .min = 1700000, .max = 3500000 }, |
| 334 | .n = { .min = 3, .max = 6 }, |
| 335 | .m = { .min = 2, .max = 256 }, |
| 336 | .m1 = { .min = 0, .max = 0 }, |
| 337 | .m2 = { .min = 0, .max = 254 }, |
| 338 | .p = { .min = 7, .max = 112 }, |
| 339 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 340 | .p2 = { .dot_limit = 112000, |
| 341 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 342 | }; |
| 343 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 344 | /* Ironlake / Sandybridge |
| 345 | * |
| 346 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 347 | * the range value for them is (actual_value - 2). |
| 348 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 349 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 350 | .dot = { .min = 25000, .max = 350000 }, |
| 351 | .vco = { .min = 1760000, .max = 3510000 }, |
| 352 | .n = { .min = 1, .max = 5 }, |
| 353 | .m = { .min = 79, .max = 127 }, |
| 354 | .m1 = { .min = 12, .max = 22 }, |
| 355 | .m2 = { .min = 5, .max = 9 }, |
| 356 | .p = { .min = 5, .max = 80 }, |
| 357 | .p1 = { .min = 1, .max = 8 }, |
| 358 | .p2 = { .dot_limit = 225000, |
| 359 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 362 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 363 | .dot = { .min = 25000, .max = 350000 }, |
| 364 | .vco = { .min = 1760000, .max = 3510000 }, |
| 365 | .n = { .min = 1, .max = 3 }, |
| 366 | .m = { .min = 79, .max = 118 }, |
| 367 | .m1 = { .min = 12, .max = 22 }, |
| 368 | .m2 = { .min = 5, .max = 9 }, |
| 369 | .p = { .min = 28, .max = 112 }, |
| 370 | .p1 = { .min = 2, .max = 8 }, |
| 371 | .p2 = { .dot_limit = 225000, |
| 372 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 373 | }; |
| 374 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 375 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 376 | .dot = { .min = 25000, .max = 350000 }, |
| 377 | .vco = { .min = 1760000, .max = 3510000 }, |
| 378 | .n = { .min = 1, .max = 3 }, |
| 379 | .m = { .min = 79, .max = 127 }, |
| 380 | .m1 = { .min = 12, .max = 22 }, |
| 381 | .m2 = { .min = 5, .max = 9 }, |
| 382 | .p = { .min = 14, .max = 56 }, |
| 383 | .p1 = { .min = 2, .max = 8 }, |
| 384 | .p2 = { .dot_limit = 225000, |
| 385 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 386 | }; |
| 387 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 388 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 389 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 390 | .dot = { .min = 25000, .max = 350000 }, |
| 391 | .vco = { .min = 1760000, .max = 3510000 }, |
| 392 | .n = { .min = 1, .max = 2 }, |
| 393 | .m = { .min = 79, .max = 126 }, |
| 394 | .m1 = { .min = 12, .max = 22 }, |
| 395 | .m2 = { .min = 5, .max = 9 }, |
| 396 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 397 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 398 | .p2 = { .dot_limit = 225000, |
| 399 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 400 | }; |
| 401 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 402 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 403 | .dot = { .min = 25000, .max = 350000 }, |
| 404 | .vco = { .min = 1760000, .max = 3510000 }, |
| 405 | .n = { .min = 1, .max = 3 }, |
| 406 | .m = { .min = 79, .max = 126 }, |
| 407 | .m1 = { .min = 12, .max = 22 }, |
| 408 | .m2 = { .min = 5, .max = 9 }, |
| 409 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 410 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 411 | .p2 = { .dot_limit = 225000, |
| 412 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 413 | }; |
| 414 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 415 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 416 | /* |
| 417 | * These are the data rate limits (measured in fast clocks) |
| 418 | * since those are the strictest limits we have. The fast |
| 419 | * clock and actual rate limits are more relaxed, so checking |
| 420 | * them would make no difference. |
| 421 | */ |
| 422 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 423 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 424 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 425 | .m1 = { .min = 2, .max = 3 }, |
| 426 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 427 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 428 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 429 | }; |
| 430 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 431 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 432 | /* |
| 433 | * These are the data rate limits (measured in fast clocks) |
| 434 | * since those are the strictest limits we have. The fast |
| 435 | * clock and actual rate limits are more relaxed, so checking |
| 436 | * them would make no difference. |
| 437 | */ |
| 438 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 439 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 440 | .n = { .min = 1, .max = 1 }, |
| 441 | .m1 = { .min = 2, .max = 2 }, |
| 442 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 443 | .p1 = { .min = 2, .max = 4 }, |
| 444 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 445 | }; |
| 446 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 447 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 448 | /* FIXME: find real dot limits */ |
| 449 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 450 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 451 | .n = { .min = 1, .max = 1 }, |
| 452 | .m1 = { .min = 2, .max = 2 }, |
| 453 | /* FIXME: find real m2 limits */ |
| 454 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 455 | .p1 = { .min = 2, .max = 4 }, |
| 456 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 457 | }; |
| 458 | |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 459 | static void |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 460 | skl_wa_528(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 461 | { |
| 462 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
| 463 | return; |
| 464 | |
| 465 | if (enable) |
| 466 | I915_WRITE(CHICKEN_PIPESL_1(pipe), HSW_FBCQ_DIS); |
| 467 | else |
| 468 | I915_WRITE(CHICKEN_PIPESL_1(pipe), 0); |
| 469 | } |
| 470 | |
| 471 | static void |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 472 | skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 473 | { |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 474 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 475 | return; |
| 476 | |
| 477 | if (enable) |
| 478 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 479 | DUPS1_GATING_DIS | DUPS2_GATING_DIS); |
| 480 | else |
| 481 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 482 | I915_READ(CLKGATE_DIS_PSL(pipe)) & |
| 483 | ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); |
| 484 | } |
| 485 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 486 | static bool |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 487 | needs_modeset(const struct drm_crtc_state *state) |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 488 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 489 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 492 | /* |
| 493 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 494 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 495 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 496 | * The helpers' return value is the rate of the clock that is fed to the |
| 497 | * display engine's pipe which can be the above fast dot clock rate or a |
| 498 | * divided-down version of it. |
| 499 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 500 | /* 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] | 501 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 502 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 503 | clock->m = clock->m2 + 2; |
| 504 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 505 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 506 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 507 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 508 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 509 | |
| 510 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 511 | } |
| 512 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 513 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 514 | { |
| 515 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 516 | } |
| 517 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 518 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 519 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 520 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 521 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 522 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 523 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 524 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 525 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 526 | |
| 527 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 530 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 531 | { |
| 532 | clock->m = clock->m1 * clock->m2; |
| 533 | clock->p = clock->p1 * clock->p2; |
| 534 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 535 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 536 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 537 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 538 | |
| 539 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 540 | } |
| 541 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 542 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 543 | { |
| 544 | clock->m = clock->m1 * clock->m2; |
| 545 | clock->p = clock->p1 * clock->p2; |
| 546 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 547 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 548 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 549 | clock->n << 22); |
| 550 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 551 | |
| 552 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 553 | } |
| 554 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 555 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 556 | |
| 557 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 558 | * Returns whether the given set of divisors are valid for a given refclk with |
| 559 | * the given connectors. |
| 560 | */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 561 | 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] | 562 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 563 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 564 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 565 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 566 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 567 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 568 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 569 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 570 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 571 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 572 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 573 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 574 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 575 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 576 | if (clock->m1 <= clock->m2) |
| 577 | INTELPllInvalid("m1 <= m2\n"); |
| 578 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 579 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 580 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 581 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 582 | INTELPllInvalid("p out of range\n"); |
| 583 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 584 | INTELPllInvalid("m out of range\n"); |
| 585 | } |
| 586 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 587 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 588 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 590 | * connector, etc., rather than just a single range. |
| 591 | */ |
| 592 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 593 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 594 | |
| 595 | return true; |
| 596 | } |
| 597 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 598 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 599 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 600 | const struct intel_crtc_state *crtc_state, |
| 601 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 602 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 603 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 604 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 605 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 606 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 607 | * For LVDS just rely on its current settings for dual-channel. |
| 608 | * We haven't figured out how to reliably set up different |
| 609 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 611 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 612 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 613 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 614 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 615 | } else { |
| 616 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 617 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 618 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 619 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 620 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 621 | } |
| 622 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 623 | /* |
| 624 | * Returns a set of divisors for the desired target clock with the given |
| 625 | * refclk, or FALSE. The returned values represent the clock equation: |
| 626 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 627 | * |
| 628 | * Target and reference clocks are specified in kHz. |
| 629 | * |
| 630 | * If match_clock is provided, then best_clock P divider must match the P |
| 631 | * divider from @match_clock used for LVDS downclocking. |
| 632 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 633 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 634 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 635 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 636 | int target, int refclk, struct dpll *match_clock, |
| 637 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 638 | { |
| 639 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 640 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 641 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 642 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 643 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 644 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 645 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 646 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 647 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 648 | clock.m1++) { |
| 649 | for (clock.m2 = limit->m2.min; |
| 650 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 651 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 652 | break; |
| 653 | for (clock.n = limit->n.min; |
| 654 | clock.n <= limit->n.max; clock.n++) { |
| 655 | for (clock.p1 = limit->p1.min; |
| 656 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 657 | int this_err; |
| 658 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 659 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 660 | if (!intel_PLL_is_valid(to_i915(dev), |
| 661 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 662 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 663 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 664 | if (match_clock && |
| 665 | clock.p != match_clock->p) |
| 666 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 667 | |
| 668 | this_err = abs(clock.dot - target); |
| 669 | if (this_err < err) { |
| 670 | *best_clock = clock; |
| 671 | err = this_err; |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | return (err != target); |
| 679 | } |
| 680 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 681 | /* |
| 682 | * Returns a set of divisors for the desired target clock with the given |
| 683 | * refclk, or FALSE. The returned values represent the clock equation: |
| 684 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 685 | * |
| 686 | * Target and reference clocks are specified in kHz. |
| 687 | * |
| 688 | * If match_clock is provided, then best_clock P divider must match the P |
| 689 | * divider from @match_clock used for LVDS downclocking. |
| 690 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 691 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 692 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 693 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 694 | int target, int refclk, struct dpll *match_clock, |
| 695 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 696 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 697 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 698 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 699 | int err = target; |
| 700 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 701 | memset(best_clock, 0, sizeof(*best_clock)); |
| 702 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 703 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 704 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 705 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 706 | clock.m1++) { |
| 707 | for (clock.m2 = limit->m2.min; |
| 708 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 709 | for (clock.n = limit->n.min; |
| 710 | clock.n <= limit->n.max; clock.n++) { |
| 711 | for (clock.p1 = limit->p1.min; |
| 712 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 713 | int this_err; |
| 714 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 715 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 716 | if (!intel_PLL_is_valid(to_i915(dev), |
| 717 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 718 | &clock)) |
| 719 | continue; |
| 720 | if (match_clock && |
| 721 | clock.p != match_clock->p) |
| 722 | continue; |
| 723 | |
| 724 | this_err = abs(clock.dot - target); |
| 725 | if (this_err < err) { |
| 726 | *best_clock = clock; |
| 727 | err = this_err; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | return (err != target); |
| 735 | } |
| 736 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 737 | /* |
| 738 | * Returns a set of divisors for the desired target clock with the given |
| 739 | * refclk, or FALSE. The returned values represent the clock equation: |
| 740 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 741 | * |
| 742 | * Target and reference clocks are specified in kHz. |
| 743 | * |
| 744 | * If match_clock is provided, then best_clock P divider must match the P |
| 745 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 746 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 747 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 748 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 749 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 750 | int target, int refclk, struct dpll *match_clock, |
| 751 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 752 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 753 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 754 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 755 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 756 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 757 | /* approximately equals target * 0.00585 */ |
| 758 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 759 | |
| 760 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 761 | |
| 762 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 763 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 764 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 765 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 766 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 767 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 768 | for (clock.m1 = limit->m1.max; |
| 769 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 770 | for (clock.m2 = limit->m2.max; |
| 771 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 772 | for (clock.p1 = limit->p1.max; |
| 773 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 774 | int this_err; |
| 775 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 776 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 777 | if (!intel_PLL_is_valid(to_i915(dev), |
| 778 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 779 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 780 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 781 | |
| 782 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 783 | if (this_err < err_most) { |
| 784 | *best_clock = clock; |
| 785 | err_most = this_err; |
| 786 | max_n = clock.n; |
| 787 | found = true; |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 793 | return found; |
| 794 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 795 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 796 | /* |
| 797 | * Check if the calculated PLL configuration is more optimal compared to the |
| 798 | * best configuration and error found so far. Return the calculated error. |
| 799 | */ |
| 800 | 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] | 801 | const struct dpll *calculated_clock, |
| 802 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 803 | unsigned int best_error_ppm, |
| 804 | unsigned int *error_ppm) |
| 805 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 806 | /* |
| 807 | * For CHV ignore the error and consider only the P value. |
| 808 | * Prefer a bigger P value based on HW requirements. |
| 809 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 810 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 811 | *error_ppm = 0; |
| 812 | |
| 813 | return calculated_clock->p > best_clock->p; |
| 814 | } |
| 815 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 816 | if (WARN_ON_ONCE(!target_freq)) |
| 817 | return false; |
| 818 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 819 | *error_ppm = div_u64(1000000ULL * |
| 820 | abs(target_freq - calculated_clock->dot), |
| 821 | target_freq); |
| 822 | /* |
| 823 | * Prefer a better P value over a better (smaller) error if the error |
| 824 | * is small. Ensure this preference for future configurations too by |
| 825 | * setting the error to 0. |
| 826 | */ |
| 827 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 828 | *error_ppm = 0; |
| 829 | |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | return *error_ppm + 10 < best_error_ppm; |
| 834 | } |
| 835 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 836 | /* |
| 837 | * Returns a set of divisors for the desired target clock with the given |
| 838 | * refclk, or FALSE. The returned values represent the clock equation: |
| 839 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 840 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 841 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 842 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 843 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 844 | int target, int refclk, struct dpll *match_clock, |
| 845 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 846 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 847 | 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] | 848 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 849 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 850 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 851 | /* min update 19.2 MHz */ |
| 852 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 853 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 854 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 855 | target *= 5; /* fast clock */ |
| 856 | |
| 857 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 858 | |
| 859 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 860 | 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] | 861 | 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] | 862 | 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] | 863 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 864 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 865 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 866 | 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] | 867 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 868 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 869 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 870 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 871 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 872 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 873 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 874 | if (!intel_PLL_is_valid(to_i915(dev), |
| 875 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 876 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 877 | continue; |
| 878 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 879 | if (!vlv_PLL_is_optimal(dev, target, |
| 880 | &clock, |
| 881 | best_clock, |
| 882 | bestppm, &ppm)) |
| 883 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 884 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 885 | *best_clock = clock; |
| 886 | bestppm = ppm; |
| 887 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | } |
| 891 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 892 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 893 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 894 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 895 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 896 | /* |
| 897 | * Returns a set of divisors for the desired target clock with the given |
| 898 | * refclk, or FALSE. The returned values represent the clock equation: |
| 899 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 900 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 901 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 902 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 903 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 904 | int target, int refclk, struct dpll *match_clock, |
| 905 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 906 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 907 | 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] | 908 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 909 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 910 | struct dpll clock; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 911 | uint64_t m2; |
| 912 | int found = false; |
| 913 | |
| 914 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 915 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 916 | |
| 917 | /* |
| 918 | * Based on hardware doc, the n always set to 1, and m1 always |
| 919 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 920 | * revisit this because n may not 1 anymore. |
| 921 | */ |
| 922 | clock.n = 1, clock.m1 = 2; |
| 923 | target *= 5; /* fast clock */ |
| 924 | |
| 925 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 926 | for (clock.p2 = limit->p2.p2_fast; |
| 927 | clock.p2 >= limit->p2.p2_slow; |
| 928 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 929 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 930 | |
| 931 | clock.p = clock.p1 * clock.p2; |
| 932 | |
| 933 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 934 | clock.n) << 22, refclk * clock.m1); |
| 935 | |
| 936 | if (m2 > INT_MAX/clock.m1) |
| 937 | continue; |
| 938 | |
| 939 | clock.m2 = m2; |
| 940 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 941 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 942 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 943 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 944 | continue; |
| 945 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 946 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 947 | best_error_ppm, &error_ppm)) |
| 948 | continue; |
| 949 | |
| 950 | *best_clock = clock; |
| 951 | best_error_ppm = error_ppm; |
| 952 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | return found; |
| 957 | } |
| 958 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 959 | 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] | 960 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 961 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 962 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 963 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 964 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 965 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 966 | target_clock, refclk, NULL, best_clock); |
| 967 | } |
| 968 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 969 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 970 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 971 | /* Be paranoid as we can arrive here with only partial |
| 972 | * state retrieved from the hardware during setup. |
| 973 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 974 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 975 | * as Haswell has gained clock readout/fastboot support. |
| 976 | * |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 977 | * 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] | 978 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 979 | * |
| 980 | * FIXME: The intel_crtc->active here should be switched to |
| 981 | * crtc->state->active once we have proper CRTC states wired up |
| 982 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 983 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 984 | return crtc->active && crtc->base.primary->state->fb && |
| 985 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 986 | } |
| 987 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 988 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 989 | enum pipe pipe) |
| 990 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 991 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 992 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 993 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 994 | } |
| 995 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 996 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
| 997 | enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 998 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 999 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1000 | u32 line1, line2; |
| 1001 | u32 line_mask; |
| 1002 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1003 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1004 | line_mask = DSL_LINEMASK_GEN2; |
| 1005 | else |
| 1006 | line_mask = DSL_LINEMASK_GEN3; |
| 1007 | |
| 1008 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1009 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1010 | line2 = I915_READ(reg) & line_mask; |
| 1011 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1012 | return line1 != line2; |
| 1013 | } |
| 1014 | |
| 1015 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) |
| 1016 | { |
| 1017 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1018 | enum pipe pipe = crtc->pipe; |
| 1019 | |
| 1020 | /* Wait for the display line to settle/start moving */ |
| 1021 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) |
| 1022 | DRM_ERROR("pipe %c scanline %s wait timed out\n", |
| 1023 | pipe_name(pipe), onoff(state)); |
| 1024 | } |
| 1025 | |
| 1026 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) |
| 1027 | { |
| 1028 | wait_for_pipe_scanline_moving(crtc, false); |
| 1029 | } |
| 1030 | |
| 1031 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) |
| 1032 | { |
| 1033 | wait_for_pipe_scanline_moving(crtc, true); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1034 | } |
| 1035 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1036 | static void |
| 1037 | 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] | 1038 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1039 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1040 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1041 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1042 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1043 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1044 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1045 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1046 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1047 | if (intel_wait_for_register(dev_priv, |
| 1048 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1049 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1050 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1051 | } else { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1052 | intel_wait_for_pipe_scanline_stopped(crtc); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1053 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1056 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1057 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1058 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1059 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1060 | u32 val; |
| 1061 | bool cur_state; |
| 1062 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1063 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1064 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1065 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1066 | "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)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1068 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1069 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1070 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1071 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1072 | { |
| 1073 | u32 val; |
| 1074 | bool cur_state; |
| 1075 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1076 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1077 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1078 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1079 | |
| 1080 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1081 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1082 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1083 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1084 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1085 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1086 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1087 | enum pipe pipe, bool state) |
| 1088 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1089 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1090 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1091 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1092 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1093 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1094 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1095 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1096 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1097 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1098 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1099 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1100 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1101 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1102 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1103 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1104 | } |
| 1105 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1106 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1107 | |
| 1108 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1109 | enum pipe pipe, bool state) |
| 1110 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1111 | u32 val; |
| 1112 | bool cur_state; |
| 1113 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1114 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1115 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1116 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1117 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1118 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1119 | } |
| 1120 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1121 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1122 | |
| 1123 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1124 | enum pipe pipe) |
| 1125 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1126 | u32 val; |
| 1127 | |
| 1128 | /* ILK FDI PLL is always enabled */ |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 1129 | if (IS_GEN5(dev_priv)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1130 | return; |
| 1131 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1132 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1133 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1134 | return; |
| 1135 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1136 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1137 | 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] | 1138 | } |
| 1139 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1140 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1141 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1142 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1143 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1144 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1145 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1146 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1147 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1148 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1149 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1150 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1153 | 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] | 1154 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1155 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1156 | u32 val; |
Ville Syrjälä | 10ed55e | 2018-05-23 17:57:18 +0300 | [diff] [blame] | 1157 | enum pipe panel_pipe = INVALID_PIPE; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1158 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1159 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1160 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1161 | return; |
| 1162 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1163 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1164 | u32 port_sel; |
| 1165 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1166 | pp_reg = PP_CONTROL(0); |
| 1167 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1168 | |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1169 | switch (port_sel) { |
| 1170 | case PANEL_PORT_SELECT_LVDS: |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1171 | intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe); |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1172 | break; |
| 1173 | case PANEL_PORT_SELECT_DPA: |
| 1174 | intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe); |
| 1175 | break; |
| 1176 | case PANEL_PORT_SELECT_DPC: |
| 1177 | intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe); |
| 1178 | break; |
| 1179 | case PANEL_PORT_SELECT_DPD: |
| 1180 | intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe); |
| 1181 | break; |
| 1182 | default: |
| 1183 | MISSING_CASE(port_sel); |
| 1184 | break; |
| 1185 | } |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1186 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1187 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1188 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1189 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1190 | } else { |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1191 | u32 port_sel; |
| 1192 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1193 | pp_reg = PP_CONTROL(0); |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1194 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
| 1195 | |
| 1196 | WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS); |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1197 | intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | val = I915_READ(pp_reg); |
| 1201 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1202 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1203 | locked = false; |
| 1204 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1205 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1206 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1207 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1210 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1211 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1212 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1213 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1214 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1215 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1216 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1217 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1218 | /* we keep both pipes enabled on 830 */ |
| 1219 | if (IS_I830(dev_priv)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1220 | state = true; |
| 1221 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1222 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1223 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1224 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1225 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1226 | |
| 1227 | intel_display_power_put(dev_priv, power_domain); |
| 1228 | } else { |
| 1229 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1230 | } |
| 1231 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1232 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1233 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1234 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1237 | static void assert_plane(struct intel_plane *plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1238 | { |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 1239 | enum pipe pipe; |
| 1240 | bool cur_state; |
| 1241 | |
| 1242 | cur_state = plane->get_hw_state(plane, &pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1243 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1244 | I915_STATE_WARN(cur_state != state, |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1245 | "%s assertion failure (expected %s, current %s)\n", |
| 1246 | plane->base.name, onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1249 | #define assert_plane_enabled(p) assert_plane(p, true) |
| 1250 | #define assert_plane_disabled(p) assert_plane(p, false) |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1251 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1252 | static void assert_planes_disabled(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1253 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1254 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1255 | struct intel_plane *plane; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1256 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1257 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
| 1258 | assert_plane_disabled(plane); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1261 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1262 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1263 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1264 | drm_crtc_vblank_put(crtc); |
| 1265 | } |
| 1266 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1267 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1268 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1269 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1270 | u32 val; |
| 1271 | bool enabled; |
| 1272 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1273 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1274 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1275 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1276 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1277 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1280 | 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] | 1281 | enum pipe pipe, enum port port, |
| 1282 | i915_reg_t dp_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1283 | { |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1284 | enum pipe port_pipe; |
| 1285 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1286 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1287 | state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe); |
| 1288 | |
| 1289 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1290 | "PCH DP %c enabled on transcoder %c, should be disabled\n", |
| 1291 | port_name(port), pipe_name(pipe)); |
| 1292 | |
| 1293 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1294 | "IBX PCH DP %c still using transcoder B\n", |
| 1295 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | 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] | 1299 | enum pipe pipe, enum port port, |
| 1300 | i915_reg_t hdmi_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1301 | { |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1302 | enum pipe port_pipe; |
| 1303 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1304 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1305 | state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe); |
| 1306 | |
| 1307 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1308 | "PCH HDMI %c enabled on transcoder %c, should be disabled\n", |
| 1309 | port_name(port), pipe_name(pipe)); |
| 1310 | |
| 1311 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1312 | "IBX PCH HDMI %c still using transcoder B\n", |
| 1313 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1317 | enum pipe pipe) |
| 1318 | { |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1319 | enum pipe port_pipe; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1320 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1321 | assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B); |
| 1322 | assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C); |
| 1323 | assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1324 | |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1325 | I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) && |
| 1326 | port_pipe == pipe, |
| 1327 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
| 1328 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1329 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1330 | I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) && |
| 1331 | port_pipe == pipe, |
| 1332 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
| 1333 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1334 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1335 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB); |
| 1336 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC); |
| 1337 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1340 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1341 | const struct intel_crtc_state *pipe_config) |
| 1342 | { |
| 1343 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1344 | enum pipe pipe = crtc->pipe; |
| 1345 | |
| 1346 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1347 | POSTING_READ(DPLL(pipe)); |
| 1348 | udelay(150); |
| 1349 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1350 | if (intel_wait_for_register(dev_priv, |
| 1351 | DPLL(pipe), |
| 1352 | DPLL_LOCK_VLV, |
| 1353 | DPLL_LOCK_VLV, |
| 1354 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1355 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1356 | } |
| 1357 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1358 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1359 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1360 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1361 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1362 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1363 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1364 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1365 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1366 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1367 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1368 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1369 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1370 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1371 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1372 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1373 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1376 | |
| 1377 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1378 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1379 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1380 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1381 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1382 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1383 | u32 tmp; |
| 1384 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1385 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1386 | |
| 1387 | /* Enable back the 10bit clock to display controller */ |
| 1388 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1389 | tmp |= DPIO_DCLKP_EN; |
| 1390 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1391 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1392 | mutex_unlock(&dev_priv->sb_lock); |
| 1393 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1394 | /* |
| 1395 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1396 | */ |
| 1397 | udelay(1); |
| 1398 | |
| 1399 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1400 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1401 | |
| 1402 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1403 | if (intel_wait_for_register(dev_priv, |
| 1404 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1405 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1406 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1410 | const struct intel_crtc_state *pipe_config) |
| 1411 | { |
| 1412 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1413 | enum pipe pipe = crtc->pipe; |
| 1414 | |
| 1415 | assert_pipe_disabled(dev_priv, pipe); |
| 1416 | |
| 1417 | /* PLL is protected by panel, make sure we can write it */ |
| 1418 | assert_panel_unlocked(dev_priv, pipe); |
| 1419 | |
| 1420 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1421 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1422 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1423 | if (pipe != PIPE_A) { |
| 1424 | /* |
| 1425 | * WaPixelRepeatModeFixForC0:chv |
| 1426 | * |
| 1427 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1428 | * the value from DPLLBMD to either pipe B or C. |
| 1429 | */ |
Ville Syrjälä | dfa311f | 2017-09-13 17:08:54 +0300 | [diff] [blame] | 1430 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1431 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1432 | I915_WRITE(CBR4_VLV, 0); |
| 1433 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1434 | |
| 1435 | /* |
| 1436 | * DPLLB VGA mode also seems to cause problems. |
| 1437 | * We should always have it disabled. |
| 1438 | */ |
| 1439 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1440 | } else { |
| 1441 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1442 | POSTING_READ(DPLL_MD(pipe)); |
| 1443 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1444 | } |
| 1445 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1446 | 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] | 1447 | { |
| 1448 | struct intel_crtc *crtc; |
| 1449 | int count = 0; |
| 1450 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1451 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1452 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1453 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1454 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1455 | |
| 1456 | return count; |
| 1457 | } |
| 1458 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1459 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
| 1460 | const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1461 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1462 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1463 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1464 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1465 | int i; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1466 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1467 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1468 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1469 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1470 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1471 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1472 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1473 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1474 | 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] | 1475 | /* |
| 1476 | * It appears to be important that we don't enable this |
| 1477 | * for the current pipe before otherwise configuring the |
| 1478 | * PLL. No idea how this should be handled if multiple |
| 1479 | * DVO outputs are enabled simultaneosly. |
| 1480 | */ |
| 1481 | dpll |= DPLL_DVO_2X_MODE; |
| 1482 | I915_WRITE(DPLL(!crtc->pipe), |
| 1483 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1484 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1485 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1486 | /* |
| 1487 | * Apparently we need to have VGA mode enabled prior to changing |
| 1488 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1489 | * dividers, even though the register value does change. |
| 1490 | */ |
| 1491 | I915_WRITE(reg, 0); |
| 1492 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1493 | I915_WRITE(reg, dpll); |
| 1494 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1495 | /* Wait for the clocks to stabilize. */ |
| 1496 | POSTING_READ(reg); |
| 1497 | udelay(150); |
| 1498 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1499 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1500 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1501 | crtc_state->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1502 | } else { |
| 1503 | /* The pixel multiplier can only be updated once the |
| 1504 | * DPLL is enabled and the clocks are stable. |
| 1505 | * |
| 1506 | * So write it again. |
| 1507 | */ |
| 1508 | I915_WRITE(reg, dpll); |
| 1509 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1510 | |
| 1511 | /* We do this three times for luck */ |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1512 | for (i = 0; i < 3; i++) { |
| 1513 | I915_WRITE(reg, dpll); |
| 1514 | POSTING_READ(reg); |
| 1515 | udelay(150); /* wait for warmup */ |
| 1516 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1517 | } |
| 1518 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1519 | static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1520 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1521 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1522 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1523 | enum pipe pipe = crtc->pipe; |
| 1524 | |
| 1525 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1526 | if (IS_I830(dev_priv) && |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1527 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1528 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1529 | I915_WRITE(DPLL(PIPE_B), |
| 1530 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1531 | I915_WRITE(DPLL(PIPE_A), |
| 1532 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1533 | } |
| 1534 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1535 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1536 | if (IS_I830(dev_priv)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1537 | return; |
| 1538 | |
| 1539 | /* Make sure the pipe isn't still relying on us */ |
| 1540 | assert_pipe_disabled(dev_priv, pipe); |
| 1541 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1542 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1543 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1546 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1547 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1548 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1549 | |
| 1550 | /* Make sure the pipe isn't still relying on us */ |
| 1551 | assert_pipe_disabled(dev_priv, pipe); |
| 1552 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1553 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1554 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1555 | if (pipe != PIPE_A) |
| 1556 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1557 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1558 | I915_WRITE(DPLL(pipe), val); |
| 1559 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1563 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1564 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1565 | u32 val; |
| 1566 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1567 | /* Make sure the pipe isn't still relying on us */ |
| 1568 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1569 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1570 | val = DPLL_SSC_REF_CLK_CHV | |
| 1571 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1572 | if (pipe != PIPE_A) |
| 1573 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1574 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1575 | I915_WRITE(DPLL(pipe), val); |
| 1576 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1577 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1578 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1579 | |
| 1580 | /* Disable 10bit clock to display controller */ |
| 1581 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1582 | val &= ~DPIO_DCLKP_EN; |
| 1583 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1584 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1585 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1588 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1589 | struct intel_digital_port *dport, |
| 1590 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1591 | { |
| 1592 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1593 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1594 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1595 | switch (dport->base.port) { |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1596 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1597 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1598 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1599 | break; |
| 1600 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1601 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1602 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1603 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1604 | break; |
| 1605 | case PORT_D: |
| 1606 | port_mask = DPLL_PORTD_READY_MASK; |
| 1607 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1608 | break; |
| 1609 | default: |
| 1610 | BUG(); |
| 1611 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1612 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1613 | if (intel_wait_for_register(dev_priv, |
| 1614 | dpll_reg, port_mask, expected_mask, |
| 1615 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1616 | 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] | 1617 | port_name(dport->base.port), |
| 1618 | I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1621 | 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] | 1622 | { |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1623 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1624 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1625 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1626 | i915_reg_t reg; |
| 1627 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1628 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1629 | /* Make sure PCH DPLL is enabled */ |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1630 | assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1631 | |
| 1632 | /* FDI must be feeding us bits for PCH ports */ |
| 1633 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1634 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1635 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1636 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1637 | /* Workaround: Set the timing override bit before enabling the |
| 1638 | * pch transcoder. */ |
| 1639 | reg = TRANS_CHICKEN2(pipe); |
| 1640 | val = I915_READ(reg); |
| 1641 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1642 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1643 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1644 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1645 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1646 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1647 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1648 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1649 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1650 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1651 | * Make the BPC in transcoder be consistent with |
| 1652 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1653 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1654 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1655 | val &= ~PIPECONF_BPC_MASK; |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1656 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1657 | val |= PIPECONF_8BPC; |
| 1658 | else |
| 1659 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1660 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1661 | |
| 1662 | val &= ~TRANS_INTERLACE_MASK; |
| 1663 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1664 | if (HAS_PCH_IBX(dev_priv) && |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1665 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1666 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1667 | else |
| 1668 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1669 | else |
| 1670 | val |= TRANS_PROGRESSIVE; |
| 1671 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1672 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1673 | if (intel_wait_for_register(dev_priv, |
| 1674 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1675 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1676 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1679 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1680 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1681 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1682 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1683 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1684 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1685 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1686 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1687 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1688 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1689 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1690 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1691 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1692 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1693 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1694 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1695 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1696 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1697 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1698 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1699 | else |
| 1700 | val |= TRANS_PROGRESSIVE; |
| 1701 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1702 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1703 | if (intel_wait_for_register(dev_priv, |
| 1704 | LPT_TRANSCONF, |
| 1705 | TRANS_STATE_ENABLE, |
| 1706 | TRANS_STATE_ENABLE, |
| 1707 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1708 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1709 | } |
| 1710 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1711 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1712 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1713 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1714 | i915_reg_t reg; |
| 1715 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1716 | |
| 1717 | /* FDI relies on the transcoder */ |
| 1718 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1719 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1720 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1721 | /* Ports must be off as well */ |
| 1722 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1723 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1724 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1725 | val = I915_READ(reg); |
| 1726 | val &= ~TRANS_ENABLE; |
| 1727 | I915_WRITE(reg, val); |
| 1728 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1729 | if (intel_wait_for_register(dev_priv, |
| 1730 | reg, TRANS_STATE_ENABLE, 0, |
| 1731 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1732 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1733 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1734 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1735 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1736 | reg = TRANS_CHICKEN2(pipe); |
| 1737 | val = I915_READ(reg); |
| 1738 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1739 | I915_WRITE(reg, val); |
| 1740 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1743 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1744 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1745 | u32 val; |
| 1746 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1747 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1748 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1749 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1750 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1751 | if (intel_wait_for_register(dev_priv, |
| 1752 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1753 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1754 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1755 | |
| 1756 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1757 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1758 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1759 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1762 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1763 | { |
| 1764 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1765 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1766 | if (HAS_PCH_LPT(dev_priv)) |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1767 | return PIPE_A; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1768 | else |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1769 | return crtc->pipe; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1770 | } |
| 1771 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1772 | 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] | 1773 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1774 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1775 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1776 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1777 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1778 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1779 | u32 val; |
| 1780 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1781 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1782 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1783 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1784 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1785 | /* |
| 1786 | * A pipe without a PLL won't actually be able to drive bits from |
| 1787 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1788 | * need the check. |
| 1789 | */ |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1790 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1791 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1792 | assert_dsi_pll_enabled(dev_priv); |
| 1793 | else |
| 1794 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1795 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1796 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1797 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1798 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1799 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1800 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1801 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1802 | } |
| 1803 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1804 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1805 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1806 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1807 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1808 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1809 | /* we keep both pipes enabled on 830 */ |
| 1810 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1811 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1812 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1813 | |
| 1814 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1815 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1816 | |
| 1817 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1818 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1819 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1820 | * resets to its proper value. That also messes up the frame count |
| 1821 | * when it's derived from the timestamps. So let's wait for the |
| 1822 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1823 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1824 | if (dev_priv->drm.max_vblank_count == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1825 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1826 | } |
| 1827 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1828 | 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] | 1829 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1830 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1831 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1832 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1833 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1834 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1835 | u32 val; |
| 1836 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1837 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1838 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1839 | /* |
| 1840 | * Make sure planes won't keep trying to pump pixels to us, |
| 1841 | * or we might hang the display. |
| 1842 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1843 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1844 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1845 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1846 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1847 | if ((val & PIPECONF_ENABLE) == 0) |
| 1848 | return; |
| 1849 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1850 | /* |
| 1851 | * Double wide has implications for planes |
| 1852 | * so best keep it disabled when not needed. |
| 1853 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1854 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1855 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1856 | |
| 1857 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1858 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1859 | val &= ~PIPECONF_ENABLE; |
| 1860 | |
| 1861 | I915_WRITE(reg, val); |
| 1862 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1863 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1864 | } |
| 1865 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1866 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1867 | { |
| 1868 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 1869 | } |
| 1870 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1871 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1872 | 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] | 1873 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1874 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1875 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1876 | |
| 1877 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1878 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1879 | return cpp; |
| 1880 | case I915_FORMAT_MOD_X_TILED: |
| 1881 | if (IS_GEN2(dev_priv)) |
| 1882 | return 128; |
| 1883 | else |
| 1884 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1885 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1886 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1887 | return 128; |
| 1888 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1889 | case I915_FORMAT_MOD_Y_TILED: |
| 1890 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 1891 | return 128; |
| 1892 | else |
| 1893 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1894 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1895 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1896 | return 128; |
| 1897 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1898 | case I915_FORMAT_MOD_Yf_TILED: |
| 1899 | switch (cpp) { |
| 1900 | case 1: |
| 1901 | return 64; |
| 1902 | case 2: |
| 1903 | case 4: |
| 1904 | return 128; |
| 1905 | case 8: |
| 1906 | case 16: |
| 1907 | return 256; |
| 1908 | default: |
| 1909 | MISSING_CASE(cpp); |
| 1910 | return cpp; |
| 1911 | } |
| 1912 | break; |
| 1913 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1914 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1915 | return cpp; |
| 1916 | } |
| 1917 | } |
| 1918 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1919 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1920 | intel_tile_height(const struct drm_framebuffer *fb, int color_plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1921 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1922 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1923 | return 1; |
| 1924 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1925 | return intel_tile_size(to_i915(fb->dev)) / |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1926 | intel_tile_width_bytes(fb, color_plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1929 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1930 | 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] | 1931 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1932 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1933 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1934 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane); |
| 1935 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1936 | |
| 1937 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1938 | *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] | 1939 | } |
| 1940 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1941 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1942 | intel_fb_align_height(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1943 | int color_plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1944 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1945 | unsigned int tile_height = intel_tile_height(fb, color_plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1946 | |
| 1947 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1948 | } |
| 1949 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1950 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1951 | { |
| 1952 | unsigned int size = 0; |
| 1953 | int i; |
| 1954 | |
| 1955 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1956 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1957 | |
| 1958 | return size; |
| 1959 | } |
| 1960 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 1961 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 1962 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 1963 | const struct drm_framebuffer *fb, |
| 1964 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 1965 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1966 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 1967 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1968 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 1969 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 1970 | } |
| 1971 | } |
| 1972 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1973 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 1974 | { |
| 1975 | if (IS_I830(dev_priv)) |
| 1976 | return 16 * 1024; |
| 1977 | else if (IS_I85X(dev_priv)) |
| 1978 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 1979 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 1980 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1981 | else |
| 1982 | return 4 * 1024; |
| 1983 | } |
| 1984 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1985 | 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] | 1986 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1987 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1988 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 1989 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1990 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1991 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1992 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1993 | return 4 * 1024; |
| 1994 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 1995 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1996 | } |
| 1997 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1998 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1999 | int color_plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2000 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2001 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2002 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2003 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2004 | if (color_plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2005 | return 4096; |
| 2006 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2007 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2008 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2009 | return intel_linear_alignment(dev_priv); |
| 2010 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2011 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2012 | return 256 * 1024; |
| 2013 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2014 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2015 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2016 | case I915_FORMAT_MOD_Y_TILED: |
| 2017 | case I915_FORMAT_MOD_Yf_TILED: |
| 2018 | return 1 * 1024 * 1024; |
| 2019 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2020 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2021 | return 0; |
| 2022 | } |
| 2023 | } |
| 2024 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2025 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2026 | { |
| 2027 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2028 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2029 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2030 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2031 | } |
| 2032 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2033 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2034 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2035 | const struct i915_ggtt_view *view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2036 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2037 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2038 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2039 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2040 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2041 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2042 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2043 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2044 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2045 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2046 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2047 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2048 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2049 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2050 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2051 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2052 | * we should always have valid PTE following the scanout preventing |
| 2053 | * the VT-d warning. |
| 2054 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2055 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2056 | alignment = 256 * 1024; |
| 2057 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2058 | /* |
| 2059 | * Global gtt pte registers are special registers which actually forward |
| 2060 | * writes to a chunk of system memory. Which means that there is no risk |
| 2061 | * that the register values disappear as soon as we call |
| 2062 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2063 | * pin/unpin/fence and not more. |
| 2064 | */ |
| 2065 | intel_runtime_pm_get(dev_priv); |
| 2066 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2067 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2068 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2069 | pinctl = 0; |
| 2070 | |
| 2071 | /* Valleyview is definitely limited to scanning out the first |
| 2072 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2073 | * g4x display engine and that all earlier gen are similarly |
| 2074 | * limited. Testing suggests that it is a little more |
| 2075 | * complicated than this. For example, Cherryview appears quite |
| 2076 | * happy to scanout from anywhere within its global aperture. |
| 2077 | */ |
| 2078 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 2079 | pinctl |= PIN_MAPPABLE; |
| 2080 | |
| 2081 | vma = i915_gem_object_pin_to_display_plane(obj, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2082 | alignment, view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2083 | if (IS_ERR(vma)) |
| 2084 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2085 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2086 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2087 | int ret; |
| 2088 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2089 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2090 | * fence, whereas 965+ only requires a fence if using |
| 2091 | * framebuffer compression. For simplicity, we always, when |
| 2092 | * possible, install a fence as the cost is not that onerous. |
| 2093 | * |
| 2094 | * If we fail to fence the tiled scanout, then either the |
| 2095 | * modeset will reject the change (which is highly unlikely as |
| 2096 | * the affected systems, all but one, do not have unmappable |
| 2097 | * space) or we will not be able to enable full powersaving |
| 2098 | * techniques (also likely not to apply due to various limits |
| 2099 | * FBC and the like impose on the size of the buffer, which |
| 2100 | * presumably we violated anyway with this unmappable buffer). |
| 2101 | * Anyway, it is presumably better to stumble onwards with |
| 2102 | * something and try to run the system in a "less than optimal" |
| 2103 | * mode that matches the user configuration. |
| 2104 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2105 | ret = i915_vma_pin_fence(vma); |
| 2106 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2107 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2108 | vma = ERR_PTR(ret); |
| 2109 | goto err; |
| 2110 | } |
| 2111 | |
| 2112 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2113 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2114 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2115 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2116 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2117 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2118 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2119 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2120 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2121 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2122 | } |
| 2123 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2124 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2125 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2126 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2127 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2128 | if (flags & PLANE_HAS_FENCE) |
| 2129 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2130 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2131 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2132 | } |
| 2133 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2134 | 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] | 2135 | unsigned int rotation) |
| 2136 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2137 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2138 | return to_intel_framebuffer(fb)->rotated[color_plane].pitch; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2139 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2140 | return fb->pitches[color_plane]; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2141 | } |
| 2142 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2143 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2144 | * Convert the x/y offsets into a linear offset. |
| 2145 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2146 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2147 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2148 | */ |
| 2149 | u32 intel_fb_xy_to_linear(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 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2153 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2154 | unsigned int cpp = fb->format->cpp[color_plane]; |
| 2155 | unsigned int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2156 | |
| 2157 | return y * pitch + x * cpp; |
| 2158 | } |
| 2159 | |
| 2160 | /* |
| 2161 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2162 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2163 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2164 | */ |
| 2165 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2166 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2167 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2168 | |
| 2169 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2170 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2171 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2172 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2173 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2174 | *x += intel_fb->rotated[color_plane].x; |
| 2175 | *y += intel_fb->rotated[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2176 | } else { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2177 | *x += intel_fb->normal[color_plane].x; |
| 2178 | *y += intel_fb->normal[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2182 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2183 | unsigned int tile_width, |
| 2184 | unsigned int tile_height, |
| 2185 | unsigned int tile_size, |
| 2186 | unsigned int pitch_tiles, |
| 2187 | u32 old_offset, |
| 2188 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2189 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2190 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2191 | unsigned int tiles; |
| 2192 | |
| 2193 | WARN_ON(old_offset & (tile_size - 1)); |
| 2194 | WARN_ON(new_offset & (tile_size - 1)); |
| 2195 | WARN_ON(new_offset > old_offset); |
| 2196 | |
| 2197 | tiles = (old_offset - new_offset) / tile_size; |
| 2198 | |
| 2199 | *y += tiles / pitch_tiles * tile_height; |
| 2200 | *x += tiles % pitch_tiles * tile_width; |
| 2201 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2202 | /* minimize x in case it got needlessly big */ |
| 2203 | *y += *x / pitch_pixels * tile_height; |
| 2204 | *x %= pitch_pixels; |
| 2205 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2206 | return new_offset; |
| 2207 | } |
| 2208 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2209 | static u32 intel_adjust_aligned_offset(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2210 | const struct drm_framebuffer *fb, |
| 2211 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2212 | unsigned int rotation, |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2213 | unsigned int pitch, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2214 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2215 | { |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2216 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2217 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2218 | |
| 2219 | WARN_ON(new_offset > old_offset); |
| 2220 | |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2221 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2222 | unsigned int tile_size, tile_width, tile_height; |
| 2223 | unsigned int pitch_tiles; |
| 2224 | |
| 2225 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2226 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2227 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2228 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2229 | pitch_tiles = pitch / tile_height; |
| 2230 | swap(tile_width, tile_height); |
| 2231 | } else { |
| 2232 | pitch_tiles = pitch / (tile_width * cpp); |
| 2233 | } |
| 2234 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2235 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2236 | tile_size, pitch_tiles, |
| 2237 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2238 | } else { |
| 2239 | old_offset += *y * pitch + *x * cpp; |
| 2240 | |
| 2241 | *y = (old_offset - new_offset) / pitch; |
| 2242 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2243 | } |
| 2244 | |
| 2245 | return new_offset; |
| 2246 | } |
| 2247 | |
| 2248 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2249 | * Adjust the tile offset by moving the difference into |
| 2250 | * the x/y offsets. |
| 2251 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2252 | static u32 intel_plane_adjust_aligned_offset(int *x, int *y, |
| 2253 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2254 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2255 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2256 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2257 | 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] | 2258 | state->base.rotation, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2259 | state->color_plane[color_plane].stride, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2260 | old_offset, new_offset); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /* |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2264 | * Computes the aligned offset to the base tile and adjusts |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2265 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2266 | * |
| 2267 | * In the 90/270 rotated case, x and y are assumed |
| 2268 | * to be already rotated to match the rotated GTT view, and |
| 2269 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2270 | * |
| 2271 | * This function is used when computing the derived information |
| 2272 | * under intel_framebuffer, so using any of that information |
| 2273 | * here is not allowed. Anything under drm_framebuffer can be |
| 2274 | * used. This is why the user has to pass in the pitch since it |
| 2275 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2276 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2277 | static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv, |
| 2278 | int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2279 | const struct drm_framebuffer *fb, |
| 2280 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2281 | unsigned int pitch, |
| 2282 | unsigned int rotation, |
| 2283 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2284 | { |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2285 | uint64_t fb_modifier = fb->modifier; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2286 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2287 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2288 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2289 | if (alignment) |
| 2290 | alignment--; |
| 2291 | |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2292 | if (fb_modifier != DRM_FORMAT_MOD_LINEAR) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2293 | unsigned int tile_size, tile_width, tile_height; |
| 2294 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2295 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2296 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2297 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2298 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2299 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2300 | pitch_tiles = pitch / tile_height; |
| 2301 | swap(tile_width, tile_height); |
| 2302 | } else { |
| 2303 | pitch_tiles = pitch / (tile_width * cpp); |
| 2304 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2305 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2306 | tile_rows = *y / tile_height; |
| 2307 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2308 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2309 | tiles = *x / tile_width; |
| 2310 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2311 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2312 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2313 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2314 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2315 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2316 | tile_size, pitch_tiles, |
| 2317 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2318 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2319 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2320 | offset_aligned = offset & ~alignment; |
| 2321 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2322 | *y = (offset & alignment) / pitch; |
| 2323 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2324 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2325 | |
| 2326 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2327 | } |
| 2328 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2329 | static u32 intel_plane_compute_aligned_offset(int *x, int *y, |
| 2330 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2331 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2332 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2333 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2334 | 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] | 2335 | const struct drm_framebuffer *fb = state->base.fb; |
| 2336 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2337 | int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2338 | u32 alignment; |
| 2339 | |
| 2340 | if (intel_plane->id == PLANE_CURSOR) |
| 2341 | alignment = intel_cursor_alignment(dev_priv); |
| 2342 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2343 | alignment = intel_surf_alignment(fb, color_plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2344 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2345 | 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] | 2346 | pitch, rotation, alignment); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2347 | } |
| 2348 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2349 | /* Convert the fb->offset[] into x/y offsets */ |
| 2350 | static int intel_fb_offset_to_xy(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2351 | const struct drm_framebuffer *fb, |
| 2352 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2353 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2354 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2355 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2356 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2357 | fb->offsets[color_plane] % intel_tile_size(dev_priv)) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2358 | return -EINVAL; |
| 2359 | |
| 2360 | *x = 0; |
| 2361 | *y = 0; |
| 2362 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2363 | intel_adjust_aligned_offset(x, y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2364 | fb, color_plane, DRM_MODE_ROTATE_0, |
| 2365 | fb->pitches[color_plane], |
| 2366 | fb->offsets[color_plane], 0); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2367 | |
| 2368 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2369 | } |
| 2370 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2371 | static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier) |
| 2372 | { |
| 2373 | switch (fb_modifier) { |
| 2374 | case I915_FORMAT_MOD_X_TILED: |
| 2375 | return I915_TILING_X; |
| 2376 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2377 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2378 | return I915_TILING_Y; |
| 2379 | default: |
| 2380 | return I915_TILING_NONE; |
| 2381 | } |
| 2382 | } |
| 2383 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2384 | /* |
| 2385 | * From the Sky Lake PRM: |
| 2386 | * "The Color Control Surface (CCS) contains the compression status of |
| 2387 | * the cache-line pairs. The compression state of the cache-line pair |
| 2388 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2389 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2390 | * cache-line-pairs. CCS is always Y tiled." |
| 2391 | * |
| 2392 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2393 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2394 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2395 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2396 | * main surface. |
| 2397 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2398 | static const struct drm_format_info ccs_formats[] = { |
| 2399 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2400 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2401 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2402 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2403 | }; |
| 2404 | |
| 2405 | static const struct drm_format_info * |
| 2406 | lookup_format_info(const struct drm_format_info formats[], |
| 2407 | int num_formats, u32 format) |
| 2408 | { |
| 2409 | int i; |
| 2410 | |
| 2411 | for (i = 0; i < num_formats; i++) { |
| 2412 | if (formats[i].format == format) |
| 2413 | return &formats[i]; |
| 2414 | } |
| 2415 | |
| 2416 | return NULL; |
| 2417 | } |
| 2418 | |
| 2419 | static const struct drm_format_info * |
| 2420 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2421 | { |
| 2422 | switch (cmd->modifier[0]) { |
| 2423 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2424 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2425 | return lookup_format_info(ccs_formats, |
| 2426 | ARRAY_SIZE(ccs_formats), |
| 2427 | cmd->pixel_format); |
| 2428 | default: |
| 2429 | return NULL; |
| 2430 | } |
| 2431 | } |
| 2432 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2433 | bool is_ccs_modifier(u64 modifier) |
| 2434 | { |
| 2435 | return modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2436 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 2437 | } |
| 2438 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2439 | static int |
| 2440 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2441 | struct drm_framebuffer *fb) |
| 2442 | { |
| 2443 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2444 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2445 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2446 | u32 gtt_offset_rotated = 0; |
| 2447 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2448 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2449 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2450 | |
| 2451 | for (i = 0; i < num_planes; i++) { |
| 2452 | unsigned int width, height; |
| 2453 | unsigned int cpp, size; |
| 2454 | u32 offset; |
| 2455 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2456 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2457 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2458 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2459 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2460 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2461 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2462 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2463 | if (ret) { |
| 2464 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2465 | i, fb->offsets[i]); |
| 2466 | return ret; |
| 2467 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2468 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2469 | if (is_ccs_modifier(fb->modifier) && i == 1) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2470 | int hsub = fb->format->hsub; |
| 2471 | int vsub = fb->format->vsub; |
| 2472 | int tile_width, tile_height; |
| 2473 | int main_x, main_y; |
| 2474 | int ccs_x, ccs_y; |
| 2475 | |
| 2476 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2477 | tile_width *= hsub; |
| 2478 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2479 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2480 | ccs_x = (x * hsub) % tile_width; |
| 2481 | ccs_y = (y * vsub) % tile_height; |
| 2482 | main_x = intel_fb->normal[0].x % tile_width; |
| 2483 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2484 | |
| 2485 | /* |
| 2486 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2487 | * x/y offsets must match between CCS and the main surface. |
| 2488 | */ |
| 2489 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2490 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2491 | main_x, main_y, |
| 2492 | ccs_x, ccs_y, |
| 2493 | intel_fb->normal[0].x, |
| 2494 | intel_fb->normal[0].y, |
| 2495 | x, y); |
| 2496 | return -EINVAL; |
| 2497 | } |
| 2498 | } |
| 2499 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2500 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2501 | * The fence (if used) is aligned to the start of the object |
| 2502 | * so having the framebuffer wrap around across the edge of the |
| 2503 | * fenced region doesn't really work. We have no API to configure |
| 2504 | * the fence start offset within the object (nor could we probably |
| 2505 | * on gen2/3). So it's just easier if we just require that the |
| 2506 | * fb layout agrees with the fence layout. We already check that the |
| 2507 | * fb stride matches the fence stride elsewhere. |
| 2508 | */ |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2509 | if (i == 0 && i915_gem_object_is_tiled(obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2510 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2511 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2512 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2513 | return -EINVAL; |
| 2514 | } |
| 2515 | |
| 2516 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2517 | * First pixel of the framebuffer from |
| 2518 | * the start of the normal gtt mapping. |
| 2519 | */ |
| 2520 | intel_fb->normal[i].x = x; |
| 2521 | intel_fb->normal[i].y = y; |
| 2522 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2523 | offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i, |
| 2524 | fb->pitches[i], |
| 2525 | DRM_MODE_ROTATE_0, |
| 2526 | tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2527 | offset /= tile_size; |
| 2528 | |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2529 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2530 | unsigned int tile_width, tile_height; |
| 2531 | unsigned int pitch_tiles; |
| 2532 | struct drm_rect r; |
| 2533 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2534 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2535 | |
| 2536 | rot_info->plane[i].offset = offset; |
| 2537 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2538 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2539 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2540 | |
| 2541 | intel_fb->rotated[i].pitch = |
| 2542 | rot_info->plane[i].height * tile_height; |
| 2543 | |
| 2544 | /* how many tiles does this plane need */ |
| 2545 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2546 | /* |
| 2547 | * If the plane isn't horizontally tile aligned, |
| 2548 | * we need one more tile. |
| 2549 | */ |
| 2550 | if (x != 0) |
| 2551 | size++; |
| 2552 | |
| 2553 | /* rotate the x/y offsets to match the GTT view */ |
| 2554 | r.x1 = x; |
| 2555 | r.y1 = y; |
| 2556 | r.x2 = x + width; |
| 2557 | r.y2 = y + height; |
| 2558 | drm_rect_rotate(&r, |
| 2559 | rot_info->plane[i].width * tile_width, |
| 2560 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2561 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2562 | x = r.x1; |
| 2563 | y = r.y1; |
| 2564 | |
| 2565 | /* rotate the tile dimensions to match the GTT view */ |
| 2566 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2567 | swap(tile_width, tile_height); |
| 2568 | |
| 2569 | /* |
| 2570 | * We only keep the x/y offsets, so push all of the |
| 2571 | * gtt offset into the x/y offsets. |
| 2572 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2573 | intel_adjust_tile_offset(&x, &y, |
| 2574 | tile_width, tile_height, |
| 2575 | tile_size, pitch_tiles, |
| 2576 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2577 | |
| 2578 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2579 | |
| 2580 | /* |
| 2581 | * First pixel of the framebuffer from |
| 2582 | * the start of the rotated gtt mapping. |
| 2583 | */ |
| 2584 | intel_fb->rotated[i].x = x; |
| 2585 | intel_fb->rotated[i].y = y; |
| 2586 | } else { |
| 2587 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2588 | x * cpp, tile_size); |
| 2589 | } |
| 2590 | |
| 2591 | /* how many tiles in total needed in the bo */ |
| 2592 | max_size = max(max_size, offset + size); |
| 2593 | } |
| 2594 | |
Ville Syrjälä | 4e05047 | 2018-09-12 21:04:43 +0300 | [diff] [blame] | 2595 | if (mul_u32_u32(max_size, tile_size) > obj->base.size) { |
| 2596 | DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n", |
| 2597 | mul_u32_u32(max_size, tile_size), obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2598 | return -EINVAL; |
| 2599 | } |
| 2600 | |
| 2601 | return 0; |
| 2602 | } |
| 2603 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2604 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2605 | { |
| 2606 | switch (format) { |
| 2607 | case DISPPLANE_8BPP: |
| 2608 | return DRM_FORMAT_C8; |
| 2609 | case DISPPLANE_BGRX555: |
| 2610 | return DRM_FORMAT_XRGB1555; |
| 2611 | case DISPPLANE_BGRX565: |
| 2612 | return DRM_FORMAT_RGB565; |
| 2613 | default: |
| 2614 | case DISPPLANE_BGRX888: |
| 2615 | return DRM_FORMAT_XRGB8888; |
| 2616 | case DISPPLANE_RGBX888: |
| 2617 | return DRM_FORMAT_XBGR8888; |
| 2618 | case DISPPLANE_BGRX101010: |
| 2619 | return DRM_FORMAT_XRGB2101010; |
| 2620 | case DISPPLANE_RGBX101010: |
| 2621 | return DRM_FORMAT_XBGR2101010; |
| 2622 | } |
| 2623 | } |
| 2624 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2625 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2626 | { |
| 2627 | switch (format) { |
| 2628 | case PLANE_CTL_FORMAT_RGB_565: |
| 2629 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2630 | case PLANE_CTL_FORMAT_NV12: |
| 2631 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2632 | default: |
| 2633 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2634 | if (rgb_order) { |
| 2635 | if (alpha) |
| 2636 | return DRM_FORMAT_ABGR8888; |
| 2637 | else |
| 2638 | return DRM_FORMAT_XBGR8888; |
| 2639 | } else { |
| 2640 | if (alpha) |
| 2641 | return DRM_FORMAT_ARGB8888; |
| 2642 | else |
| 2643 | return DRM_FORMAT_XRGB8888; |
| 2644 | } |
| 2645 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2646 | if (rgb_order) |
| 2647 | return DRM_FORMAT_XBGR2101010; |
| 2648 | else |
| 2649 | return DRM_FORMAT_XRGB2101010; |
| 2650 | } |
| 2651 | } |
| 2652 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2653 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2654 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2655 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2656 | { |
| 2657 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2658 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2659 | struct drm_i915_gem_object *obj = NULL; |
| 2660 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2661 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2662 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2663 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2664 | PAGE_SIZE); |
| 2665 | |
| 2666 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2667 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2668 | if (plane_config->size == 0) |
| 2669 | return false; |
| 2670 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2671 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2672 | * important and we should probably use that space with FBC or other |
| 2673 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2674 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2675 | return false; |
| 2676 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2677 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2678 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2679 | base_aligned, |
| 2680 | base_aligned, |
| 2681 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2682 | mutex_unlock(&dev->struct_mutex); |
| 2683 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2684 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2685 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2686 | if (plane_config->tiling == I915_TILING_X) |
| 2687 | obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2688 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2689 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2690 | mode_cmd.width = fb->width; |
| 2691 | mode_cmd.height = fb->height; |
| 2692 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2693 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2694 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2695 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2696 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2697 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2698 | goto out_unref_obj; |
| 2699 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2700 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2701 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2702 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2703 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2704 | |
| 2705 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2706 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2707 | return false; |
| 2708 | } |
| 2709 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2710 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2711 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2712 | struct intel_plane_state *plane_state, |
| 2713 | bool visible) |
| 2714 | { |
| 2715 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2716 | |
| 2717 | plane_state->base.visible = visible; |
| 2718 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2719 | if (visible) |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2720 | crtc_state->base.plane_mask |= drm_plane_mask(&plane->base); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2721 | else |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2722 | crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2723 | } |
| 2724 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2725 | static void fixup_active_planes(struct intel_crtc_state *crtc_state) |
| 2726 | { |
| 2727 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2728 | struct drm_plane *plane; |
| 2729 | |
| 2730 | /* |
| 2731 | * Active_planes aliases if multiple "primary" or cursor planes |
| 2732 | * have been used on the same (or wrong) pipe. plane_mask uses |
| 2733 | * unique ids, hence we can use that to reconstruct active_planes. |
| 2734 | */ |
| 2735 | crtc_state->active_planes = 0; |
| 2736 | |
| 2737 | drm_for_each_plane_mask(plane, &dev_priv->drm, |
| 2738 | crtc_state->base.plane_mask) |
| 2739 | crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); |
| 2740 | } |
| 2741 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2742 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2743 | struct intel_plane *plane) |
| 2744 | { |
| 2745 | struct intel_crtc_state *crtc_state = |
| 2746 | to_intel_crtc_state(crtc->base.state); |
| 2747 | struct intel_plane_state *plane_state = |
| 2748 | to_intel_plane_state(plane->base.state); |
| 2749 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 2750 | DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", |
| 2751 | plane->base.base.id, plane->base.name, |
| 2752 | crtc->base.base.id, crtc->base.name); |
| 2753 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2754 | intel_set_plane_visible(crtc_state, plane_state, false); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2755 | fixup_active_planes(crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2756 | |
| 2757 | if (plane->id == PLANE_PRIMARY) |
| 2758 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2759 | |
| 2760 | trace_intel_disable_plane(&plane->base, crtc); |
| 2761 | plane->disable_plane(plane, crtc); |
| 2762 | } |
| 2763 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2764 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2765 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2766 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2767 | { |
| 2768 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2769 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2770 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2771 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2772 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2773 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2774 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2775 | struct intel_plane_state *intel_state = |
| 2776 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2777 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2778 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2779 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2780 | return; |
| 2781 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2782 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2783 | fb = &plane_config->fb->base; |
| 2784 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2785 | } |
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 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2788 | |
| 2789 | /* |
| 2790 | * Failed to alloc the obj, check to see if we should share |
| 2791 | * an fb with another CRTC instead |
| 2792 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2793 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2794 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2795 | |
| 2796 | if (c == &intel_crtc->base) |
| 2797 | continue; |
| 2798 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2799 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2800 | continue; |
| 2801 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2802 | state = to_intel_plane_state(c->primary->state); |
| 2803 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2804 | continue; |
| 2805 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2806 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2807 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2808 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2809 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2810 | } |
| 2811 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2812 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2813 | /* |
| 2814 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2815 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2816 | * which will lead to problems later if we don't fix it up. The |
| 2817 | * simplest solution is to just disable the primary plane now and |
| 2818 | * pretend the BIOS never had it enabled. |
| 2819 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2820 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2821 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2822 | return; |
| 2823 | |
| 2824 | valid_fb: |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2825 | intel_fill_fb_ggtt_view(&intel_state->view, fb, |
| 2826 | intel_state->base.rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2827 | intel_state->color_plane[0].stride = |
| 2828 | intel_fb_pitch(fb, 0, intel_state->base.rotation); |
| 2829 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2830 | mutex_lock(&dev->struct_mutex); |
| 2831 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2832 | intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2833 | &intel_state->view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2834 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2835 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2836 | mutex_unlock(&dev->struct_mutex); |
| 2837 | if (IS_ERR(intel_state->vma)) { |
| 2838 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2839 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2840 | |
| 2841 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2842 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2843 | return; |
| 2844 | } |
| 2845 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2846 | obj = intel_fb_obj(fb); |
| 2847 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2848 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2849 | plane_state->src_x = 0; |
| 2850 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2851 | plane_state->src_w = fb->width << 16; |
| 2852 | plane_state->src_h = fb->height << 16; |
| 2853 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2854 | plane_state->crtc_x = 0; |
| 2855 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2856 | plane_state->crtc_w = fb->width; |
| 2857 | plane_state->crtc_h = fb->height; |
| 2858 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2859 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2860 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2861 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2862 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2863 | dev_priv->preserve_bios_swizzle = true; |
| 2864 | |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 2865 | plane_state->fb = fb; |
| 2866 | plane_state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2867 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2868 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2869 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2870 | } |
| 2871 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2872 | static int skl_max_plane_width(const struct drm_framebuffer *fb, |
| 2873 | int color_plane, |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2874 | unsigned int rotation) |
| 2875 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2876 | int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2877 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2878 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2879 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2880 | case I915_FORMAT_MOD_X_TILED: |
| 2881 | switch (cpp) { |
| 2882 | case 8: |
| 2883 | return 4096; |
| 2884 | case 4: |
| 2885 | case 2: |
| 2886 | case 1: |
| 2887 | return 8192; |
| 2888 | default: |
| 2889 | MISSING_CASE(cpp); |
| 2890 | break; |
| 2891 | } |
| 2892 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2893 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2894 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2895 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2896 | case I915_FORMAT_MOD_Y_TILED: |
| 2897 | case I915_FORMAT_MOD_Yf_TILED: |
| 2898 | switch (cpp) { |
| 2899 | case 8: |
| 2900 | return 2048; |
| 2901 | case 4: |
| 2902 | return 4096; |
| 2903 | case 2: |
| 2904 | case 1: |
| 2905 | return 8192; |
| 2906 | default: |
| 2907 | MISSING_CASE(cpp); |
| 2908 | break; |
| 2909 | } |
| 2910 | break; |
| 2911 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2912 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | return 2048; |
| 2916 | } |
| 2917 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2918 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2919 | int main_x, int main_y, u32 main_offset) |
| 2920 | { |
| 2921 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2922 | int hsub = fb->format->hsub; |
| 2923 | int vsub = fb->format->vsub; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2924 | int aux_x = plane_state->color_plane[1].x; |
| 2925 | int aux_y = plane_state->color_plane[1].y; |
| 2926 | u32 aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2927 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2928 | |
| 2929 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2930 | int x, y; |
| 2931 | |
| 2932 | if (aux_x == main_x && aux_y == main_y) |
| 2933 | break; |
| 2934 | |
| 2935 | if (aux_offset == 0) |
| 2936 | break; |
| 2937 | |
| 2938 | x = aux_x / hsub; |
| 2939 | y = aux_y / vsub; |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2940 | aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1, |
| 2941 | aux_offset, aux_offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2942 | aux_x = x * hsub + aux_x % hsub; |
| 2943 | aux_y = y * vsub + aux_y % vsub; |
| 2944 | } |
| 2945 | |
| 2946 | if (aux_x != main_x || aux_y != main_y) |
| 2947 | return false; |
| 2948 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2949 | plane_state->color_plane[1].offset = aux_offset; |
| 2950 | plane_state->color_plane[1].x = aux_x; |
| 2951 | plane_state->color_plane[1].y = aux_y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2952 | |
| 2953 | return true; |
| 2954 | } |
| 2955 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 2956 | 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] | 2957 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2958 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2959 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2960 | int x = plane_state->base.src.x1 >> 16; |
| 2961 | int y = plane_state->base.src.y1 >> 16; |
| 2962 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 2963 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2964 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 2965 | int max_height = 4096; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2966 | u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2967 | |
| 2968 | if (w > max_width || h > max_height) { |
| 2969 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 2970 | w, h, max_width, max_height); |
| 2971 | return -EINVAL; |
| 2972 | } |
| 2973 | |
| 2974 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2975 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2976 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2977 | |
| 2978 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2979 | * AUX surface offset is specified as the distance from the |
| 2980 | * main surface offset, and it must be non-negative. Make |
| 2981 | * sure that is what we will get. |
| 2982 | */ |
| 2983 | if (offset > aux_offset) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2984 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 2985 | offset, aux_offset & ~(alignment - 1)); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2986 | |
| 2987 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2988 | * When using an X-tiled surface, the plane blows up |
| 2989 | * if the x offset + width exceed the stride. |
| 2990 | * |
| 2991 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 2992 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2993 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2994 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2995 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2996 | while ((x + w) * cpp > plane_state->color_plane[0].stride) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2997 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2998 | 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] | 2999 | return -EINVAL; |
| 3000 | } |
| 3001 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3002 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3003 | offset, offset - alignment); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3007 | /* |
| 3008 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3009 | * they match with the main surface x/y offsets. |
| 3010 | */ |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3011 | if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3012 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3013 | if (offset == 0) |
| 3014 | break; |
| 3015 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3016 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3017 | offset, offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3020 | 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] | 3021 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3022 | return -EINVAL; |
| 3023 | } |
| 3024 | } |
| 3025 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3026 | plane_state->color_plane[0].offset = offset; |
| 3027 | plane_state->color_plane[0].x = x; |
| 3028 | plane_state->color_plane[0].y = y; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3029 | |
| 3030 | return 0; |
| 3031 | } |
| 3032 | |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 3033 | static int |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3034 | skl_check_nv12_surface(struct intel_plane_state *plane_state) |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 3035 | { |
| 3036 | /* Display WA #1106 */ |
| 3037 | if (plane_state->base.rotation != |
| 3038 | (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90) && |
| 3039 | plane_state->base.rotation != DRM_MODE_ROTATE_270) |
| 3040 | return 0; |
| 3041 | |
| 3042 | /* |
| 3043 | * src coordinates are rotated here. |
| 3044 | * We check height but report it as width |
| 3045 | */ |
| 3046 | if (((drm_rect_height(&plane_state->base.src) >> 16) % 4) != 0) { |
| 3047 | DRM_DEBUG_KMS("src width must be multiple " |
| 3048 | "of 4 for rotated NV12\n"); |
| 3049 | return -EINVAL; |
| 3050 | } |
| 3051 | |
| 3052 | return 0; |
| 3053 | } |
| 3054 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3055 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3056 | { |
| 3057 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3058 | unsigned int rotation = plane_state->base.rotation; |
| 3059 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3060 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3061 | int x = plane_state->base.src.x1 >> 17; |
| 3062 | int y = plane_state->base.src.y1 >> 17; |
| 3063 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3064 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3065 | u32 offset; |
| 3066 | |
| 3067 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3068 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3069 | |
| 3070 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3071 | if (w > max_width || h > max_height) { |
| 3072 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3073 | w, h, max_width, max_height); |
| 3074 | return -EINVAL; |
| 3075 | } |
| 3076 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3077 | plane_state->color_plane[1].offset = offset; |
| 3078 | plane_state->color_plane[1].x = x; |
| 3079 | plane_state->color_plane[1].y = y; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3080 | |
| 3081 | return 0; |
| 3082 | } |
| 3083 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3084 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3085 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3086 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3087 | int src_x = plane_state->base.src.x1 >> 16; |
| 3088 | int src_y = plane_state->base.src.y1 >> 16; |
| 3089 | int hsub = fb->format->hsub; |
| 3090 | int vsub = fb->format->vsub; |
| 3091 | int x = src_x / hsub; |
| 3092 | int y = src_y / vsub; |
| 3093 | u32 offset; |
| 3094 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3095 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3096 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3097 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3098 | plane_state->color_plane[1].offset = offset; |
| 3099 | plane_state->color_plane[1].x = x * hsub + src_x % hsub; |
| 3100 | plane_state->color_plane[1].y = y * vsub + src_y % vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3101 | |
| 3102 | return 0; |
| 3103 | } |
| 3104 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3105 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3106 | { |
| 3107 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3108 | unsigned int rotation = plane_state->base.rotation; |
| 3109 | int ret; |
| 3110 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3111 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3112 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3113 | plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation); |
| 3114 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3115 | ret = intel_plane_check_stride(plane_state); |
| 3116 | if (ret) |
| 3117 | return ret; |
| 3118 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3119 | /* HW only has 8 bits pixel precision, disable plane if invisible */ |
| 3120 | if (!(plane_state->base.alpha >> 8)) |
| 3121 | plane_state->base.visible = false; |
| 3122 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3123 | if (!plane_state->base.visible) |
| 3124 | return 0; |
| 3125 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3126 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3127 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3128 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3129 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3130 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3131 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3132 | /* |
| 3133 | * Handle the AUX surface first since |
| 3134 | * the main surface setup depends on it. |
| 3135 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3136 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3137 | ret = skl_check_nv12_surface(plane_state); |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 3138 | if (ret) |
| 3139 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3140 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3141 | if (ret) |
| 3142 | return ret; |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3143 | } else if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3144 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3145 | if (ret) |
| 3146 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3147 | } else { |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3148 | plane_state->color_plane[1].offset = ~0xfff; |
| 3149 | plane_state->color_plane[1].x = 0; |
| 3150 | plane_state->color_plane[1].y = 0; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3151 | } |
| 3152 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3153 | ret = skl_check_main_surface(plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3154 | if (ret) |
| 3155 | return ret; |
| 3156 | |
| 3157 | return 0; |
| 3158 | } |
| 3159 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3160 | unsigned int |
| 3161 | i9xx_plane_max_stride(struct intel_plane *plane, |
| 3162 | u32 pixel_format, u64 modifier, |
| 3163 | unsigned int rotation) |
| 3164 | { |
| 3165 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3166 | |
| 3167 | if (!HAS_GMCH_DISPLAY(dev_priv)) { |
| 3168 | return 32*1024; |
| 3169 | } else if (INTEL_GEN(dev_priv) >= 4) { |
| 3170 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3171 | return 16*1024; |
| 3172 | else |
| 3173 | return 32*1024; |
| 3174 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 3175 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3176 | return 8*1024; |
| 3177 | else |
| 3178 | return 16*1024; |
| 3179 | } else { |
| 3180 | if (plane->i9xx_plane == PLANE_C) |
| 3181 | return 4*1024; |
| 3182 | else |
| 3183 | return 8*1024; |
| 3184 | } |
| 3185 | } |
| 3186 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3187 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3188 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3189 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3190 | struct drm_i915_private *dev_priv = |
| 3191 | to_i915(plane_state->base.plane->dev); |
| 3192 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3193 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3194 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3195 | u32 dspcntr; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3196 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3197 | dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3198 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3199 | if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) || |
| 3200 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3201 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3202 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3203 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 3204 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3205 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3206 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3207 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3208 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3209 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3210 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3211 | dspcntr |= DISPPLANE_8BPP; |
| 3212 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3213 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3214 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3215 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3216 | case DRM_FORMAT_RGB565: |
| 3217 | dspcntr |= DISPPLANE_BGRX565; |
| 3218 | break; |
| 3219 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3220 | dspcntr |= DISPPLANE_BGRX888; |
| 3221 | break; |
| 3222 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3223 | dspcntr |= DISPPLANE_RGBX888; |
| 3224 | break; |
| 3225 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3226 | dspcntr |= DISPPLANE_BGRX101010; |
| 3227 | break; |
| 3228 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3229 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3230 | break; |
| 3231 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3232 | MISSING_CASE(fb->format->format); |
| 3233 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3234 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3235 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3236 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3237 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3238 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3239 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3240 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3241 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3242 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3243 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3244 | dspcntr |= DISPPLANE_MIRROR; |
| 3245 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3246 | return dspcntr; |
| 3247 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3248 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3249 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3250 | { |
| 3251 | struct drm_i915_private *dev_priv = |
| 3252 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3253 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3254 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3255 | int src_x = plane_state->base.src.x1 >> 16; |
| 3256 | int src_y = plane_state->base.src.y1 >> 16; |
| 3257 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3258 | int ret; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3259 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3260 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3261 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3262 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3263 | ret = intel_plane_check_stride(plane_state); |
| 3264 | if (ret) |
| 3265 | return ret; |
| 3266 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3267 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3268 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3269 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3270 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 3271 | plane_state, 0); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3272 | else |
| 3273 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3274 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3275 | /* HSW/BDW do this automagically in hardware */ |
| 3276 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3277 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3278 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3279 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3280 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3281 | src_x += src_w - 1; |
| 3282 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3283 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3284 | src_x += src_w - 1; |
| 3285 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3286 | } |
| 3287 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3288 | plane_state->color_plane[0].offset = offset; |
| 3289 | plane_state->color_plane[0].x = src_x; |
| 3290 | plane_state->color_plane[0].y = src_y; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3291 | |
| 3292 | return 0; |
| 3293 | } |
| 3294 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3295 | static int |
| 3296 | i9xx_plane_check(struct intel_crtc_state *crtc_state, |
| 3297 | struct intel_plane_state *plane_state) |
| 3298 | { |
| 3299 | int ret; |
| 3300 | |
Ville Syrjälä | 25721f8 | 2018-09-07 18:24:12 +0300 | [diff] [blame] | 3301 | ret = chv_plane_check_rotation(plane_state); |
| 3302 | if (ret) |
| 3303 | return ret; |
| 3304 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3305 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 3306 | &crtc_state->base, |
| 3307 | DRM_PLANE_HELPER_NO_SCALING, |
| 3308 | DRM_PLANE_HELPER_NO_SCALING, |
| 3309 | false, true); |
| 3310 | if (ret) |
| 3311 | return ret; |
| 3312 | |
| 3313 | if (!plane_state->base.visible) |
| 3314 | return 0; |
| 3315 | |
| 3316 | ret = intel_plane_check_src_coordinates(plane_state); |
| 3317 | if (ret) |
| 3318 | return ret; |
| 3319 | |
| 3320 | ret = i9xx_check_plane_surface(plane_state); |
| 3321 | if (ret) |
| 3322 | return ret; |
| 3323 | |
| 3324 | plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state); |
| 3325 | |
| 3326 | return 0; |
| 3327 | } |
| 3328 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3329 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3330 | const struct intel_crtc_state *crtc_state, |
| 3331 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3332 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3333 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3334 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3335 | u32 linear_offset; |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 3336 | u32 dspcntr = plane_state->ctl; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3337 | i915_reg_t reg = DSPCNTR(i9xx_plane); |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3338 | int x = plane_state->color_plane[0].x; |
| 3339 | int y = plane_state->color_plane[0].y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3340 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3341 | u32 dspaddr_offset; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3342 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3343 | 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] | 3344 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3345 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3346 | dspaddr_offset = plane_state->color_plane[0].offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3347 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3348 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3349 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3350 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3351 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3352 | if (INTEL_GEN(dev_priv) < 4) { |
| 3353 | /* pipesrc and dspsize control the size that is scaled from, |
| 3354 | * which should always be the user's requested size. |
| 3355 | */ |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3356 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3357 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3358 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3359 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
| 3360 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
| 3361 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3362 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3363 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3364 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
| 3365 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3366 | } |
| 3367 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3368 | I915_WRITE_FW(reg, dspcntr); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3369 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3370 | 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] | 3371 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3372 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3373 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3374 | dspaddr_offset); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3375 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3376 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3377 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3378 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3379 | dspaddr_offset); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3380 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3381 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3382 | } else { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3383 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3384 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3385 | dspaddr_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3386 | } |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3387 | POSTING_READ_FW(reg); |
| 3388 | |
| 3389 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3392 | static void i9xx_disable_plane(struct intel_plane *plane, |
| 3393 | struct intel_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3394 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3395 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3396 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3397 | unsigned long irqflags; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3398 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3399 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3400 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3401 | I915_WRITE_FW(DSPCNTR(i9xx_plane), 0); |
| 3402 | if (INTEL_GEN(dev_priv) >= 4) |
| 3403 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3404 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3405 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
| 3406 | POSTING_READ_FW(DSPCNTR(i9xx_plane)); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3407 | |
| 3408 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3411 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane, |
| 3412 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3413 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3414 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3415 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3416 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3417 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3418 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3419 | |
| 3420 | /* |
| 3421 | * Not 100% correct for planes that can move between pipes, |
| 3422 | * but that's only the case for gen2-4 which don't have any |
| 3423 | * display power wells. |
| 3424 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3425 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3426 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 3427 | return false; |
| 3428 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3429 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 3430 | |
| 3431 | ret = val & DISPLAY_PLANE_ENABLE; |
| 3432 | |
| 3433 | if (INTEL_GEN(dev_priv) >= 5) |
| 3434 | *pipe = plane->pipe; |
| 3435 | else |
| 3436 | *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 3437 | DISPPLANE_SEL_PIPE_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3438 | |
| 3439 | intel_display_power_put(dev_priv, power_domain); |
| 3440 | |
| 3441 | return ret; |
| 3442 | } |
| 3443 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3444 | static u32 |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3445 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3446 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3447 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3448 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3449 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3450 | return intel_tile_width_bytes(fb, color_plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3453 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3454 | { |
| 3455 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3456 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3457 | |
| 3458 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3459 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3460 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3461 | } |
| 3462 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3463 | /* |
| 3464 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3465 | */ |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3466 | static void skl_detach_scalers(const struct intel_crtc_state *crtc_state) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3467 | { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3468 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3469 | const struct intel_crtc_scaler_state *scaler_state = |
| 3470 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3471 | int i; |
| 3472 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3473 | /* loop through and disable scalers that aren't in use */ |
| 3474 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3475 | if (!scaler_state->scalers[i].in_use) |
| 3476 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3477 | } |
| 3478 | } |
| 3479 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3480 | u32 skl_plane_stride(const struct intel_plane_state *plane_state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3481 | int color_plane) |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3482 | { |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3483 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3484 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3485 | u32 stride = plane_state->color_plane[color_plane].stride; |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3486 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3487 | if (color_plane >= fb->format->num_planes) |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3488 | return 0; |
| 3489 | |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3490 | /* |
| 3491 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3492 | * linear buffers or in number of tiles for tiled buffers. |
| 3493 | */ |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3494 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3495 | stride /= intel_tile_height(fb, color_plane); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3496 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3497 | stride /= intel_fb_stride_alignment(fb, color_plane); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3498 | |
| 3499 | return stride; |
| 3500 | } |
| 3501 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3502 | static u32 skl_plane_ctl_format(uint32_t pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3503 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3504 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3505 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3506 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3507 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3508 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3509 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3510 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3511 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3512 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3513 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3514 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3515 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3516 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3517 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3518 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3519 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3520 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3521 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3522 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3523 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3524 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3525 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3526 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3527 | case DRM_FORMAT_NV12: |
| 3528 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3529 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3530 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3531 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3532 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3533 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3536 | 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] | 3537 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3538 | if (!plane_state->base.fb->format->has_alpha) |
| 3539 | return PLANE_CTL_ALPHA_DISABLE; |
| 3540 | |
| 3541 | switch (plane_state->base.pixel_blend_mode) { |
| 3542 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3543 | return PLANE_CTL_ALPHA_DISABLE; |
| 3544 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3545 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3546 | case DRM_MODE_BLEND_COVERAGE: |
| 3547 | return PLANE_CTL_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3548 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3549 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3550 | return PLANE_CTL_ALPHA_DISABLE; |
| 3551 | } |
| 3552 | } |
| 3553 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3554 | 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] | 3555 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3556 | if (!plane_state->base.fb->format->has_alpha) |
| 3557 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3558 | |
| 3559 | switch (plane_state->base.pixel_blend_mode) { |
| 3560 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3561 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3562 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3563 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3564 | case DRM_MODE_BLEND_COVERAGE: |
| 3565 | return PLANE_COLOR_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3566 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3567 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3568 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3569 | } |
| 3570 | } |
| 3571 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3572 | static u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3573 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3574 | switch (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3575 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3576 | break; |
| 3577 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3578 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3579 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3580 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3581 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3582 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3583 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3584 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3585 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3586 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3587 | default: |
| 3588 | MISSING_CASE(fb_modifier); |
| 3589 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3590 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3591 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3594 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3595 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3596 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3597 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3598 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3599 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3600 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3601 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3602 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3603 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3604 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3605 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3606 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3607 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3608 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3609 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3610 | MISSING_CASE(rotate); |
| 3611 | } |
| 3612 | |
| 3613 | return 0; |
| 3614 | } |
| 3615 | |
| 3616 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3617 | { |
| 3618 | switch (reflect) { |
| 3619 | case 0: |
| 3620 | break; |
| 3621 | case DRM_MODE_REFLECT_X: |
| 3622 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3623 | case DRM_MODE_REFLECT_Y: |
| 3624 | default: |
| 3625 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3628 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3631 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3632 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3633 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3634 | struct drm_i915_private *dev_priv = |
| 3635 | to_i915(plane_state->base.plane->dev); |
| 3636 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3637 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3638 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3639 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3640 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3641 | plane_ctl = PLANE_CTL_ENABLE; |
| 3642 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3643 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3644 | plane_ctl |= skl_plane_ctl_alpha(plane_state); |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3645 | plane_ctl |= |
| 3646 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3647 | PLANE_CTL_PIPE_CSC_ENABLE | |
| 3648 | PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3649 | |
| 3650 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3651 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3652 | |
| 3653 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3654 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3655 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3656 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3657 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3658 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3659 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3660 | |
| 3661 | if (INTEL_GEN(dev_priv) >= 10) |
| 3662 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3663 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3664 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3665 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3666 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3667 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3668 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3669 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3670 | return plane_ctl; |
| 3671 | } |
| 3672 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3673 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3674 | const struct intel_plane_state *plane_state) |
| 3675 | { |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3676 | struct drm_i915_private *dev_priv = |
| 3677 | to_i915(plane_state->base.plane->dev); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3678 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3679 | u32 plane_color_ctl = 0; |
| 3680 | |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3681 | if (INTEL_GEN(dev_priv) < 11) { |
| 3682 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3683 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
| 3684 | } |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3685 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3686 | plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3687 | |
Ayan Kumar Halder | 9bace65 | 2018-07-17 18:13:43 +0100 | [diff] [blame] | 3688 | if (fb->format->is_yuv) { |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3689 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3690 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3691 | else |
| 3692 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3693 | |
| 3694 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3695 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3696 | } |
Ville Syrjälä | 012d79e | 2018-05-21 21:56:12 +0300 | [diff] [blame] | 3697 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3698 | return plane_color_ctl; |
| 3699 | } |
| 3700 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3701 | static int |
| 3702 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3703 | struct drm_atomic_state *state, |
| 3704 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3705 | { |
| 3706 | struct drm_crtc_state *crtc_state; |
| 3707 | struct drm_crtc *crtc; |
| 3708 | int i, ret; |
| 3709 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3710 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3711 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3712 | |
| 3713 | if (!state) |
| 3714 | return 0; |
| 3715 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3716 | /* |
| 3717 | * We've duplicated the state, pointers to the old state are invalid. |
| 3718 | * |
| 3719 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3720 | */ |
| 3721 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3722 | /* |
| 3723 | * Force recalculation even if we restore |
| 3724 | * current state. With fast modeset this may not result |
| 3725 | * in a modeset when the state is compatible. |
| 3726 | */ |
| 3727 | crtc_state->mode_changed = true; |
| 3728 | } |
| 3729 | |
| 3730 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3731 | if (!HAS_GMCH_DISPLAY(to_i915(dev))) |
| 3732 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3733 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3734 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3735 | |
| 3736 | WARN_ON(ret == -EDEADLK); |
| 3737 | return ret; |
| 3738 | } |
| 3739 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3740 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3741 | { |
Ville Syrjälä | ae98104 | 2016-08-05 23:28:30 +0300 | [diff] [blame] | 3742 | return intel_has_gpu_reset(dev_priv) && |
| 3743 | INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3744 | } |
| 3745 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3746 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3747 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3748 | struct drm_device *dev = &dev_priv->drm; |
| 3749 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3750 | struct drm_atomic_state *state; |
| 3751 | int ret; |
| 3752 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3753 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3754 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3755 | !gpu_reset_clobbers_display(dev_priv)) |
| 3756 | return; |
| 3757 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3758 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3759 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3760 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3761 | |
| 3762 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3763 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3764 | i915_gem_set_wedged(dev_priv); |
| 3765 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3766 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3767 | /* |
| 3768 | * Need mode_config.mutex so that we don't |
| 3769 | * trample ongoing ->detect() and whatnot. |
| 3770 | */ |
| 3771 | mutex_lock(&dev->mode_config.mutex); |
| 3772 | drm_modeset_acquire_init(ctx, 0); |
| 3773 | while (1) { |
| 3774 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3775 | if (ret != -EDEADLK) |
| 3776 | break; |
| 3777 | |
| 3778 | drm_modeset_backoff(ctx); |
| 3779 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3780 | /* |
| 3781 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3782 | * g33 docs say we should at least disable all the planes. |
| 3783 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3784 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3785 | if (IS_ERR(state)) { |
| 3786 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3787 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3788 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3792 | if (ret) { |
| 3793 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3794 | drm_atomic_state_put(state); |
| 3795 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | dev_priv->modeset_restore_state = state; |
| 3799 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3800 | } |
| 3801 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3802 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3803 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3804 | struct drm_device *dev = &dev_priv->drm; |
| 3805 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3806 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3807 | int ret; |
| 3808 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3809 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3810 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3811 | return; |
| 3812 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3813 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3814 | if (!state) |
| 3815 | goto unlock; |
| 3816 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3817 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3818 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3819 | /* for testing only restore the display */ |
| 3820 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3821 | if (ret) |
| 3822 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3823 | } else { |
| 3824 | /* |
| 3825 | * The display has been reset as well, |
| 3826 | * so need a full re-initialization. |
| 3827 | */ |
| 3828 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3829 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3830 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3831 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3832 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3833 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3834 | |
| 3835 | spin_lock_irq(&dev_priv->irq_lock); |
| 3836 | if (dev_priv->display.hpd_irq_setup) |
| 3837 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3838 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3839 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3840 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3841 | if (ret) |
| 3842 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3843 | |
| 3844 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3845 | } |
| 3846 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3847 | drm_atomic_state_put(state); |
| 3848 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3849 | drm_modeset_drop_locks(ctx); |
| 3850 | drm_modeset_acquire_fini(ctx); |
| 3851 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3852 | |
| 3853 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3854 | } |
| 3855 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3856 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3857 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3858 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3859 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3860 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3861 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3862 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3863 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3864 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3865 | /* |
| 3866 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3867 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3868 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3869 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3870 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3871 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3872 | */ |
| 3873 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3874 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3875 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3876 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3877 | |
| 3878 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3879 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3880 | skl_detach_scalers(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3881 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3882 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3883 | skylake_pfit_enable(new_crtc_state); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3884 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3885 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3886 | ironlake_pfit_enable(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3887 | else if (old_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3888 | ironlake_pfit_disable(old_crtc_state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3889 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3890 | } |
| 3891 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3892 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3893 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3894 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3895 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3896 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3897 | i915_reg_t reg; |
| 3898 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3899 | |
| 3900 | /* enable normal train */ |
| 3901 | reg = FDI_TX_CTL(pipe); |
| 3902 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3903 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3904 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3905 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3906 | } else { |
| 3907 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3908 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3909 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3910 | I915_WRITE(reg, temp); |
| 3911 | |
| 3912 | reg = FDI_RX_CTL(pipe); |
| 3913 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3914 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3915 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3916 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3917 | } else { |
| 3918 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3919 | temp |= FDI_LINK_TRAIN_NONE; |
| 3920 | } |
| 3921 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3922 | |
| 3923 | /* wait one idle pattern time */ |
| 3924 | POSTING_READ(reg); |
| 3925 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3926 | |
| 3927 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3928 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3929 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3930 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3931 | } |
| 3932 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3933 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3934 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 3935 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3936 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3937 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3938 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3939 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3940 | i915_reg_t reg; |
| 3941 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3942 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3943 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3944 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3945 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3946 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3947 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3948 | reg = FDI_RX_IMR(pipe); |
| 3949 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3950 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3951 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3952 | I915_WRITE(reg, temp); |
| 3953 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3954 | udelay(150); |
| 3955 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3956 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3957 | reg = FDI_TX_CTL(pipe); |
| 3958 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3959 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3960 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3961 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3962 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3963 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3964 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3965 | reg = FDI_RX_CTL(pipe); |
| 3966 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3967 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3968 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3969 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3970 | |
| 3971 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3972 | udelay(150); |
| 3973 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3974 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3975 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3976 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3977 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3978 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3979 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3980 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3981 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3982 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3983 | |
| 3984 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3985 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3986 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3987 | break; |
| 3988 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3989 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3990 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3991 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3992 | |
| 3993 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3994 | reg = FDI_TX_CTL(pipe); |
| 3995 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3996 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3997 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3998 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3999 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4000 | reg = FDI_RX_CTL(pipe); |
| 4001 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4002 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4003 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4004 | I915_WRITE(reg, temp); |
| 4005 | |
| 4006 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4007 | udelay(150); |
| 4008 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4009 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4010 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4011 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4012 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4013 | |
| 4014 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4015 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4016 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4017 | break; |
| 4018 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4019 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4020 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4021 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4022 | |
| 4023 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4024 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4025 | } |
| 4026 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4027 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4028 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 4029 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 4030 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 4031 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 4032 | }; |
| 4033 | |
| 4034 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4035 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
| 4036 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4037 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4038 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4039 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4040 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4041 | i915_reg_t reg; |
| 4042 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4043 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4044 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4045 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4046 | reg = FDI_RX_IMR(pipe); |
| 4047 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4048 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4049 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4050 | I915_WRITE(reg, temp); |
| 4051 | |
| 4052 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4053 | udelay(150); |
| 4054 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4055 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4056 | reg = FDI_TX_CTL(pipe); |
| 4057 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4058 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4059 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4060 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4061 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4062 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4063 | /* SNB-B */ |
| 4064 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4065 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4066 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4067 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4068 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4069 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4070 | reg = FDI_RX_CTL(pipe); |
| 4071 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4072 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4073 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4074 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4075 | } else { |
| 4076 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4077 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4078 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4079 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4080 | |
| 4081 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4082 | udelay(150); |
| 4083 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4084 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4085 | reg = FDI_TX_CTL(pipe); |
| 4086 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4087 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4088 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4089 | I915_WRITE(reg, temp); |
| 4090 | |
| 4091 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4092 | udelay(500); |
| 4093 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4094 | for (retry = 0; retry < 5; retry++) { |
| 4095 | reg = FDI_RX_IIR(pipe); |
| 4096 | temp = I915_READ(reg); |
| 4097 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4098 | if (temp & FDI_RX_BIT_LOCK) { |
| 4099 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4100 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4101 | break; |
| 4102 | } |
| 4103 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4104 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4105 | if (retry < 5) |
| 4106 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4107 | } |
| 4108 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4109 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4110 | |
| 4111 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4112 | reg = FDI_TX_CTL(pipe); |
| 4113 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4114 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4115 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4116 | if (IS_GEN6(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4117 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4118 | /* SNB-B */ |
| 4119 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4120 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4121 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4122 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4123 | reg = FDI_RX_CTL(pipe); |
| 4124 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4125 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4126 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4127 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4128 | } else { |
| 4129 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4130 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4131 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4132 | I915_WRITE(reg, temp); |
| 4133 | |
| 4134 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4135 | udelay(150); |
| 4136 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4137 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4138 | reg = FDI_TX_CTL(pipe); |
| 4139 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4140 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4141 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4142 | I915_WRITE(reg, temp); |
| 4143 | |
| 4144 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4145 | udelay(500); |
| 4146 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4147 | for (retry = 0; retry < 5; retry++) { |
| 4148 | reg = FDI_RX_IIR(pipe); |
| 4149 | temp = I915_READ(reg); |
| 4150 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4151 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4152 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4153 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4154 | break; |
| 4155 | } |
| 4156 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4157 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4158 | if (retry < 5) |
| 4159 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4160 | } |
| 4161 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4162 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4163 | |
| 4164 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4165 | } |
| 4166 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4167 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4168 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4169 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4170 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4171 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4172 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4173 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4174 | i915_reg_t reg; |
| 4175 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4176 | |
| 4177 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4178 | for train result */ |
| 4179 | reg = FDI_RX_IMR(pipe); |
| 4180 | temp = I915_READ(reg); |
| 4181 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4182 | temp &= ~FDI_RX_BIT_LOCK; |
| 4183 | I915_WRITE(reg, temp); |
| 4184 | |
| 4185 | POSTING_READ(reg); |
| 4186 | udelay(150); |
| 4187 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4188 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4189 | I915_READ(FDI_RX_IIR(pipe))); |
| 4190 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4191 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4192 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4193 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4194 | reg = FDI_TX_CTL(pipe); |
| 4195 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4196 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4197 | temp &= ~FDI_TX_ENABLE; |
| 4198 | I915_WRITE(reg, temp); |
| 4199 | |
| 4200 | reg = FDI_RX_CTL(pipe); |
| 4201 | temp = I915_READ(reg); |
| 4202 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4203 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4204 | temp &= ~FDI_RX_ENABLE; |
| 4205 | I915_WRITE(reg, temp); |
| 4206 | |
| 4207 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4208 | reg = FDI_TX_CTL(pipe); |
| 4209 | temp = I915_READ(reg); |
| 4210 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4211 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4212 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4213 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4214 | temp |= snb_b_fdi_train_param[j/2]; |
| 4215 | temp |= FDI_COMPOSITE_SYNC; |
| 4216 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4217 | |
| 4218 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4219 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4220 | |
| 4221 | reg = FDI_RX_CTL(pipe); |
| 4222 | temp = I915_READ(reg); |
| 4223 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4224 | temp |= FDI_COMPOSITE_SYNC; |
| 4225 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4226 | |
| 4227 | POSTING_READ(reg); |
| 4228 | udelay(1); /* should be 0.5us */ |
| 4229 | |
| 4230 | for (i = 0; i < 4; i++) { |
| 4231 | reg = FDI_RX_IIR(pipe); |
| 4232 | temp = I915_READ(reg); |
| 4233 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4234 | |
| 4235 | if (temp & FDI_RX_BIT_LOCK || |
| 4236 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4237 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4238 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4239 | i); |
| 4240 | break; |
| 4241 | } |
| 4242 | udelay(1); /* should be 0.5us */ |
| 4243 | } |
| 4244 | if (i == 4) { |
| 4245 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4246 | continue; |
| 4247 | } |
| 4248 | |
| 4249 | /* Train 2 */ |
| 4250 | reg = FDI_TX_CTL(pipe); |
| 4251 | temp = I915_READ(reg); |
| 4252 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4253 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4254 | I915_WRITE(reg, temp); |
| 4255 | |
| 4256 | reg = FDI_RX_CTL(pipe); |
| 4257 | temp = I915_READ(reg); |
| 4258 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4259 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4260 | I915_WRITE(reg, temp); |
| 4261 | |
| 4262 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4263 | udelay(2); /* should be 1.5us */ |
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 | for (i = 0; i < 4; i++) { |
| 4266 | reg = FDI_RX_IIR(pipe); |
| 4267 | temp = I915_READ(reg); |
| 4268 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4269 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4270 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4271 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4272 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4273 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4274 | i); |
| 4275 | goto train_done; |
| 4276 | } |
| 4277 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4278 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4279 | if (i == 4) |
| 4280 | 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] | 4281 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4282 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4283 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4284 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4285 | } |
| 4286 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4287 | 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] | 4288 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4289 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4290 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4291 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4292 | i915_reg_t reg; |
| 4293 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4294 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4295 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4296 | reg = FDI_RX_CTL(pipe); |
| 4297 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4298 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4299 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4300 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4301 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4302 | |
| 4303 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4304 | udelay(200); |
| 4305 | |
| 4306 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4307 | temp = I915_READ(reg); |
| 4308 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4309 | |
| 4310 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4311 | udelay(200); |
| 4312 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4313 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4314 | reg = FDI_TX_CTL(pipe); |
| 4315 | temp = I915_READ(reg); |
| 4316 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4317 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4318 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4319 | POSTING_READ(reg); |
| 4320 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4321 | } |
| 4322 | } |
| 4323 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4324 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4325 | { |
| 4326 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4327 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4328 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4329 | i915_reg_t reg; |
| 4330 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4331 | |
| 4332 | /* Switch from PCDclk to Rawclk */ |
| 4333 | reg = FDI_RX_CTL(pipe); |
| 4334 | temp = I915_READ(reg); |
| 4335 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4336 | |
| 4337 | /* Disable CPU FDI TX PLL */ |
| 4338 | reg = FDI_TX_CTL(pipe); |
| 4339 | temp = I915_READ(reg); |
| 4340 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4341 | |
| 4342 | POSTING_READ(reg); |
| 4343 | udelay(100); |
| 4344 | |
| 4345 | reg = FDI_RX_CTL(pipe); |
| 4346 | temp = I915_READ(reg); |
| 4347 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4348 | |
| 4349 | /* Wait for the clocks to turn off. */ |
| 4350 | POSTING_READ(reg); |
| 4351 | udelay(100); |
| 4352 | } |
| 4353 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4354 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4355 | { |
| 4356 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4357 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4358 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4359 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4360 | i915_reg_t reg; |
| 4361 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4362 | |
| 4363 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4364 | reg = FDI_TX_CTL(pipe); |
| 4365 | temp = I915_READ(reg); |
| 4366 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4367 | POSTING_READ(reg); |
| 4368 | |
| 4369 | reg = FDI_RX_CTL(pipe); |
| 4370 | temp = I915_READ(reg); |
| 4371 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4372 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4373 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4374 | |
| 4375 | POSTING_READ(reg); |
| 4376 | udelay(100); |
| 4377 | |
| 4378 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4379 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4380 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4381 | |
| 4382 | /* still set train pattern 1 */ |
| 4383 | reg = FDI_TX_CTL(pipe); |
| 4384 | temp = I915_READ(reg); |
| 4385 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4386 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4387 | I915_WRITE(reg, temp); |
| 4388 | |
| 4389 | reg = FDI_RX_CTL(pipe); |
| 4390 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4391 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4392 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4393 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4394 | } else { |
| 4395 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4396 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4397 | } |
| 4398 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4399 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4400 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4401 | I915_WRITE(reg, temp); |
| 4402 | |
| 4403 | POSTING_READ(reg); |
| 4404 | udelay(100); |
| 4405 | } |
| 4406 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4407 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4408 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4409 | struct drm_crtc *crtc; |
| 4410 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4411 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4412 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4413 | struct drm_crtc_commit *commit; |
| 4414 | spin_lock(&crtc->commit_lock); |
| 4415 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4416 | struct drm_crtc_commit, commit_entry); |
| 4417 | cleanup_done = commit ? |
| 4418 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4419 | spin_unlock(&crtc->commit_lock); |
| 4420 | |
| 4421 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4422 | continue; |
| 4423 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4424 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4425 | |
| 4426 | return true; |
| 4427 | } |
| 4428 | |
| 4429 | return false; |
| 4430 | } |
| 4431 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4432 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4433 | { |
| 4434 | u32 temp; |
| 4435 | |
| 4436 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4437 | |
| 4438 | mutex_lock(&dev_priv->sb_lock); |
| 4439 | |
| 4440 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4441 | temp |= SBI_SSCCTL_DISABLE; |
| 4442 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4443 | |
| 4444 | mutex_unlock(&dev_priv->sb_lock); |
| 4445 | } |
| 4446 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4447 | /* Program iCLKIP clock to the desired frequency */ |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4448 | static void lpt_program_iclkip(struct intel_crtc *crtc) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4449 | { |
Ander Conselvan de Oliveira | 0dcdc38 | 2017-03-02 14:58:52 +0200 | [diff] [blame] | 4450 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4451 | int clock = crtc->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4452 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4453 | u32 temp; |
| 4454 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4455 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4456 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4457 | /* The iCLK virtual clock root frequency is in MHz, |
| 4458 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4459 | * divisors, it is necessary to divide one by another, so we |
| 4460 | * convert the virtual clock precision to KHz here for higher |
| 4461 | * precision. |
| 4462 | */ |
| 4463 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4464 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4465 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4466 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4467 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4468 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4469 | clock << auxdiv); |
| 4470 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4471 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4472 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4473 | /* |
| 4474 | * Near 20MHz is a corner case which is |
| 4475 | * out of range for the 7-bit divisor |
| 4476 | */ |
| 4477 | if (divsel <= 0x7f) |
| 4478 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | /* This should not happen with any sane values */ |
| 4482 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4483 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4484 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4485 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4486 | |
| 4487 | 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] | 4488 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4489 | auxdiv, |
| 4490 | divsel, |
| 4491 | phasedir, |
| 4492 | phaseinc); |
| 4493 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4494 | mutex_lock(&dev_priv->sb_lock); |
| 4495 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4496 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4497 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4498 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4499 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4500 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4501 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4502 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4503 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4504 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4505 | |
| 4506 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4507 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4508 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4509 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4510 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4511 | |
| 4512 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4513 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4514 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4515 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4516 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4517 | mutex_unlock(&dev_priv->sb_lock); |
| 4518 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4519 | /* Wait for initialization time */ |
| 4520 | udelay(24); |
| 4521 | |
| 4522 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4523 | } |
| 4524 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4525 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4526 | { |
| 4527 | u32 divsel, phaseinc, auxdiv; |
| 4528 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4529 | u32 iclk_pi_range = 64; |
| 4530 | u32 desired_divisor; |
| 4531 | u32 temp; |
| 4532 | |
| 4533 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4534 | return 0; |
| 4535 | |
| 4536 | mutex_lock(&dev_priv->sb_lock); |
| 4537 | |
| 4538 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4539 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4540 | mutex_unlock(&dev_priv->sb_lock); |
| 4541 | return 0; |
| 4542 | } |
| 4543 | |
| 4544 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4545 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4546 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4547 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4548 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4549 | |
| 4550 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4551 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4552 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4553 | |
| 4554 | mutex_unlock(&dev_priv->sb_lock); |
| 4555 | |
| 4556 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4557 | |
| 4558 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4559 | desired_divisor << auxdiv); |
| 4560 | } |
| 4561 | |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4562 | 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] | 4563 | enum pipe pch_transcoder) |
| 4564 | { |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4565 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4566 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4567 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4568 | |
| 4569 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4570 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4571 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4572 | I915_READ(HBLANK(cpu_transcoder))); |
| 4573 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4574 | I915_READ(HSYNC(cpu_transcoder))); |
| 4575 | |
| 4576 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4577 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4578 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4579 | I915_READ(VBLANK(cpu_transcoder))); |
| 4580 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4581 | I915_READ(VSYNC(cpu_transcoder))); |
| 4582 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4583 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4584 | } |
| 4585 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4586 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4587 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4588 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4589 | uint32_t temp; |
| 4590 | |
| 4591 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4592 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4593 | return; |
| 4594 | |
| 4595 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4596 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4597 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4598 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4599 | if (enable) |
| 4600 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4601 | |
| 4602 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4603 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4604 | POSTING_READ(SOUTH_CHICKEN1); |
| 4605 | } |
| 4606 | |
| 4607 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4608 | { |
| 4609 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4610 | |
| 4611 | switch (intel_crtc->pipe) { |
| 4612 | case PIPE_A: |
| 4613 | break; |
| 4614 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4615 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4616 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4617 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4618 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4619 | |
| 4620 | break; |
| 4621 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4622 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4623 | |
| 4624 | break; |
| 4625 | default: |
| 4626 | BUG(); |
| 4627 | } |
| 4628 | } |
| 4629 | |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4630 | /* |
| 4631 | * Finds the encoder associated with the given CRTC. This can only be |
| 4632 | * used when we know that the CRTC isn't feeding multiple encoders! |
| 4633 | */ |
| 4634 | static struct intel_encoder * |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4635 | intel_get_crtc_new_encoder(const struct intel_atomic_state *state, |
| 4636 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4637 | { |
| 4638 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4639 | const struct drm_connector_state *connector_state; |
| 4640 | const struct drm_connector *connector; |
| 4641 | struct intel_encoder *encoder = NULL; |
| 4642 | int num_encoders = 0; |
| 4643 | int i; |
| 4644 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4645 | 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] | 4646 | if (connector_state->crtc != &crtc->base) |
| 4647 | continue; |
| 4648 | |
| 4649 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 4650 | num_encoders++; |
| 4651 | } |
| 4652 | |
| 4653 | WARN(num_encoders != 1, "%d encoders for pipe %c\n", |
| 4654 | num_encoders, pipe_name(crtc->pipe)); |
| 4655 | |
| 4656 | return encoder; |
| 4657 | } |
| 4658 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4659 | /* |
| 4660 | * Enable PCH resources required for PCH ports: |
| 4661 | * - PCH PLLs |
| 4662 | * - FDI training & RX/TX |
| 4663 | * - update transcoder timings |
| 4664 | * - DP transcoding bits |
| 4665 | * - transcoder |
| 4666 | */ |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4667 | static void ironlake_pch_enable(const struct intel_atomic_state *state, |
| 4668 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4669 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4670 | 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] | 4671 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4672 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4673 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4674 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4675 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4676 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4677 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4678 | if (IS_IVYBRIDGE(dev_priv)) |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4679 | ivybridge_update_fdi_bc_bifurcation(crtc); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4680 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4681 | /* Write the TU size bits before fdi link training, so that error |
| 4682 | * detection works. */ |
| 4683 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4684 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4685 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4686 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4687 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4688 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4689 | /* We need to program the right clock selection before writing the pixel |
| 4690 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4691 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4692 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4693 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4694 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4695 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4696 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4697 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4698 | 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] | 4699 | temp |= sel; |
| 4700 | else |
| 4701 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4702 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4703 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4704 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4705 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4706 | * transcoder, and we actually should do this to not upset any PCH |
| 4707 | * transcoder that already use the clock when we share it. |
| 4708 | * |
| 4709 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4710 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4711 | * the right LVDS enable sequence. */ |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 4712 | intel_enable_shared_dpll(crtc_state); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4713 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4714 | /* set transcoder timing, panel must allow it */ |
| 4715 | assert_panel_unlocked(dev_priv, pipe); |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4716 | ironlake_pch_transcoder_set_timings(crtc_state, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4717 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4718 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4719 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4720 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4721 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4722 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4723 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4724 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4725 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4726 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4727 | enum port port; |
| 4728 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4729 | temp = I915_READ(reg); |
| 4730 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4731 | TRANS_DP_SYNC_MASK | |
| 4732 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4733 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4734 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4735 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4736 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4737 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4738 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4739 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4740 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4741 | port = intel_get_crtc_new_encoder(state, crtc_state)->port; |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4742 | WARN_ON(port < PORT_B || port > PORT_D); |
| 4743 | temp |= TRANS_DP_PORT_SEL(port); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4744 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4745 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 4748 | ironlake_enable_pch_transcoder(crtc_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4749 | } |
| 4750 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4751 | static void lpt_pch_enable(const struct intel_atomic_state *state, |
| 4752 | const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4753 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4754 | 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] | 4755 | 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] | 4756 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4757 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4758 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4759 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4760 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4761 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4762 | /* Set transcoder timing. */ |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4763 | ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4764 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4765 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4766 | } |
| 4767 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4768 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4769 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4770 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4771 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4772 | u32 temp; |
| 4773 | |
| 4774 | temp = I915_READ(dslreg); |
| 4775 | udelay(500); |
| 4776 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4777 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4778 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4779 | } |
| 4780 | } |
| 4781 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4782 | /* |
| 4783 | * The hardware phase 0.0 refers to the center of the pixel. |
| 4784 | * We want to start from the top/left edge which is phase |
| 4785 | * -0.5. That matches how the hardware calculates the scaling |
| 4786 | * factors (from top-left of the first pixel to bottom-right |
| 4787 | * of the last pixel, as opposed to the pixel centers). |
| 4788 | * |
| 4789 | * For 4:2:0 subsampled chroma planes we obviously have to |
| 4790 | * adjust that so that the chroma sample position lands in |
| 4791 | * the right spot. |
| 4792 | * |
| 4793 | * Note that for packed YCbCr 4:2:2 formats there is no way to |
| 4794 | * control chroma siting. The hardware simply replicates the |
| 4795 | * chroma samples for both of the luma samples, and thus we don't |
| 4796 | * actually get the expected MPEG2 chroma siting convention :( |
| 4797 | * The same behaviour is observed on pre-SKL platforms as well. |
| 4798 | */ |
| 4799 | u16 skl_scaler_calc_phase(int sub, bool chroma_cosited) |
| 4800 | { |
| 4801 | int phase = -0x8000; |
| 4802 | u16 trip = 0; |
| 4803 | |
| 4804 | if (chroma_cosited) |
| 4805 | phase += (sub - 1) * 0x8000 / sub; |
| 4806 | |
| 4807 | if (phase < 0) |
| 4808 | phase = 0x10000 + phase; |
| 4809 | else |
| 4810 | trip = PS_PHASE_TRIP; |
| 4811 | |
| 4812 | return ((phase >> 2) & PS_PHASE_MASK) | trip; |
| 4813 | } |
| 4814 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4815 | static int |
| 4816 | 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] | 4817 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4818 | int src_w, int src_h, int dst_w, int dst_h, |
| 4819 | bool plane_scaler_check, |
| 4820 | uint32_t pixel_format) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4821 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4822 | struct intel_crtc_scaler_state *scaler_state = |
| 4823 | &crtc_state->scaler_state; |
| 4824 | struct intel_crtc *intel_crtc = |
| 4825 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4826 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4827 | const struct drm_display_mode *adjusted_mode = |
| 4828 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4829 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4830 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4831 | /* |
| 4832 | * Src coordinates are already rotated by 270 degrees for |
| 4833 | * the 90/270 degree plane rotation cases (to match the |
| 4834 | * GTT mapping), hence no need to account for rotation here. |
| 4835 | */ |
| 4836 | need_scaling = src_w != dst_w || src_h != dst_h; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4837 | |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4838 | if (plane_scaler_check) |
| 4839 | if (pixel_format == DRM_FORMAT_NV12) |
| 4840 | need_scaling = true; |
| 4841 | |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 4842 | if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX) |
| 4843 | need_scaling = true; |
| 4844 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4845 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4846 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 4847 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 4848 | * Once NV12 is enabled, handle it here while allocating scaler |
| 4849 | * for NV12. |
| 4850 | */ |
| 4851 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
| 4852 | need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 4853 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 4854 | return -EINVAL; |
| 4855 | } |
| 4856 | |
| 4857 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4858 | * if plane is being disabled or scaler is no more required or force detach |
| 4859 | * - free scaler binded to this plane/crtc |
| 4860 | * - in order to do this, update crtc->scaler_usage |
| 4861 | * |
| 4862 | * Here scaler state in crtc_state is set free so that |
| 4863 | * scaler can be assigned to other user. Actual register |
| 4864 | * update to free the scaler is done in plane/panel-fit programming. |
| 4865 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4866 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4867 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4868 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4869 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4870 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4871 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4872 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4873 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4874 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4875 | scaler_state->scaler_users); |
| 4876 | *scaler_id = -1; |
| 4877 | } |
| 4878 | return 0; |
| 4879 | } |
| 4880 | |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4881 | if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 4882 | (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] | 4883 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 4884 | return -EINVAL; |
| 4885 | } |
| 4886 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4887 | /* range checks */ |
| 4888 | 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] | 4889 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4890 | (IS_GEN11(dev_priv) && |
| 4891 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 4892 | dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) || |
| 4893 | (!IS_GEN11(dev_priv) && |
| 4894 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4895 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4896 | 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] | 4897 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4898 | 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] | 4899 | return -EINVAL; |
| 4900 | } |
| 4901 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4902 | /* mark this plane as a scaler user in crtc_state */ |
| 4903 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4904 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4905 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4906 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4907 | scaler_state->scaler_users); |
| 4908 | |
| 4909 | return 0; |
| 4910 | } |
| 4911 | |
| 4912 | /** |
| 4913 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4914 | * |
| 4915 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4916 | * |
| 4917 | * Return |
| 4918 | * 0 - scaler_usage updated successfully |
| 4919 | * error - requested scaling cannot be supported or other error condition |
| 4920 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4921 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4922 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4923 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4924 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4925 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4926 | &state->scaler_state.scaler_id, |
| 4927 | state->pipe_src_w, state->pipe_src_h, |
| 4928 | adjusted_mode->crtc_hdisplay, |
| 4929 | adjusted_mode->crtc_vdisplay, false, 0); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | /** |
| 4933 | * 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] | 4934 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4935 | * @plane_state: atomic plane state to update |
| 4936 | * |
| 4937 | * Return |
| 4938 | * 0 - scaler_usage updated successfully |
| 4939 | * error - requested scaling cannot be supported or other error condition |
| 4940 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4941 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4942 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4943 | { |
| 4944 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4945 | struct intel_plane *intel_plane = |
| 4946 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4947 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4948 | int ret; |
| 4949 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4950 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4951 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4952 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4953 | drm_plane_index(&intel_plane->base), |
| 4954 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4955 | drm_rect_width(&plane_state->base.src) >> 16, |
| 4956 | drm_rect_height(&plane_state->base.src) >> 16, |
| 4957 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4958 | drm_rect_height(&plane_state->base.dst), |
| 4959 | fb ? true : false, fb ? fb->format->format : 0); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4960 | |
| 4961 | if (ret || plane_state->scaler_id < 0) |
| 4962 | return ret; |
| 4963 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4964 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 4965 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4966 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 4967 | intel_plane->base.base.id, |
| 4968 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4969 | return -EINVAL; |
| 4970 | } |
| 4971 | |
| 4972 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4973 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4974 | case DRM_FORMAT_RGB565: |
| 4975 | case DRM_FORMAT_XBGR8888: |
| 4976 | case DRM_FORMAT_XRGB8888: |
| 4977 | case DRM_FORMAT_ABGR8888: |
| 4978 | case DRM_FORMAT_ARGB8888: |
| 4979 | case DRM_FORMAT_XRGB2101010: |
| 4980 | case DRM_FORMAT_XBGR2101010: |
| 4981 | case DRM_FORMAT_YUYV: |
| 4982 | case DRM_FORMAT_YVYU: |
| 4983 | case DRM_FORMAT_UYVY: |
| 4984 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4985 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4986 | break; |
| 4987 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4988 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 4989 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 4990 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4991 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4994 | return 0; |
| 4995 | } |
| 4996 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4997 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4998 | { |
| 4999 | int i; |
| 5000 | |
| 5001 | for (i = 0; i < crtc->num_scalers; i++) |
| 5002 | skl_detach_scaler(crtc, i); |
| 5003 | } |
| 5004 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5005 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5006 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5007 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5008 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5009 | enum pipe pipe = crtc->pipe; |
| 5010 | const struct intel_crtc_scaler_state *scaler_state = |
| 5011 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5012 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5013 | if (crtc_state->pch_pfit.enabled) { |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5014 | u16 uv_rgb_hphase, uv_rgb_vphase; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5015 | int id; |
| 5016 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5017 | if (WARN_ON(crtc_state->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5018 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5019 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5020 | uv_rgb_hphase = skl_scaler_calc_phase(1, false); |
| 5021 | uv_rgb_vphase = skl_scaler_calc_phase(1, false); |
| 5022 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5023 | id = scaler_state->scaler_id; |
| 5024 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 5025 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5026 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, id), |
| 5027 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase)); |
| 5028 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, id), |
| 5029 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase)); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5030 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos); |
| 5031 | 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] | 5032 | } |
| 5033 | } |
| 5034 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5035 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5036 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5037 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5038 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5039 | int pipe = crtc->pipe; |
| 5040 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5041 | if (crtc_state->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5042 | /* Force use of hard-coded filter coefficients |
| 5043 | * as some pre-programmed values are broken, |
| 5044 | * e.g. x201. |
| 5045 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5046 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5047 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 5048 | PF_PIPE_SEL_IVB(pipe)); |
| 5049 | else |
| 5050 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5051 | I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos); |
| 5052 | I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 5053 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5054 | } |
| 5055 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5056 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5057 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5058 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 5059 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5060 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5061 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5062 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5063 | return; |
| 5064 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 5065 | /* |
| 5066 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 5067 | * This function is called from post_plane_update, which is run after |
| 5068 | * a vblank wait. |
| 5069 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5070 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 5071 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5072 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5073 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 5074 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 5075 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5076 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5077 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 5078 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5079 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 5080 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5081 | */ |
| 5082 | } else { |
| 5083 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 5084 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 5085 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5086 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5087 | * the HW state readout code will complain that the expected |
| 5088 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5089 | if (intel_wait_for_register(dev_priv, |
| 5090 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5091 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5092 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5093 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5094 | } |
| 5095 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5096 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5097 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5098 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5099 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5100 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5101 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5102 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5103 | return; |
| 5104 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5105 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5106 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5107 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5108 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5109 | /* |
| 5110 | * Wait for PCODE to finish disabling IPS. The BSpec specified |
| 5111 | * 42ms timeout value leads to occasional timeouts so use 100ms |
| 5112 | * instead. |
| 5113 | */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5114 | if (intel_wait_for_register(dev_priv, |
| 5115 | IPS_CTL, IPS_ENABLE, 0, |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5116 | 100)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5117 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5118 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5119 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5120 | POSTING_READ(IPS_CTL); |
| 5121 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5122 | |
| 5123 | /* 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] | 5124 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5125 | } |
| 5126 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5127 | 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] | 5128 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5129 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5130 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5131 | |
| 5132 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5133 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5134 | mutex_unlock(&dev->struct_mutex); |
| 5135 | } |
| 5136 | |
| 5137 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5138 | * has to recompute where to put it anyway. |
| 5139 | */ |
| 5140 | } |
| 5141 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5142 | /** |
| 5143 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5144 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5145 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5146 | * |
| 5147 | * Performs potentially sleeping operations that must be done after the primary |
| 5148 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5149 | * called due to an explicit primary plane update, or due to an implicit |
| 5150 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5151 | * completely hide the primary plane. |
| 5152 | */ |
| 5153 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5154 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5155 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5156 | { |
| 5157 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5158 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5159 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5160 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5161 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5162 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5163 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5164 | * So don't enable underrun reporting before at least some planes |
| 5165 | * are enabled. |
| 5166 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5167 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5168 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5169 | if (IS_GEN2(dev_priv)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5170 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5171 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5172 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5173 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5174 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5175 | } |
| 5176 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5177 | /* FIXME get rid of this and use pre_plane_update */ |
| 5178 | static void |
| 5179 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5180 | { |
| 5181 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5182 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5183 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5184 | int pipe = intel_crtc->pipe; |
| 5185 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5186 | /* |
| 5187 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5188 | * So disable underrun reporting before all the planes get disabled. |
| 5189 | */ |
| 5190 | if (IS_GEN2(dev_priv)) |
| 5191 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5192 | |
| 5193 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5194 | |
| 5195 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5196 | * Vblank time updates from the shadow to live plane control register |
| 5197 | * are blocked if the memory self-refresh mode is active at that |
| 5198 | * moment. So to make sure the plane gets truly disabled, disable |
| 5199 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5200 | * will be checked/applied by the HW only at the next frame start |
| 5201 | * event which is after the vblank start event, so we need to have a |
| 5202 | * wait-for-vblank between disabling the plane and the pipe. |
| 5203 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5204 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 5205 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5206 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5207 | } |
| 5208 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5209 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5210 | const struct intel_crtc_state *new_crtc_state) |
| 5211 | { |
| 5212 | if (!old_crtc_state->ips_enabled) |
| 5213 | return false; |
| 5214 | |
| 5215 | if (needs_modeset(&new_crtc_state->base)) |
| 5216 | return true; |
| 5217 | |
| 5218 | return !new_crtc_state->ips_enabled; |
| 5219 | } |
| 5220 | |
| 5221 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5222 | const struct intel_crtc_state *new_crtc_state) |
| 5223 | { |
| 5224 | if (!new_crtc_state->ips_enabled) |
| 5225 | return false; |
| 5226 | |
| 5227 | if (needs_modeset(&new_crtc_state->base)) |
| 5228 | return true; |
| 5229 | |
| 5230 | /* |
| 5231 | * We can't read out IPS on broadwell, assume the worst and |
| 5232 | * forcibly enable IPS on the first fastset. |
| 5233 | */ |
| 5234 | if (new_crtc_state->update_pipe && |
| 5235 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5236 | return true; |
| 5237 | |
| 5238 | return !old_crtc_state->ips_enabled; |
| 5239 | } |
| 5240 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5241 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5242 | const struct intel_crtc_state *crtc_state) |
| 5243 | { |
| 5244 | if (!crtc_state->nv12_planes) |
| 5245 | return false; |
| 5246 | |
| 5247 | if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv)) |
| 5248 | return false; |
| 5249 | |
| 5250 | if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) || |
| 5251 | IS_CANNONLAKE(dev_priv)) |
| 5252 | return true; |
| 5253 | |
| 5254 | return false; |
| 5255 | } |
| 5256 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5257 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5258 | { |
| 5259 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5260 | struct drm_device *dev = crtc->base.dev; |
| 5261 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5262 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5263 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5264 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5265 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5266 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5267 | struct drm_plane_state *old_primary_state = |
| 5268 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5269 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5270 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5271 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5272 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5273 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5274 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5275 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5276 | hsw_enable_ips(pipe_config); |
| 5277 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5278 | if (old_primary_state) { |
| 5279 | struct drm_plane_state *new_primary_state = |
| 5280 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5281 | |
| 5282 | intel_fbc_post_update(crtc); |
| 5283 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5284 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5285 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5286 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5287 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5288 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5289 | |
| 5290 | /* Display WA 827 */ |
| 5291 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5292 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5293 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5294 | skl_wa_528(dev_priv, crtc->pipe, false); |
| 5295 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5296 | } |
| 5297 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5298 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5299 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5300 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5301 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5302 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5303 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5304 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5305 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5306 | struct drm_plane_state *old_primary_state = |
| 5307 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5308 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5309 | struct intel_atomic_state *old_intel_state = |
| 5310 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5311 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5312 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5313 | hsw_disable_ips(old_crtc_state); |
| 5314 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5315 | if (old_primary_state) { |
| 5316 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5317 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5318 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5319 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5320 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5321 | /* |
| 5322 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5323 | * So disable underrun reporting before all the planes get disabled. |
| 5324 | */ |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5325 | if (IS_GEN2(dev_priv) && old_primary_state->visible && |
| 5326 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5327 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5328 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5329 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5330 | /* Display WA 827 */ |
| 5331 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5332 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5333 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5334 | skl_wa_528(dev_priv, crtc->pipe, true); |
| 5335 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5336 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5337 | /* |
| 5338 | * Vblank time updates from the shadow to live plane control register |
| 5339 | * are blocked if the memory self-refresh mode is active at that |
| 5340 | * moment. So to make sure the plane gets truly disabled, disable |
| 5341 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5342 | * will be checked/applied by the HW only at the next frame start |
| 5343 | * event which is after the vblank start event, so we need to have a |
| 5344 | * wait-for-vblank between disabling the plane and the pipe. |
| 5345 | */ |
| 5346 | if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active && |
| 5347 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5348 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5349 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5350 | /* |
| 5351 | * IVB workaround: must disable low power watermarks for at least |
| 5352 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5353 | * when scaling is disabled. |
| 5354 | * |
| 5355 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5356 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 5357 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) && |
| 5358 | old_crtc_state->base.active) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5359 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5360 | |
| 5361 | /* |
| 5362 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5363 | * watermark programming here. |
| 5364 | */ |
| 5365 | if (needs_modeset(&pipe_config->base)) |
| 5366 | return; |
| 5367 | |
| 5368 | /* |
| 5369 | * For platforms that support atomic watermarks, program the |
| 5370 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5371 | * will be the intermediate values that are safe for both pre- and |
| 5372 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5373 | * to the final 'target' values and we'll do this again to get the |
| 5374 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5375 | * will be the final target values which will get automatically latched |
| 5376 | * at vblank time; no further programming will be necessary. |
| 5377 | * |
| 5378 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5379 | * we'll continue to update watermarks the old way, if flags tell |
| 5380 | * us to. |
| 5381 | */ |
| 5382 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5383 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5384 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5385 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5386 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5387 | } |
| 5388 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5389 | 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] | 5390 | { |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5391 | struct drm_device *dev = crtc->base.dev; |
| 5392 | struct intel_plane *plane; |
| 5393 | unsigned fb_bits = 0; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5394 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5395 | intel_crtc_dpms_overlay_disable(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5396 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5397 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 5398 | if (plane_mask & BIT(plane->id)) { |
| 5399 | plane->disable_plane(plane, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5400 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5401 | fb_bits |= plane->frontbuffer_bit; |
| 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | intel_frontbuffer_flip(to_i915(dev), fb_bits); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5406 | } |
| 5407 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5408 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5409 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5410 | struct drm_atomic_state *old_state) |
| 5411 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5412 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5413 | struct drm_connector *conn; |
| 5414 | int i; |
| 5415 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5416 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5417 | struct intel_encoder *encoder = |
| 5418 | to_intel_encoder(conn_state->best_encoder); |
| 5419 | |
| 5420 | if (conn_state->crtc != crtc) |
| 5421 | continue; |
| 5422 | |
| 5423 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5424 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | |
| 5428 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5429 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5430 | struct drm_atomic_state *old_state) |
| 5431 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5432 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5433 | struct drm_connector *conn; |
| 5434 | int i; |
| 5435 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5436 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5437 | struct intel_encoder *encoder = |
| 5438 | to_intel_encoder(conn_state->best_encoder); |
| 5439 | |
| 5440 | if (conn_state->crtc != crtc) |
| 5441 | continue; |
| 5442 | |
| 5443 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5444 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5445 | } |
| 5446 | } |
| 5447 | |
| 5448 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5449 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5450 | struct drm_atomic_state *old_state) |
| 5451 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5452 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5453 | struct drm_connector *conn; |
| 5454 | int i; |
| 5455 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5456 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5457 | struct intel_encoder *encoder = |
| 5458 | to_intel_encoder(conn_state->best_encoder); |
| 5459 | |
| 5460 | if (conn_state->crtc != crtc) |
| 5461 | continue; |
| 5462 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5463 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5464 | intel_opregion_notify_encoder(encoder, true); |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | static void intel_encoders_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 | intel_opregion_notify_encoder(encoder, false); |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5484 | encoder->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_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_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5504 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5509 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5510 | struct drm_atomic_state *old_state) |
| 5511 | { |
| 5512 | struct drm_connector_state *old_conn_state; |
| 5513 | struct drm_connector *conn; |
| 5514 | int i; |
| 5515 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5516 | 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] | 5517 | struct intel_encoder *encoder = |
| 5518 | to_intel_encoder(old_conn_state->best_encoder); |
| 5519 | |
| 5520 | if (old_conn_state->crtc != crtc) |
| 5521 | continue; |
| 5522 | |
| 5523 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5524 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5525 | } |
| 5526 | } |
| 5527 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5528 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5529 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5530 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5531 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5532 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5533 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5534 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5535 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5536 | struct intel_atomic_state *old_intel_state = |
| 5537 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5538 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5539 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5540 | return; |
| 5541 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5542 | /* |
| 5543 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5544 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5545 | * |
| 5546 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5547 | * between eDP port A enable and vdd enable. Also PCH port |
| 5548 | * enable seems to result in the occasional CPU pipe underrun. |
| 5549 | * |
| 5550 | * Spurious PCH underruns also occur during PCH enabling. |
| 5551 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5552 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5553 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5554 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5555 | if (pipe_config->has_pch_encoder) |
| 5556 | intel_prepare_shared_dpll(pipe_config); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5557 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5558 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5559 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5560 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5561 | intel_set_pipe_timings(pipe_config); |
| 5562 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5563 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5564 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5565 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5566 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5567 | } |
| 5568 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5569 | ironlake_set_pipeconf(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5570 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5571 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5572 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5573 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5574 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5575 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5576 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5577 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5578 | * enabling. */ |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 5579 | ironlake_fdi_pll_enable(pipe_config); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5580 | } else { |
| 5581 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5582 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5583 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5584 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5585 | ironlake_pfit_enable(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5586 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5587 | /* |
| 5588 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5589 | * clocks enabled |
| 5590 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5591 | intel_color_load_luts(&pipe_config->base); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5592 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5593 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5594 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5595 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5596 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5597 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5598 | ironlake_pch_enable(old_intel_state, pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5599 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5600 | assert_vblank_disabled(crtc); |
| 5601 | drm_crtc_vblank_on(crtc); |
| 5602 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5603 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5604 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5605 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5606 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5607 | |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5608 | /* |
| 5609 | * Must wait for vblank to avoid spurious PCH FIFO underruns. |
| 5610 | * And a second vblank wait is needed at least on ILK with |
| 5611 | * some interlaced HDMI modes. Let's do the double wait always |
| 5612 | * in case there are more corner cases we don't know about. |
| 5613 | */ |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5614 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5615 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5616 | intel_wait_for_vblank(dev_priv, pipe); |
| 5617 | } |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5618 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5619 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5620 | } |
| 5621 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5622 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5623 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5624 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5625 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5626 | } |
| 5627 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5628 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5629 | enum pipe pipe, bool apply) |
| 5630 | { |
| 5631 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5632 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5633 | |
| 5634 | if (apply) |
| 5635 | val |= mask; |
| 5636 | else |
| 5637 | val &= ~mask; |
| 5638 | |
| 5639 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5640 | } |
| 5641 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5642 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5643 | { |
| 5644 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5645 | enum pipe pipe = crtc->pipe; |
| 5646 | uint32_t val; |
| 5647 | |
Rodrigo Vivi | 443d5e3 | 2018-10-04 08:18:14 -0700 | [diff] [blame] | 5648 | val = MBUS_DBOX_A_CREDIT(2); |
| 5649 | val |= MBUS_DBOX_BW_CREDIT(1); |
| 5650 | val |= MBUS_DBOX_B_CREDIT(8); |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5651 | |
| 5652 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5653 | } |
| 5654 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5655 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5656 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5657 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5658 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5659 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5660 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5661 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5662 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5663 | struct intel_atomic_state *old_intel_state = |
| 5664 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5665 | bool psl_clkgate_wa; |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5666 | u32 pipe_chicken; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5667 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5668 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5669 | return; |
| 5670 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5671 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5672 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5673 | if (pipe_config->shared_dpll) |
| 5674 | intel_enable_shared_dpll(pipe_config); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5675 | |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5676 | if (INTEL_GEN(dev_priv) >= 11) |
| 5677 | icl_map_plls_to_ports(crtc, pipe_config, old_state); |
| 5678 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame] | 5679 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5680 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5681 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5682 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5683 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5684 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5685 | intel_set_pipe_timings(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5686 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5687 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5688 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5689 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5690 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5691 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5692 | pipe_config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5693 | } |
| 5694 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5695 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5696 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5697 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5698 | } |
| 5699 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5700 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5701 | haswell_set_pipeconf(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5702 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5703 | haswell_set_pipemisc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5704 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5705 | intel_color_set_csc(&pipe_config->base); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5706 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5707 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5708 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5709 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5710 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5711 | pipe_config->pch_pfit.enabled; |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5712 | if (psl_clkgate_wa) |
| 5713 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5714 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5715 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5716 | skylake_pfit_enable(pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5717 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5718 | ironlake_pfit_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5719 | |
| 5720 | /* |
| 5721 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5722 | * clocks enabled |
| 5723 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5724 | intel_color_load_luts(&pipe_config->base); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5725 | |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5726 | /* |
| 5727 | * Display WA #1153: enable hardware to bypass the alpha math |
| 5728 | * and rounding for per-pixel values 00 and 0xff |
| 5729 | */ |
| 5730 | if (INTEL_GEN(dev_priv) >= 11) { |
| 5731 | pipe_chicken = I915_READ(PIPE_CHICKEN(pipe)); |
| 5732 | if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN)) |
| 5733 | I915_WRITE_FW(PIPE_CHICKEN(pipe), |
| 5734 | pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN); |
| 5735 | } |
| 5736 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5737 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5738 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5739 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5740 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5741 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5742 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5743 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5744 | if (INTEL_GEN(dev_priv) >= 11) |
| 5745 | icl_pipe_mbus_enable(intel_crtc); |
| 5746 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5747 | /* 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] | 5748 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5749 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5750 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5751 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5752 | lpt_pch_enable(old_intel_state, pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5753 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5754 | 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] | 5755 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5756 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5757 | assert_vblank_disabled(crtc); |
| 5758 | drm_crtc_vblank_on(crtc); |
| 5759 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5760 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5761 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5762 | if (psl_clkgate_wa) { |
| 5763 | intel_wait_for_vblank(dev_priv, pipe); |
| 5764 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5765 | } |
| 5766 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5767 | /* If we change the relative order between pipe/planes enabling, we need |
| 5768 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5769 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5770 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5771 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5772 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5773 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5774 | } |
| 5775 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5776 | 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] | 5777 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5778 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5779 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5780 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5781 | |
| 5782 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5783 | * 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] | 5784 | if (old_crtc_state->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5785 | I915_WRITE(PF_CTL(pipe), 0); |
| 5786 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5787 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5788 | } |
| 5789 | } |
| 5790 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5791 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5792 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5793 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5794 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5795 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5796 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5797 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5798 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5799 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5800 | /* |
| 5801 | * Sometimes spurious CPU pipe underruns happen when the |
| 5802 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 5803 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 5804 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5805 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5806 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5807 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5808 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5809 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5810 | drm_crtc_vblank_off(crtc); |
| 5811 | assert_vblank_disabled(crtc); |
| 5812 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5813 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5814 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5815 | ironlake_pfit_disable(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5816 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5817 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 5818 | ironlake_fdi_disable(crtc); |
| 5819 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5820 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5821 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5822 | if (old_crtc_state->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5823 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5824 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5825 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5826 | i915_reg_t reg; |
| 5827 | u32 temp; |
| 5828 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5829 | /* disable TRANS_DP_CTL */ |
| 5830 | reg = TRANS_DP_CTL(pipe); |
| 5831 | temp = I915_READ(reg); |
| 5832 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5833 | TRANS_DP_PORT_SEL_MASK); |
| 5834 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5835 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5836 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5837 | /* disable DPLL_SEL */ |
| 5838 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5839 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5840 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5841 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5842 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5843 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5844 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5845 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5846 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5847 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5850 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5851 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5852 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5853 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5854 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5855 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5856 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
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_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5859 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5860 | drm_crtc_vblank_off(crtc); |
| 5861 | assert_vblank_disabled(crtc); |
| 5862 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5863 | /* 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] | 5864 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5865 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5866 | |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5867 | if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) |
| 5868 | intel_ddi_set_vc_payload_alloc(old_crtc_state, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5869 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5870 | if (!transcoder_is_dsi(cpu_transcoder)) |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 5871 | intel_ddi_disable_transcoder_func(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5872 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5873 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5874 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5875 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5876 | ironlake_pfit_disable(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5877 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5878 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5879 | |
| 5880 | if (INTEL_GEN(dev_priv) >= 11) |
| 5881 | icl_unmap_plls_to_ports(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5882 | } |
| 5883 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5884 | static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5885 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5886 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5887 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5888 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5889 | if (!crtc_state->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5890 | return; |
| 5891 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5892 | /* |
| 5893 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5894 | * according to register description and PRM. |
| 5895 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5896 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5897 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5898 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5899 | I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios); |
| 5900 | I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5901 | |
| 5902 | /* Border color in case we don't scale up to the full screen. Black by |
| 5903 | * default, change to something else for debugging. */ |
| 5904 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
Paulo Zanoni | ac213c1 | 2018-05-21 17:25:37 -0700 | [diff] [blame] | 5907 | bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5908 | { |
| 5909 | if (IS_ICELAKE(dev_priv)) |
| 5910 | return port >= PORT_C && port <= PORT_F; |
| 5911 | |
| 5912 | return false; |
| 5913 | } |
| 5914 | |
| 5915 | enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5916 | { |
| 5917 | if (!intel_port_is_tc(dev_priv, port)) |
| 5918 | return PORT_TC_NONE; |
| 5919 | |
| 5920 | return port - PORT_C; |
| 5921 | } |
| 5922 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 5923 | 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] | 5924 | { |
| 5925 | switch (port) { |
| 5926 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5927 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5928 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5929 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5930 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5931 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5932 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5933 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5934 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5935 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 5936 | case PORT_F: |
| 5937 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5938 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5939 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5940 | return POWER_DOMAIN_PORT_OTHER; |
| 5941 | } |
| 5942 | } |
| 5943 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5944 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 5945 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5946 | { |
| 5947 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5948 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5949 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5950 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5951 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5952 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5953 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5954 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5955 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5956 | return 0; |
| 5957 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 5958 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 5959 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5960 | if (crtc_state->pch_pfit.enabled || |
| 5961 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5962 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5963 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5964 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5965 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5966 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 5967 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5968 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5969 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5970 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 5971 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 5972 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5973 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5974 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5975 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5976 | return mask; |
| 5977 | } |
| 5978 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 5979 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5980 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5981 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5982 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5983 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5984 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5985 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 5986 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5987 | |
| 5988 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5989 | intel_crtc->enabled_power_domains = new_domains = |
| 5990 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5991 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5992 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5993 | |
| 5994 | for_each_power_domain(domain, domains) |
| 5995 | intel_display_power_get(dev_priv, domain); |
| 5996 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5997 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | 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] | 6001 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6002 | { |
| 6003 | enum intel_display_power_domain domain; |
| 6004 | |
| 6005 | for_each_power_domain(domain, domains) |
| 6006 | intel_display_power_put(dev_priv, domain); |
| 6007 | } |
| 6008 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6009 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6010 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6011 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6012 | struct intel_atomic_state *old_intel_state = |
| 6013 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6014 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6015 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6016 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6017 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6018 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6019 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6020 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6021 | return; |
| 6022 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6023 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6024 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6025 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6026 | intel_set_pipe_timings(pipe_config); |
| 6027 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6028 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6029 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6030 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6031 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6032 | } |
| 6033 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6034 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6035 | |
P Raviraj Sitaram | c59d2da | 2018-09-10 19:57:14 +0530 | [diff] [blame] | 6036 | intel_color_set_csc(&pipe_config->base); |
| 6037 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6038 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6039 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6040 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6041 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6042 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6043 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6044 | if (IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6045 | chv_prepare_pll(intel_crtc, pipe_config); |
| 6046 | chv_enable_pll(intel_crtc, pipe_config); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6047 | } else { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6048 | vlv_prepare_pll(intel_crtc, pipe_config); |
| 6049 | vlv_enable_pll(intel_crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6050 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6051 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6052 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6053 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6054 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6055 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6056 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6057 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6058 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6059 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6060 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6061 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6062 | assert_vblank_disabled(crtc); |
| 6063 | drm_crtc_vblank_on(crtc); |
| 6064 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6065 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6066 | } |
| 6067 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6068 | 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] | 6069 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6070 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6071 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6072 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6073 | I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0); |
| 6074 | I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6075 | } |
| 6076 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6077 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6078 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6079 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6080 | struct intel_atomic_state *old_intel_state = |
| 6081 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6082 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6083 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6084 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6085 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6086 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6087 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6088 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6089 | return; |
| 6090 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6091 | i9xx_set_pll_dividers(pipe_config); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6092 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6093 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6094 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6095 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6096 | intel_set_pipe_timings(pipe_config); |
| 6097 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6098 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6099 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6100 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6101 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6102 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6103 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6104 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6105 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6106 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6107 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 6108 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6109 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6110 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6111 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6112 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6113 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6114 | if (dev_priv->display.initial_watermarks != NULL) |
| 6115 | dev_priv->display.initial_watermarks(old_intel_state, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6116 | pipe_config); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6117 | else |
| 6118 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6119 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6120 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6121 | assert_vblank_disabled(crtc); |
| 6122 | drm_crtc_vblank_on(crtc); |
| 6123 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6124 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6125 | } |
| 6126 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6127 | 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] | 6128 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6129 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 6130 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6131 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6132 | if (!old_crtc_state->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6133 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6134 | |
| 6135 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6136 | |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 6137 | DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n", |
| 6138 | I915_READ(PFIT_CONTROL)); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6139 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6140 | } |
| 6141 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6142 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6143 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6144 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6145 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6146 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6147 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6148 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6149 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6150 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6151 | /* |
| 6152 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6153 | * wait for planes to fully turn off before disabling the pipe. |
| 6154 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6155 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6156 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6157 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6158 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6159 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6160 | drm_crtc_vblank_off(crtc); |
| 6161 | assert_vblank_disabled(crtc); |
| 6162 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6163 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6164 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6165 | i9xx_pfit_disable(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6166 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6167 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6168 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6169 | if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6170 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6171 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6172 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6173 | vlv_disable_pll(dev_priv, pipe); |
| 6174 | else |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6175 | i9xx_disable_pll(old_crtc_state); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6176 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6177 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6178 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6179 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6180 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6181 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6182 | |
| 6183 | if (!dev_priv->display.initial_watermarks) |
| 6184 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6185 | |
| 6186 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6187 | if (IS_I830(dev_priv)) |
| 6188 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6189 | } |
| 6190 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6191 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6192 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6193 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6194 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6195 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6196 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6197 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6198 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6199 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6200 | struct drm_atomic_state *state; |
| 6201 | struct intel_crtc_state *crtc_state; |
| 6202 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6203 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6204 | if (!intel_crtc->active) |
| 6205 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6206 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6207 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6208 | const struct intel_plane_state *plane_state = |
| 6209 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6210 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6211 | if (plane_state->base.visible) |
| 6212 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6213 | } |
| 6214 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6215 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6216 | if (!state) { |
| 6217 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6218 | crtc->base.id, crtc->name); |
| 6219 | return; |
| 6220 | } |
| 6221 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6222 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6223 | |
| 6224 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6225 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6226 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6227 | |
| 6228 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6229 | |
| 6230 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6231 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6232 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6233 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6234 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6235 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6236 | |
| 6237 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6238 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6239 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6240 | crtc->enabled = false; |
| 6241 | crtc->state->connector_mask = 0; |
| 6242 | crtc->state->encoder_mask = 0; |
| 6243 | |
| 6244 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6245 | encoder->base.crtc = NULL; |
| 6246 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6247 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6248 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 6249 | intel_disable_shared_dpll(to_intel_crtc_state(crtc->state)); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6250 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6251 | domains = intel_crtc->enabled_power_domains; |
| 6252 | for_each_power_domain(domain, domains) |
| 6253 | intel_display_power_put(dev_priv, domain); |
| 6254 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6255 | |
| 6256 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6257 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6258 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6259 | } |
| 6260 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6261 | /* |
| 6262 | * turn all crtc's off, but do not adjust state |
| 6263 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6264 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6265 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6266 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6267 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6268 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6269 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6270 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6271 | state = drm_atomic_helper_suspend(dev); |
| 6272 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6273 | if (ret) |
| 6274 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6275 | else |
| 6276 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6277 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6278 | } |
| 6279 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6280 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6281 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6282 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6283 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6284 | drm_encoder_cleanup(encoder); |
| 6285 | kfree(intel_encoder); |
| 6286 | } |
| 6287 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6288 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6289 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6290 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6291 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6292 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6293 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6294 | |
| 6295 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6296 | connector->base.base.id, |
| 6297 | connector->base.name); |
| 6298 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6299 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6300 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6301 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6302 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6303 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6304 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6305 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6306 | return; |
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 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6309 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6310 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6311 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6312 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6313 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6314 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6315 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6316 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6317 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6318 | "attached encoder crtc differs from connector crtc\n"); |
| 6319 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6320 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6321 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6322 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6323 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6324 | } |
| 6325 | } |
| 6326 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6327 | int intel_connector_init(struct intel_connector *connector) |
| 6328 | { |
Maarten Lankhorst | 11c1a9e | 2017-05-01 15:37:57 +0200 | [diff] [blame] | 6329 | struct intel_digital_connector_state *conn_state; |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6330 | |
Maarten Lankhorst | 11c1a9e | 2017-05-01 15:37:57 +0200 | [diff] [blame] | 6331 | /* |
| 6332 | * Allocate enough memory to hold intel_digital_connector_state, |
| 6333 | * This might be a few bytes too many, but for connectors that don't |
| 6334 | * need it we'll free the state and allocate a smaller one on the first |
| 6335 | * succesful commit anyway. |
| 6336 | */ |
| 6337 | conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL); |
| 6338 | if (!conn_state) |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6339 | return -ENOMEM; |
| 6340 | |
Maarten Lankhorst | 11c1a9e | 2017-05-01 15:37:57 +0200 | [diff] [blame] | 6341 | __drm_atomic_helper_connector_reset(&connector->base, |
| 6342 | &conn_state->base); |
| 6343 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6344 | return 0; |
| 6345 | } |
| 6346 | |
| 6347 | struct intel_connector *intel_connector_alloc(void) |
| 6348 | { |
| 6349 | struct intel_connector *connector; |
| 6350 | |
| 6351 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6352 | if (!connector) |
| 6353 | return NULL; |
| 6354 | |
| 6355 | if (intel_connector_init(connector) < 0) { |
| 6356 | kfree(connector); |
| 6357 | return NULL; |
| 6358 | } |
| 6359 | |
| 6360 | return connector; |
| 6361 | } |
| 6362 | |
James Ausmus | 091a4f9 | 2017-10-13 11:01:44 -0700 | [diff] [blame] | 6363 | /* |
| 6364 | * Free the bits allocated by intel_connector_alloc. |
| 6365 | * This should only be used after intel_connector_alloc has returned |
| 6366 | * successfully, and before drm_connector_init returns successfully. |
| 6367 | * Otherwise the destroy callbacks for the connector and the state should |
| 6368 | * take care of proper cleanup/free |
| 6369 | */ |
| 6370 | void intel_connector_free(struct intel_connector *connector) |
| 6371 | { |
| 6372 | kfree(to_intel_digital_connector_state(connector->base.state)); |
| 6373 | kfree(connector); |
| 6374 | } |
| 6375 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6376 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6377 | * one connector and no cloning and hence the encoder state determines the state |
| 6378 | * of the connector. */ |
| 6379 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6380 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6381 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6382 | struct intel_encoder *encoder = connector->encoder; |
| 6383 | |
| 6384 | return encoder->get_hw_state(encoder, &pipe); |
| 6385 | } |
| 6386 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6387 | 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] | 6388 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6389 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6390 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6391 | |
| 6392 | return 0; |
| 6393 | } |
| 6394 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6395 | 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] | 6396 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6397 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6398 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6399 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6400 | struct intel_crtc *other_crtc; |
| 6401 | struct intel_crtc_state *other_crtc_state; |
| 6402 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6403 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6404 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6405 | if (pipe_config->fdi_lanes > 4) { |
| 6406 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6407 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6408 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6409 | } |
| 6410 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6411 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6412 | if (pipe_config->fdi_lanes > 2) { |
| 6413 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6414 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6415 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6416 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6417 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6418 | } |
| 6419 | } |
| 6420 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6421 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6422 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6423 | |
| 6424 | /* Ivybridge 3 pipe is really complicated */ |
| 6425 | switch (pipe) { |
| 6426 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6427 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6428 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6429 | if (pipe_config->fdi_lanes <= 2) |
| 6430 | return 0; |
| 6431 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6432 | 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] | 6433 | other_crtc_state = |
| 6434 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6435 | if (IS_ERR(other_crtc_state)) |
| 6436 | return PTR_ERR(other_crtc_state); |
| 6437 | |
| 6438 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6439 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6440 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6441 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6442 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6443 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6444 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6445 | if (pipe_config->fdi_lanes > 2) { |
| 6446 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6447 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6448 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6449 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6450 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6451 | 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] | 6452 | other_crtc_state = |
| 6453 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6454 | if (IS_ERR(other_crtc_state)) |
| 6455 | return PTR_ERR(other_crtc_state); |
| 6456 | |
| 6457 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6458 | 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] | 6459 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6460 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6461 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6462 | default: |
| 6463 | BUG(); |
| 6464 | } |
| 6465 | } |
| 6466 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6467 | #define RETRY 1 |
| 6468 | 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] | 6469 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6470 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6471 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6472 | 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] | 6473 | int lane, link_bw, fdi_dotclock, ret; |
| 6474 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6475 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6476 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6477 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6478 | * each output octet as 10 bits. The actual frequency |
| 6479 | * is stored as a divider into a 100MHz clock, and the |
| 6480 | * mode pixel clock is stored in units of 1KHz. |
| 6481 | * Hence the bw of each lane in terms of the mode signal |
| 6482 | * is: |
| 6483 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6484 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6485 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6486 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6487 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6488 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6489 | pipe_config->pipe_bpp); |
| 6490 | |
| 6491 | pipe_config->fdi_lanes = lane; |
| 6492 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6493 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6494 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6495 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6496 | 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] | 6497 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6498 | pipe_config->pipe_bpp -= 2*3; |
| 6499 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6500 | pipe_config->pipe_bpp); |
| 6501 | needs_recompute = true; |
| 6502 | pipe_config->bw_constrained = true; |
| 6503 | |
| 6504 | goto retry; |
| 6505 | } |
| 6506 | |
| 6507 | if (needs_recompute) |
| 6508 | return RETRY; |
| 6509 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6510 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6511 | } |
| 6512 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6513 | 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] | 6514 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6515 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6516 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6517 | |
| 6518 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6519 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6520 | return false; |
| 6521 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6522 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6523 | return false; |
| 6524 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6525 | if (crtc_state->pipe_bpp > 24) |
| 6526 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6527 | |
| 6528 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6529 | * We compare against max which means we must take |
| 6530 | * the increased cdclk requirement into account when |
| 6531 | * calculating the new cdclk. |
| 6532 | * |
| 6533 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6534 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6535 | if (IS_BROADWELL(dev_priv) && |
| 6536 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6537 | return false; |
| 6538 | |
| 6539 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6540 | } |
| 6541 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6542 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6543 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6544 | struct drm_i915_private *dev_priv = |
| 6545 | to_i915(crtc_state->base.crtc->dev); |
| 6546 | struct intel_atomic_state *intel_state = |
| 6547 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6548 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6549 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6550 | return false; |
| 6551 | |
| 6552 | if (crtc_state->ips_force_disable) |
| 6553 | return false; |
| 6554 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6555 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6556 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6557 | return false; |
| 6558 | |
| 6559 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6560 | if (IS_BROADWELL(dev_priv) && |
| 6561 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6562 | return false; |
| 6563 | |
| 6564 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6565 | } |
| 6566 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6567 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6568 | { |
| 6569 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6570 | |
| 6571 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6572 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6573 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6574 | } |
| 6575 | |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6576 | static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
| 6577 | { |
| 6578 | uint32_t pixel_rate; |
| 6579 | |
| 6580 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6581 | |
| 6582 | /* |
| 6583 | * We only use IF-ID interlacing. If we ever use |
| 6584 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6585 | */ |
| 6586 | |
| 6587 | if (pipe_config->pch_pfit.enabled) { |
| 6588 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; |
| 6589 | uint32_t pfit_size = pipe_config->pch_pfit.size; |
| 6590 | |
| 6591 | pipe_w = pipe_config->pipe_src_w; |
| 6592 | pipe_h = pipe_config->pipe_src_h; |
| 6593 | |
| 6594 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6595 | pfit_h = pfit_size & 0xFFFF; |
| 6596 | if (pipe_w < pfit_w) |
| 6597 | pipe_w = pfit_w; |
| 6598 | if (pipe_h < pfit_h) |
| 6599 | pipe_h = pfit_h; |
| 6600 | |
| 6601 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6602 | return pixel_rate; |
| 6603 | |
| 6604 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, |
| 6605 | pfit_w * pfit_h); |
| 6606 | } |
| 6607 | |
| 6608 | return pixel_rate; |
| 6609 | } |
| 6610 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6611 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6612 | { |
| 6613 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6614 | |
| 6615 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 6616 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6617 | crtc_state->pixel_rate = |
| 6618 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6619 | else |
| 6620 | crtc_state->pixel_rate = |
| 6621 | ilk_pipe_pixel_rate(crtc_state); |
| 6622 | } |
| 6623 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6624 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6625 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6626 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6627 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6628 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6629 | 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] | 6630 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6631 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6632 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6633 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6634 | |
| 6635 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6636 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6637 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6638 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6639 | if (intel_crtc_supports_double_wide(crtc) && |
| 6640 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6641 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6642 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6643 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6644 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6645 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6646 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6647 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6648 | adjusted_mode->crtc_clock, clock_limit, |
| 6649 | yesno(pipe_config->double_wide)); |
| 6650 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6651 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6652 | |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6653 | if (pipe_config->ycbcr420 && pipe_config->base.ctm) { |
| 6654 | /* |
| 6655 | * There is only one pipe CSC unit per pipe, and we need that |
| 6656 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6657 | * applied we can't support YCBCR420 output. |
| 6658 | */ |
| 6659 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6660 | return -EINVAL; |
| 6661 | } |
| 6662 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6663 | /* |
| 6664 | * Pipe horizontal size must be even in: |
| 6665 | * - DVO ganged mode |
| 6666 | * - LVDS dual channel mode |
| 6667 | * - Double wide pipe |
| 6668 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6669 | if (pipe_config->pipe_src_w & 1) { |
| 6670 | if (pipe_config->double_wide) { |
| 6671 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6672 | return -EINVAL; |
| 6673 | } |
| 6674 | |
| 6675 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6676 | intel_is_dual_link_lvds(dev)) { |
| 6677 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6678 | return -EINVAL; |
| 6679 | } |
| 6680 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6681 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6682 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6683 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6684 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6685 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6686 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6687 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6688 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6689 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6690 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6691 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6692 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6693 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6694 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6695 | } |
| 6696 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6697 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6698 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6699 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6700 | while (*num > DATA_LINK_M_N_MASK || |
| 6701 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6702 | *num >>= 1; |
| 6703 | *den >>= 1; |
| 6704 | } |
| 6705 | } |
| 6706 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6707 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6708 | uint32_t *ret_m, uint32_t *ret_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6709 | bool constant_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6710 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6711 | /* |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6712 | * Several DP dongles in particular seem to be fussy about |
| 6713 | * too large link M/N values. Give N value as 0x8000 that |
| 6714 | * should be acceptable by specific devices. 0x8000 is the |
| 6715 | * specified fixed N value for asynchronous clock mode, |
| 6716 | * which the devices expect also in synchronous clock mode. |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6717 | */ |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6718 | if (constant_n) |
| 6719 | *ret_n = 0x8000; |
| 6720 | else |
| 6721 | *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] | 6722 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6723 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6724 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6725 | } |
| 6726 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6727 | void |
| 6728 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 6729 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6730 | struct intel_link_m_n *m_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6731 | bool constant_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6732 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6733 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6734 | |
| 6735 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6736 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6737 | &m_n->gmch_m, &m_n->gmch_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6738 | constant_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6739 | |
| 6740 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6741 | &m_n->link_m, &m_n->link_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6742 | constant_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6743 | } |
| 6744 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6745 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6746 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6747 | if (i915_modparams.panel_use_ssc >= 0) |
| 6748 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6749 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6750 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6751 | } |
| 6752 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6753 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6754 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6755 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6756 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6757 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6758 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6759 | { |
| 6760 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6761 | } |
| 6762 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6763 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6764 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6765 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6766 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6767 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6768 | u32 fp, fp2 = 0; |
| 6769 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6770 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6771 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6772 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6773 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6774 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6775 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6776 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6777 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6778 | } |
| 6779 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6780 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6781 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6782 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6783 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6784 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6785 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6786 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6787 | } |
| 6788 | } |
| 6789 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6790 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6791 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6792 | { |
| 6793 | u32 reg_val; |
| 6794 | |
| 6795 | /* |
| 6796 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6797 | * and set it to a reasonable value instead. |
| 6798 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6799 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6800 | reg_val &= 0xffffff00; |
| 6801 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6802 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6803 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6804 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 6805 | reg_val &= 0x00ffffff; |
| 6806 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6807 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6808 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6809 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6810 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6811 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6812 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6813 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6814 | reg_val &= 0x00ffffff; |
| 6815 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6816 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6817 | } |
| 6818 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6819 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 6820 | struct intel_link_m_n *m_n) |
| 6821 | { |
| 6822 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6823 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6824 | int pipe = crtc->pipe; |
| 6825 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6826 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6827 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6828 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6829 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6830 | } |
| 6831 | |
| 6832 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6833 | struct intel_link_m_n *m_n, |
| 6834 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6835 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6836 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6837 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6838 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6839 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6840 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6841 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6842 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6843 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6844 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6845 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 6846 | * for gen < 8) and if DRRS is supported (to make sure the |
| 6847 | * registers are not unnecessarily accessed). |
| 6848 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6849 | if (m2_n2 && (IS_CHERRYVIEW(dev_priv) || |
| 6850 | INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6851 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6852 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6853 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6854 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6855 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6856 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6857 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6858 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6859 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6860 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6861 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6862 | } |
| 6863 | } |
| 6864 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6865 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6866 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6867 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 6868 | |
| 6869 | if (m_n == M1_N1) { |
| 6870 | dp_m_n = &crtc->config->dp_m_n; |
| 6871 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 6872 | } else if (m_n == M2_N2) { |
| 6873 | |
| 6874 | /* |
| 6875 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6876 | * needs to be programmed into M1_N1. |
| 6877 | */ |
| 6878 | dp_m_n = &crtc->config->dp_m2_n2; |
| 6879 | } else { |
| 6880 | DRM_ERROR("Unsupported divider value\n"); |
| 6881 | return; |
| 6882 | } |
| 6883 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6884 | if (crtc->config->has_pch_encoder) |
| 6885 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6886 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6887 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6888 | } |
| 6889 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 6890 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 6891 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6892 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6893 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6894 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6895 | if (crtc->pipe != PIPE_A) |
| 6896 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6897 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6898 | /* 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] | 6899 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6900 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 6901 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 6902 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6903 | pipe_config->dpll_hw_state.dpll_md = |
| 6904 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 6905 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6906 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6907 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 6908 | struct intel_crtc_state *pipe_config) |
| 6909 | { |
| 6910 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6911 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6912 | if (crtc->pipe != PIPE_A) |
| 6913 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6914 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6915 | /* 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] | 6916 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6917 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 6918 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6919 | pipe_config->dpll_hw_state.dpll_md = |
| 6920 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6921 | } |
| 6922 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6923 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6924 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6925 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6926 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6927 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6928 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6929 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6930 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6931 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6932 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6933 | /* Enable Refclk */ |
| 6934 | I915_WRITE(DPLL(pipe), |
| 6935 | pipe_config->dpll_hw_state.dpll & |
| 6936 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 6937 | |
| 6938 | /* No need to actually set up the DPLL with DSI */ |
| 6939 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 6940 | return; |
| 6941 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6942 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6943 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6944 | bestn = pipe_config->dpll.n; |
| 6945 | bestm1 = pipe_config->dpll.m1; |
| 6946 | bestm2 = pipe_config->dpll.m2; |
| 6947 | bestp1 = pipe_config->dpll.p1; |
| 6948 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6949 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6950 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6951 | |
| 6952 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6953 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6954 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6955 | |
| 6956 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6957 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6958 | |
| 6959 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6960 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6961 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6962 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6963 | |
| 6964 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6965 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6966 | |
| 6967 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6968 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6969 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6970 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6971 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6972 | |
| 6973 | /* |
| 6974 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6975 | * but we don't support that). |
| 6976 | * Note: don't use the DAC post divider as it seems unstable. |
| 6977 | */ |
| 6978 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6979 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6980 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6981 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6982 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6983 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6984 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6985 | if (pipe_config->port_clock == 162000 || |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6986 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) || |
| 6987 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6988 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6989 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6990 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6991 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6992 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6993 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 6994 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6995 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6996 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6997 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6998 | 0x0df40000); |
| 6999 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7000 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7001 | 0x0df70000); |
| 7002 | } else { /* HDMI or VGA */ |
| 7003 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7004 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7005 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7006 | 0x0df70000); |
| 7007 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7008 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7009 | 0x0df40000); |
| 7010 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7011 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7012 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7013 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ville Syrjälä | 2210ce7 | 2016-06-22 21:57:05 +0300 | [diff] [blame] | 7014 | if (intel_crtc_has_dp_encoder(crtc->config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7015 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7016 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7017 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7018 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7019 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7020 | } |
| 7021 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7022 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7023 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7024 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7025 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7026 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7027 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7028 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7029 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7030 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7031 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7032 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7033 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7034 | /* Enable Refclk and SSC */ |
| 7035 | I915_WRITE(DPLL(pipe), |
| 7036 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7037 | |
| 7038 | /* No need to actually set up the DPLL with DSI */ |
| 7039 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7040 | return; |
| 7041 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7042 | bestn = pipe_config->dpll.n; |
| 7043 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7044 | bestm1 = pipe_config->dpll.m1; |
| 7045 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7046 | bestp1 = pipe_config->dpll.p1; |
| 7047 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7048 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7049 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7050 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7051 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7052 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7053 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7054 | /* p1 and p2 divider */ |
| 7055 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7056 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7057 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7058 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7059 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7060 | |
| 7061 | /* Feedback post-divider - m2 */ |
| 7062 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7063 | |
| 7064 | /* Feedback refclk divider - n and m1 */ |
| 7065 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7066 | DPIO_CHV_M1_DIV_BY_2 | |
| 7067 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7068 | |
| 7069 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7070 | 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] | 7071 | |
| 7072 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7073 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7074 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7075 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7076 | if (bestm2_frac) |
| 7077 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7078 | 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] | 7079 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7080 | /* Program digital lock detect threshold */ |
| 7081 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7082 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7083 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7084 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7085 | if (!bestm2_frac) |
| 7086 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7087 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7088 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7089 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7090 | if (vco == 5400000) { |
| 7091 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7092 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7093 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7094 | tribuf_calcntr = 0x9; |
| 7095 | } else if (vco <= 6200000) { |
| 7096 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7097 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7098 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7099 | tribuf_calcntr = 0x9; |
| 7100 | } else if (vco <= 6480000) { |
| 7101 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7102 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7103 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7104 | tribuf_calcntr = 0x8; |
| 7105 | } else { |
| 7106 | /* Not supported. Apply the same limits as in the max case */ |
| 7107 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7108 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7109 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7110 | tribuf_calcntr = 0; |
| 7111 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7112 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7113 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7114 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7115 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7116 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7117 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7118 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7119 | /* AFC Recal */ |
| 7120 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7121 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7122 | DPIO_AFC_RECAL); |
| 7123 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7124 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7125 | } |
| 7126 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7127 | /** |
| 7128 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7129 | * @dev_priv: i915 private structure |
| 7130 | * @pipe: pipe PLL to enable |
| 7131 | * @dpll: PLL configuration |
| 7132 | * |
| 7133 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7134 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7135 | * be enabled. |
| 7136 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7137 | 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] | 7138 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7139 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7140 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7141 | struct intel_crtc_state *pipe_config; |
| 7142 | |
| 7143 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7144 | if (!pipe_config) |
| 7145 | return -ENOMEM; |
| 7146 | |
| 7147 | pipe_config->base.crtc = &crtc->base; |
| 7148 | pipe_config->pixel_multiplier = 1; |
| 7149 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7150 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7151 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7152 | chv_compute_dpll(crtc, pipe_config); |
| 7153 | chv_prepare_pll(crtc, pipe_config); |
| 7154 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7155 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7156 | vlv_compute_dpll(crtc, pipe_config); |
| 7157 | vlv_prepare_pll(crtc, pipe_config); |
| 7158 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7159 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7160 | |
| 7161 | kfree(pipe_config); |
| 7162 | |
| 7163 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | /** |
| 7167 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7168 | * @dev_priv: i915 private structure |
| 7169 | * @pipe: pipe PLL to disable |
| 7170 | * |
| 7171 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7172 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7173 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7174 | 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] | 7175 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7176 | if (IS_CHERRYVIEW(dev_priv)) |
| 7177 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7178 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7179 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7180 | } |
| 7181 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7182 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7183 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7184 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7185 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7186 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7187 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7188 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7189 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7190 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7191 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7192 | dpll = DPLL_VGA_MODE_DIS; |
| 7193 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7194 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7195 | dpll |= DPLLB_MODE_LVDS; |
| 7196 | else |
| 7197 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7198 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7199 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7200 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7201 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7202 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7203 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7204 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7205 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7206 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7207 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7208 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7209 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7210 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7211 | |
| 7212 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7213 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7214 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7215 | else { |
| 7216 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7217 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7218 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7219 | } |
| 7220 | switch (clock->p2) { |
| 7221 | case 5: |
| 7222 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7223 | break; |
| 7224 | case 7: |
| 7225 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7226 | break; |
| 7227 | case 10: |
| 7228 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7229 | break; |
| 7230 | case 14: |
| 7231 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7232 | break; |
| 7233 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7234 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7235 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7236 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7237 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7238 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7239 | 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] | 7240 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7241 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7242 | else |
| 7243 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7244 | |
| 7245 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7246 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7247 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7248 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7249 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7250 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7251 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7252 | } |
| 7253 | } |
| 7254 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7255 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7256 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7257 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7258 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7259 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7260 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7261 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7262 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7263 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7264 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7265 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7266 | dpll = DPLL_VGA_MODE_DIS; |
| 7267 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7268 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7269 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7270 | } else { |
| 7271 | if (clock->p1 == 2) |
| 7272 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7273 | else |
| 7274 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7275 | if (clock->p2 == 4) |
| 7276 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7277 | } |
| 7278 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7279 | if (!IS_I830(dev_priv) && |
| 7280 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7281 | dpll |= DPLL_DVO_2X_MODE; |
| 7282 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7283 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7284 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7285 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7286 | else |
| 7287 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7288 | |
| 7289 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7290 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7291 | } |
| 7292 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7293 | 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] | 7294 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7295 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7296 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7297 | enum pipe pipe = crtc->pipe; |
| 7298 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 7299 | 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] | 7300 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7301 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7302 | |
| 7303 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7304 | * the hw state checker will get angry at the mismatch. */ |
| 7305 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7306 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7307 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7308 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7309 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7310 | crtc_vtotal -= 1; |
| 7311 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7312 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7313 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7314 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7315 | else |
| 7316 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7317 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7318 | if (vsyncshift < 0) |
| 7319 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7320 | } |
| 7321 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7322 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7323 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7324 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7325 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7326 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7327 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7328 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7329 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7330 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7331 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7332 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7333 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7334 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7335 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7336 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7337 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7338 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7339 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7340 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7341 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7342 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7343 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7344 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7345 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7346 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7347 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7348 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7349 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7350 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7351 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7352 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7353 | } |
| 7354 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7355 | 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] | 7356 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7357 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7358 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7359 | enum pipe pipe = crtc->pipe; |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7360 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7361 | /* pipesrc controls the size that is scaled from, which should |
| 7362 | * always be the user's requested size. |
| 7363 | */ |
| 7364 | I915_WRITE(PIPESRC(pipe), |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7365 | ((crtc_state->pipe_src_w - 1) << 16) | |
| 7366 | (crtc_state->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7367 | } |
| 7368 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7369 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7370 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7371 | { |
| 7372 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7373 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7374 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7375 | uint32_t tmp; |
| 7376 | |
| 7377 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7378 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7379 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7380 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7381 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7382 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7383 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7384 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7385 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7386 | |
| 7387 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7388 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7389 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7390 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7391 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7392 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7393 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7394 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7395 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7396 | |
| 7397 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7398 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7399 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7400 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7401 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7402 | } |
| 7403 | |
| 7404 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7405 | struct intel_crtc_state *pipe_config) |
| 7406 | { |
| 7407 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7408 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7409 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7410 | |
| 7411 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7412 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7413 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7414 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7415 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7416 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7417 | } |
| 7418 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7419 | 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] | 7420 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7421 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7422 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7423 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7424 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7425 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7426 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7427 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7428 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7429 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7430 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7431 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7432 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7433 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7434 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7435 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7436 | |
| 7437 | mode->hsync = drm_mode_hsync(mode); |
| 7438 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7439 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7440 | } |
| 7441 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7442 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7443 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7444 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7445 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7446 | uint32_t pipeconf; |
| 7447 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7448 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7449 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7450 | /* we keep both pipes enabled on 830 */ |
| 7451 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7452 | pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7453 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7454 | if (crtc_state->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7455 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7456 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7457 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7458 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7459 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7460 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7461 | if (crtc_state->dither && crtc_state->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7462 | pipeconf |= PIPECONF_DITHER_EN | |
| 7463 | PIPECONF_DITHER_TYPE_SP; |
| 7464 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7465 | switch (crtc_state->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7466 | case 18: |
| 7467 | pipeconf |= PIPECONF_6BPC; |
| 7468 | break; |
| 7469 | case 24: |
| 7470 | pipeconf |= PIPECONF_8BPC; |
| 7471 | break; |
| 7472 | case 30: |
| 7473 | pipeconf |= PIPECONF_10BPC; |
| 7474 | break; |
| 7475 | default: |
| 7476 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7477 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7478 | } |
| 7479 | } |
| 7480 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7481 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7482 | if (INTEL_GEN(dev_priv) < 4 || |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7483 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7484 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7485 | else |
| 7486 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7487 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7488 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7489 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7490 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7491 | crtc_state->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7492 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7493 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7494 | I915_WRITE(PIPECONF(crtc->pipe), pipeconf); |
| 7495 | POSTING_READ(PIPECONF(crtc->pipe)); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7496 | } |
| 7497 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7498 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7499 | struct intel_crtc_state *crtc_state) |
| 7500 | { |
| 7501 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7502 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7503 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7504 | int refclk = 48000; |
| 7505 | |
| 7506 | memset(&crtc_state->dpll_hw_state, 0, |
| 7507 | sizeof(crtc_state->dpll_hw_state)); |
| 7508 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7509 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7510 | if (intel_panel_use_ssc(dev_priv)) { |
| 7511 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7512 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7513 | } |
| 7514 | |
| 7515 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7516 | } 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] | 7517 | limit = &intel_limits_i8xx_dvo; |
| 7518 | } else { |
| 7519 | limit = &intel_limits_i8xx_dac; |
| 7520 | } |
| 7521 | |
| 7522 | if (!crtc_state->clock_set && |
| 7523 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7524 | refclk, NULL, &crtc_state->dpll)) { |
| 7525 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7526 | return -EINVAL; |
| 7527 | } |
| 7528 | |
| 7529 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7530 | |
| 7531 | return 0; |
| 7532 | } |
| 7533 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7534 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7535 | struct intel_crtc_state *crtc_state) |
| 7536 | { |
| 7537 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7538 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7539 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7540 | int refclk = 96000; |
| 7541 | |
| 7542 | memset(&crtc_state->dpll_hw_state, 0, |
| 7543 | sizeof(crtc_state->dpll_hw_state)); |
| 7544 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7545 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7546 | if (intel_panel_use_ssc(dev_priv)) { |
| 7547 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7548 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7549 | } |
| 7550 | |
| 7551 | if (intel_is_dual_link_lvds(dev)) |
| 7552 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7553 | else |
| 7554 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7555 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7556 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7557 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7558 | } 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] | 7559 | limit = &intel_limits_g4x_sdvo; |
| 7560 | } else { |
| 7561 | /* The option is for other outputs */ |
| 7562 | limit = &intel_limits_i9xx_sdvo; |
| 7563 | } |
| 7564 | |
| 7565 | if (!crtc_state->clock_set && |
| 7566 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7567 | refclk, NULL, &crtc_state->dpll)) { |
| 7568 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7569 | return -EINVAL; |
| 7570 | } |
| 7571 | |
| 7572 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7573 | |
| 7574 | return 0; |
| 7575 | } |
| 7576 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7577 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7578 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7579 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7580 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7581 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7582 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7583 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7584 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7585 | memset(&crtc_state->dpll_hw_state, 0, |
| 7586 | sizeof(crtc_state->dpll_hw_state)); |
| 7587 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7588 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7589 | if (intel_panel_use_ssc(dev_priv)) { |
| 7590 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7591 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7592 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7593 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7594 | limit = &intel_limits_pineview_lvds; |
| 7595 | } else { |
| 7596 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7597 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7598 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7599 | if (!crtc_state->clock_set && |
| 7600 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7601 | refclk, NULL, &crtc_state->dpll)) { |
| 7602 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7603 | return -EINVAL; |
| 7604 | } |
| 7605 | |
| 7606 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7607 | |
| 7608 | return 0; |
| 7609 | } |
| 7610 | |
| 7611 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7612 | struct intel_crtc_state *crtc_state) |
| 7613 | { |
| 7614 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7615 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7616 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7617 | int refclk = 96000; |
| 7618 | |
| 7619 | memset(&crtc_state->dpll_hw_state, 0, |
| 7620 | sizeof(crtc_state->dpll_hw_state)); |
| 7621 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7622 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7623 | if (intel_panel_use_ssc(dev_priv)) { |
| 7624 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7625 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7626 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7627 | |
| 7628 | limit = &intel_limits_i9xx_lvds; |
| 7629 | } else { |
| 7630 | limit = &intel_limits_i9xx_sdvo; |
| 7631 | } |
| 7632 | |
| 7633 | if (!crtc_state->clock_set && |
| 7634 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7635 | refclk, NULL, &crtc_state->dpll)) { |
| 7636 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7637 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7638 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7639 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7640 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7641 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7642 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7643 | } |
| 7644 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7645 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7646 | struct intel_crtc_state *crtc_state) |
| 7647 | { |
| 7648 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7649 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7650 | |
| 7651 | memset(&crtc_state->dpll_hw_state, 0, |
| 7652 | sizeof(crtc_state->dpll_hw_state)); |
| 7653 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7654 | if (!crtc_state->clock_set && |
| 7655 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7656 | refclk, NULL, &crtc_state->dpll)) { |
| 7657 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7658 | return -EINVAL; |
| 7659 | } |
| 7660 | |
| 7661 | chv_compute_dpll(crtc, crtc_state); |
| 7662 | |
| 7663 | return 0; |
| 7664 | } |
| 7665 | |
| 7666 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7667 | struct intel_crtc_state *crtc_state) |
| 7668 | { |
| 7669 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7670 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7671 | |
| 7672 | memset(&crtc_state->dpll_hw_state, 0, |
| 7673 | sizeof(crtc_state->dpll_hw_state)); |
| 7674 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7675 | if (!crtc_state->clock_set && |
| 7676 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7677 | refclk, NULL, &crtc_state->dpll)) { |
| 7678 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7679 | return -EINVAL; |
| 7680 | } |
| 7681 | |
| 7682 | vlv_compute_dpll(crtc, crtc_state); |
| 7683 | |
| 7684 | return 0; |
| 7685 | } |
| 7686 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7687 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7688 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7689 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7690 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7691 | uint32_t tmp; |
| 7692 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7693 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7694 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7695 | return; |
| 7696 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7697 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7698 | if (!(tmp & PFIT_ENABLE)) |
| 7699 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7700 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7701 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7702 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7703 | if (crtc->pipe != PIPE_B) |
| 7704 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7705 | } else { |
| 7706 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7707 | return; |
| 7708 | } |
| 7709 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7710 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7711 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7712 | } |
| 7713 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7714 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7715 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7716 | { |
| 7717 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7718 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7719 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7720 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7721 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7722 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7723 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7724 | /* In case of DSI, DPLL will not be used */ |
| 7725 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7726 | return; |
| 7727 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7728 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7729 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7730 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7731 | |
| 7732 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7733 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7734 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7735 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7736 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7737 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7738 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7739 | } |
| 7740 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7741 | static void |
| 7742 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7743 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7744 | { |
| 7745 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7746 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7747 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7748 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7749 | enum pipe pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7750 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7751 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7752 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7753 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7754 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7755 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7756 | if (!plane->get_hw_state(plane, &pipe)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7757 | return; |
| 7758 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7759 | WARN_ON(pipe != crtc->pipe); |
| 7760 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7761 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7762 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7763 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7764 | return; |
| 7765 | } |
| 7766 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7767 | fb = &intel_fb->base; |
| 7768 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7769 | fb->dev = dev; |
| 7770 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7771 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7772 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7773 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7774 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7775 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7776 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7777 | } |
| 7778 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7779 | |
| 7780 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7781 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 7782 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7783 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 7784 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 7785 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 7786 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 7787 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7788 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7789 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7790 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7791 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 7792 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7793 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7794 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7795 | } |
| 7796 | plane_config->base = base; |
| 7797 | |
| 7798 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7799 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7800 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7801 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7802 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7803 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7804 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 7805 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7806 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7807 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7808 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7809 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7810 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 7811 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7812 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7813 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7814 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7815 | } |
| 7816 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7817 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7818 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7819 | { |
| 7820 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7821 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7822 | int pipe = pipe_config->cpu_transcoder; |
| 7823 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7824 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7825 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7826 | int refclk = 100000; |
| 7827 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7828 | /* In case of DSI, DPLL will not be used */ |
| 7829 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7830 | return; |
| 7831 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7832 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7833 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7834 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7835 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7836 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7837 | 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] | 7838 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7839 | |
| 7840 | 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] | 7841 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 7842 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 7843 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7844 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7845 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7846 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7847 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7848 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7849 | } |
| 7850 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7851 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7852 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7853 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7854 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7855 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7856 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7857 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7858 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7859 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 7860 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7861 | return false; |
| 7862 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7863 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 7864 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7865 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7866 | ret = false; |
| 7867 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7868 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7869 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7870 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7871 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7872 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7873 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7874 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7875 | case PIPECONF_6BPC: |
| 7876 | pipe_config->pipe_bpp = 18; |
| 7877 | break; |
| 7878 | case PIPECONF_8BPC: |
| 7879 | pipe_config->pipe_bpp = 24; |
| 7880 | break; |
| 7881 | case PIPECONF_10BPC: |
| 7882 | pipe_config->pipe_bpp = 30; |
| 7883 | break; |
| 7884 | default: |
| 7885 | break; |
| 7886 | } |
| 7887 | } |
| 7888 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7889 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7890 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7891 | pipe_config->limited_color_range = true; |
| 7892 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7893 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 7894 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 7895 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7896 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7897 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7898 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7899 | i9xx_get_pfit_config(crtc, pipe_config); |
| 7900 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7901 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 7902 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7903 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 7904 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 7905 | else |
| 7906 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7907 | pipe_config->pixel_multiplier = |
| 7908 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 7909 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7910 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7911 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7912 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7913 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 7914 | pipe_config->pixel_multiplier = |
| 7915 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 7916 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 7917 | } else { |
| 7918 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 7919 | * port and will be fixed up in the encoder->get_config |
| 7920 | * function. */ |
| 7921 | pipe_config->pixel_multiplier = 1; |
| 7922 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7923 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7924 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7925 | /* |
| 7926 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 7927 | * on 830. Filter it out here so that we don't |
| 7928 | * report errors due to that. |
| 7929 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7930 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7931 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 7932 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7933 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 7934 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 7935 | } else { |
| 7936 | /* Mask out read-only status bits. */ |
| 7937 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 7938 | DPLL_PORTC_READY_MASK | |
| 7939 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7940 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7941 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7942 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7943 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 7944 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7945 | vlv_crtc_clock_get(crtc, pipe_config); |
| 7946 | else |
| 7947 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7948 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 7949 | /* |
| 7950 | * Normally the dotclock is filled in by the encoder .get_config() |
| 7951 | * but in case the pipe is enabled w/o any ports we need a sane |
| 7952 | * default. |
| 7953 | */ |
| 7954 | pipe_config->base.adjusted_mode.crtc_clock = |
| 7955 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 7956 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7957 | ret = true; |
| 7958 | |
| 7959 | out: |
| 7960 | intel_display_power_put(dev_priv, power_domain); |
| 7961 | |
| 7962 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7963 | } |
| 7964 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 7965 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7966 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7967 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7968 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7969 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7970 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7971 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7972 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7973 | bool has_ck505 = false; |
| 7974 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 7975 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7976 | |
| 7977 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 7978 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7979 | switch (encoder->type) { |
| 7980 | case INTEL_OUTPUT_LVDS: |
| 7981 | has_panel = true; |
| 7982 | has_lvds = true; |
| 7983 | break; |
| 7984 | case INTEL_OUTPUT_EDP: |
| 7985 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 7986 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7987 | has_cpu_edp = true; |
| 7988 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7989 | default: |
| 7990 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7991 | } |
| 7992 | } |
| 7993 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7994 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7995 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7996 | can_ssc = has_ck505; |
| 7997 | } else { |
| 7998 | has_ck505 = false; |
| 7999 | can_ssc = true; |
| 8000 | } |
| 8001 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8002 | /* Check if any DPLLs are using the SSC source */ |
| 8003 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8004 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8005 | |
| 8006 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8007 | continue; |
| 8008 | |
| 8009 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8010 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8011 | using_ssc_source = true; |
| 8012 | break; |
| 8013 | } |
| 8014 | } |
| 8015 | |
| 8016 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8017 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8018 | |
| 8019 | /* Ironlake: try to setup display ref clock before DPLL |
| 8020 | * enabling. This is only under driver's control after |
| 8021 | * PCH B stepping, previous chipset stepping should be |
| 8022 | * ignoring this setting. |
| 8023 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8024 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8025 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8026 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8027 | * compute the final state we want first and check if we need to |
| 8028 | * make any changes at all. |
| 8029 | */ |
| 8030 | final = val; |
| 8031 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8032 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8033 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8034 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8035 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8036 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8037 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8038 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8039 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8040 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8041 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8042 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8043 | |
| 8044 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8045 | final |= DREF_SSC1_ENABLE; |
| 8046 | |
| 8047 | if (has_cpu_edp) { |
| 8048 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8049 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8050 | else |
| 8051 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8052 | } else |
| 8053 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8054 | } else if (using_ssc_source) { |
| 8055 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8056 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8057 | } |
| 8058 | |
| 8059 | if (final == val) |
| 8060 | return; |
| 8061 | |
| 8062 | /* Always enable nonspread source */ |
| 8063 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8064 | |
| 8065 | if (has_ck505) |
| 8066 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8067 | else |
| 8068 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8069 | |
| 8070 | if (has_panel) { |
| 8071 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8072 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8073 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8074 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8075 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8076 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8077 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8078 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8079 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8080 | |
| 8081 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8082 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8083 | POSTING_READ(PCH_DREF_CONTROL); |
| 8084 | udelay(200); |
| 8085 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8086 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8087 | |
| 8088 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8089 | if (has_cpu_edp) { |
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 eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8092 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8093 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8094 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8095 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8096 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8097 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8098 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8099 | POSTING_READ(PCH_DREF_CONTROL); |
| 8100 | udelay(200); |
| 8101 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8102 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8103 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8104 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8105 | |
| 8106 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8107 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8108 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8109 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8110 | POSTING_READ(PCH_DREF_CONTROL); |
| 8111 | udelay(200); |
| 8112 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8113 | if (!using_ssc_source) { |
| 8114 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8115 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8116 | /* Turn off the SSC source */ |
| 8117 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8118 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8119 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8120 | /* Turn off SSC1 */ |
| 8121 | val &= ~DREF_SSC1_ENABLE; |
| 8122 | |
| 8123 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8124 | POSTING_READ(PCH_DREF_CONTROL); |
| 8125 | udelay(200); |
| 8126 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8127 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8128 | |
| 8129 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8132 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8133 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8134 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8135 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8136 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8137 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8138 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8139 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8140 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8141 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8142 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8143 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8144 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8145 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8146 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8147 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8148 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8149 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8150 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8151 | } |
| 8152 | |
| 8153 | /* WaMPhyProgramming:hsw */ |
| 8154 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8155 | { |
| 8156 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8157 | |
| 8158 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8159 | tmp &= ~(0xFF << 24); |
| 8160 | tmp |= (0x12 << 24); |
| 8161 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8162 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8163 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8164 | tmp |= (1 << 11); |
| 8165 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8166 | |
| 8167 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8168 | tmp |= (1 << 11); |
| 8169 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8170 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8171 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8172 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8173 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8174 | |
| 8175 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8176 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8177 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8178 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8179 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8180 | tmp &= ~(7 << 13); |
| 8181 | tmp |= (5 << 13); |
| 8182 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8183 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8184 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8185 | tmp &= ~(7 << 13); |
| 8186 | tmp |= (5 << 13); |
| 8187 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8188 | |
| 8189 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8190 | tmp &= ~0xFF; |
| 8191 | tmp |= 0x1C; |
| 8192 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8193 | |
| 8194 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8195 | tmp &= ~0xFF; |
| 8196 | tmp |= 0x1C; |
| 8197 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8198 | |
| 8199 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8200 | tmp &= ~(0xFF << 16); |
| 8201 | tmp |= (0x1C << 16); |
| 8202 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8203 | |
| 8204 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8205 | tmp &= ~(0xFF << 16); |
| 8206 | tmp |= (0x1C << 16); |
| 8207 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8208 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8209 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8210 | tmp |= (1 << 27); |
| 8211 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8212 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8213 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8214 | tmp |= (1 << 27); |
| 8215 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8216 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8217 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8218 | tmp &= ~(0xF << 28); |
| 8219 | tmp |= (4 << 28); |
| 8220 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8221 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8222 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8223 | tmp &= ~(0xF << 28); |
| 8224 | tmp |= (4 << 28); |
| 8225 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8226 | } |
| 8227 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8228 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8229 | * Programming" based on the parameters passed: |
| 8230 | * - Sequence to enable CLKOUT_DP |
| 8231 | * - Sequence to enable CLKOUT_DP without spread |
| 8232 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8233 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8234 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8235 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8236 | { |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8237 | uint32_t reg, tmp; |
| 8238 | |
| 8239 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8240 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8241 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8242 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8243 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8244 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8245 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8246 | |
| 8247 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8248 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8249 | tmp |= SBI_SSCCTL_PATHALT; |
| 8250 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8251 | |
| 8252 | udelay(24); |
| 8253 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8254 | if (with_spread) { |
| 8255 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8256 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8257 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8258 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8259 | if (with_fdi) { |
| 8260 | lpt_reset_fdi_mphy(dev_priv); |
| 8261 | lpt_program_fdi_mphy(dev_priv); |
| 8262 | } |
| 8263 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8264 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8265 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8266 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8267 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8268 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8269 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8270 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8271 | } |
| 8272 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8273 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8274 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8275 | { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8276 | uint32_t reg, tmp; |
| 8277 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8278 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [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 | 47701c3 | 2013-07-23 11:19:25 -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); |
| 8284 | |
| 8285 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8286 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8287 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8288 | tmp |= SBI_SSCCTL_PATHALT; |
| 8289 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8290 | udelay(32); |
| 8291 | } |
| 8292 | tmp |= SBI_SSCCTL_DISABLE; |
| 8293 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8294 | } |
| 8295 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8296 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8297 | } |
| 8298 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8299 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8300 | |
| 8301 | static const uint16_t sscdivintphase[] = { |
| 8302 | [BEND_IDX( 50)] = 0x3B23, |
| 8303 | [BEND_IDX( 45)] = 0x3B23, |
| 8304 | [BEND_IDX( 40)] = 0x3C23, |
| 8305 | [BEND_IDX( 35)] = 0x3C23, |
| 8306 | [BEND_IDX( 30)] = 0x3D23, |
| 8307 | [BEND_IDX( 25)] = 0x3D23, |
| 8308 | [BEND_IDX( 20)] = 0x3E23, |
| 8309 | [BEND_IDX( 15)] = 0x3E23, |
| 8310 | [BEND_IDX( 10)] = 0x3F23, |
| 8311 | [BEND_IDX( 5)] = 0x3F23, |
| 8312 | [BEND_IDX( 0)] = 0x0025, |
| 8313 | [BEND_IDX( -5)] = 0x0025, |
| 8314 | [BEND_IDX(-10)] = 0x0125, |
| 8315 | [BEND_IDX(-15)] = 0x0125, |
| 8316 | [BEND_IDX(-20)] = 0x0225, |
| 8317 | [BEND_IDX(-25)] = 0x0225, |
| 8318 | [BEND_IDX(-30)] = 0x0325, |
| 8319 | [BEND_IDX(-35)] = 0x0325, |
| 8320 | [BEND_IDX(-40)] = 0x0425, |
| 8321 | [BEND_IDX(-45)] = 0x0425, |
| 8322 | [BEND_IDX(-50)] = 0x0525, |
| 8323 | }; |
| 8324 | |
| 8325 | /* |
| 8326 | * Bend CLKOUT_DP |
| 8327 | * steps -50 to 50 inclusive, in steps of 5 |
| 8328 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8329 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8330 | */ |
| 8331 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8332 | { |
| 8333 | uint32_t tmp; |
| 8334 | int idx = BEND_IDX(steps); |
| 8335 | |
| 8336 | if (WARN_ON(steps % 5 != 0)) |
| 8337 | return; |
| 8338 | |
| 8339 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8340 | return; |
| 8341 | |
| 8342 | mutex_lock(&dev_priv->sb_lock); |
| 8343 | |
| 8344 | if (steps % 10 != 0) |
| 8345 | tmp = 0xAAAAAAAB; |
| 8346 | else |
| 8347 | tmp = 0x00000000; |
| 8348 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8349 | |
| 8350 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8351 | tmp &= 0xffff0000; |
| 8352 | tmp |= sscdivintphase[idx]; |
| 8353 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8354 | |
| 8355 | mutex_unlock(&dev_priv->sb_lock); |
| 8356 | } |
| 8357 | |
| 8358 | #undef BEND_IDX |
| 8359 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8360 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8361 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8362 | struct intel_encoder *encoder; |
| 8363 | bool has_vga = false; |
| 8364 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8365 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8366 | switch (encoder->type) { |
| 8367 | case INTEL_OUTPUT_ANALOG: |
| 8368 | has_vga = true; |
| 8369 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8370 | default: |
| 8371 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8372 | } |
| 8373 | } |
| 8374 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8375 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8376 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8377 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8378 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8379 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8380 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8381 | } |
| 8382 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8383 | /* |
| 8384 | * Initialize reference clocks when the driver loads |
| 8385 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8386 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8387 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8388 | 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] | 8389 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8390 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8391 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8392 | } |
| 8393 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8394 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8395 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8396 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8397 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8398 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8399 | uint32_t val; |
| 8400 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8401 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8402 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8403 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8404 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8405 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8406 | break; |
| 8407 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8408 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8409 | break; |
| 8410 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8411 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8412 | break; |
| 8413 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8414 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8415 | break; |
| 8416 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8417 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8418 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8419 | } |
| 8420 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8421 | if (crtc_state->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8422 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8423 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8424 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8425 | val |= PIPECONF_INTERLACED_ILK; |
| 8426 | else |
| 8427 | val |= PIPECONF_PROGRESSIVE; |
| 8428 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8429 | if (crtc_state->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8430 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8431 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8432 | I915_WRITE(PIPECONF(pipe), val); |
| 8433 | POSTING_READ(PIPECONF(pipe)); |
| 8434 | } |
| 8435 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8436 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8437 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8438 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8439 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8440 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8441 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8442 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8443 | if (IS_HASWELL(dev_priv) && crtc_state->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8444 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8445 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8446 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8447 | val |= PIPECONF_INTERLACED_ILK; |
| 8448 | else |
| 8449 | val |= PIPECONF_PROGRESSIVE; |
| 8450 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8451 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8452 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8453 | } |
| 8454 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8455 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state) |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8456 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8457 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8458 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8459 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8460 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8461 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8462 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8463 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8464 | case 18: |
| 8465 | val |= PIPEMISC_DITHER_6_BPC; |
| 8466 | break; |
| 8467 | case 24: |
| 8468 | val |= PIPEMISC_DITHER_8_BPC; |
| 8469 | break; |
| 8470 | case 30: |
| 8471 | val |= PIPEMISC_DITHER_10_BPC; |
| 8472 | break; |
| 8473 | case 36: |
| 8474 | val |= PIPEMISC_DITHER_12_BPC; |
| 8475 | break; |
| 8476 | default: |
| 8477 | /* Case prevented by pipe_config_set_bpp. */ |
| 8478 | BUG(); |
| 8479 | } |
| 8480 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8481 | if (crtc_state->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8482 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8483 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8484 | if (crtc_state->ycbcr420) { |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8485 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV | |
| 8486 | PIPEMISC_YUV420_ENABLE | |
| 8487 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 8488 | } |
| 8489 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8490 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8491 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8492 | } |
| 8493 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8494 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8495 | { |
| 8496 | /* |
| 8497 | * Account for spread spectrum to avoid |
| 8498 | * oversubscribing the link. Max center spread |
| 8499 | * is 2.5%; use 5% for safety's sake. |
| 8500 | */ |
| 8501 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8502 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8503 | } |
| 8504 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8505 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8506 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8507 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8508 | } |
| 8509 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8510 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8511 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8512 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8513 | { |
| 8514 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8515 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8516 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8517 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8518 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8519 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8520 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8521 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8522 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8523 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8524 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8525 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8526 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8527 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8528 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8529 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8530 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8531 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8532 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8533 | fp |= FP_CB_TUNE; |
| 8534 | |
| 8535 | if (reduced_clock) { |
| 8536 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8537 | |
| 8538 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8539 | fp2 |= FP_CB_TUNE; |
| 8540 | } else { |
| 8541 | fp2 = fp; |
| 8542 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8543 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8544 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8545 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8546 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8547 | dpll |= DPLLB_MODE_LVDS; |
| 8548 | else |
| 8549 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8550 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8551 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8552 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8553 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8554 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8555 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8556 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8557 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8558 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8559 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8560 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8561 | /* |
| 8562 | * The high speed IO clock is only really required for |
| 8563 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8564 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8565 | * the clock needlessly does no real harm, except use up a |
| 8566 | * bit of power potentially. |
| 8567 | * |
| 8568 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8569 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8570 | * driving PCH ports at the same time. On SNB we could do this, |
| 8571 | * and potentially avoid enabling the second DPLL, but it's not |
| 8572 | * clear if it''s a win or loss power wise. No point in doing |
| 8573 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8574 | */ |
| 8575 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8576 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8577 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8578 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8579 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8580 | 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] | 8581 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8582 | 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] | 8583 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8584 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8585 | case 5: |
| 8586 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8587 | break; |
| 8588 | case 7: |
| 8589 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8590 | break; |
| 8591 | case 10: |
| 8592 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8593 | break; |
| 8594 | case 14: |
| 8595 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8596 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8597 | } |
| 8598 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8599 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8600 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8601 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8602 | else |
| 8603 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8604 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8605 | dpll |= DPLL_VCO_ENABLE; |
| 8606 | |
| 8607 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8608 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8609 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8610 | } |
| 8611 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8612 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8613 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8614 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8615 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8616 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8617 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8618 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8619 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8620 | memset(&crtc_state->dpll_hw_state, 0, |
| 8621 | sizeof(crtc_state->dpll_hw_state)); |
| 8622 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8623 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8624 | if (!crtc_state->has_pch_encoder) |
| 8625 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8626 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8627 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8628 | if (intel_panel_use_ssc(dev_priv)) { |
| 8629 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8630 | dev_priv->vbt.lvds_ssc_freq); |
| 8631 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8632 | } |
| 8633 | |
| 8634 | if (intel_is_dual_link_lvds(dev)) { |
| 8635 | if (refclk == 100000) |
| 8636 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8637 | else |
| 8638 | limit = &intel_limits_ironlake_dual_lvds; |
| 8639 | } else { |
| 8640 | if (refclk == 100000) |
| 8641 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8642 | else |
| 8643 | limit = &intel_limits_ironlake_single_lvds; |
| 8644 | } |
| 8645 | } else { |
| 8646 | limit = &intel_limits_ironlake_dac; |
| 8647 | } |
| 8648 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8649 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8650 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8651 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8652 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8653 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8654 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8655 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8656 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8657 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8658 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 8659 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 8660 | pipe_name(crtc->pipe)); |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8661 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8662 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8663 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8664 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8665 | } |
| 8666 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8667 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8668 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8669 | { |
| 8670 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8671 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8672 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8673 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8674 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8675 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8676 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8677 | & ~TU_SIZE_MASK; |
| 8678 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8679 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8680 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8681 | } |
| 8682 | |
| 8683 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8684 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8685 | struct intel_link_m_n *m_n, |
| 8686 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8687 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8688 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8689 | enum pipe pipe = crtc->pipe; |
| 8690 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8691 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8692 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8693 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8694 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8695 | & ~TU_SIZE_MASK; |
| 8696 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8697 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8698 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8699 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8700 | * gen < 8) and if DRRS is supported (to make sure the |
| 8701 | * registers are not unnecessarily read). |
| 8702 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8703 | if (m2_n2 && INTEL_GEN(dev_priv) < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8704 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8705 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8706 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8707 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8708 | & ~TU_SIZE_MASK; |
| 8709 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8710 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8711 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8712 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8713 | } else { |
| 8714 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8715 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8716 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8717 | & ~TU_SIZE_MASK; |
| 8718 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8719 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8720 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8721 | } |
| 8722 | } |
| 8723 | |
| 8724 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8725 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8726 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8727 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8728 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8729 | else |
| 8730 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8731 | &pipe_config->dp_m_n, |
| 8732 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8733 | } |
| 8734 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8735 | 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] | 8736 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8737 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8738 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8739 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8740 | } |
| 8741 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8742 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8743 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8744 | { |
| 8745 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8746 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8747 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 8748 | uint32_t ps_ctrl = 0; |
| 8749 | int id = -1; |
| 8750 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8751 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8752 | /* find scaler attached to this pipe */ |
| 8753 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8754 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8755 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8756 | id = i; |
| 8757 | pipe_config->pch_pfit.enabled = true; |
| 8758 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8759 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8760 | break; |
| 8761 | } |
| 8762 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8763 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8764 | scaler_state->scaler_id = id; |
| 8765 | if (id >= 0) { |
| 8766 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8767 | } else { |
| 8768 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8769 | } |
| 8770 | } |
| 8771 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8772 | static void |
| 8773 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8774 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8775 | { |
| 8776 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8777 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8778 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 8779 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8780 | enum pipe pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8781 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8782 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8783 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8784 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8785 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8786 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8787 | if (!plane->get_hw_state(plane, &pipe)) |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 8788 | return; |
| 8789 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8790 | WARN_ON(pipe != crtc->pipe); |
| 8791 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8792 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8793 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8794 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8795 | return; |
| 8796 | } |
| 8797 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8798 | fb = &intel_fb->base; |
| 8799 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 8800 | fb->dev = dev; |
| 8801 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8802 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8803 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 8804 | if (INTEL_GEN(dev_priv) >= 11) |
| 8805 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 8806 | else |
| 8807 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8808 | |
| 8809 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8810 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8811 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 8812 | } else { |
| 8813 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 8814 | } |
| 8815 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8816 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8817 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 8818 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8819 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8820 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8821 | switch (tiling) { |
| 8822 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 8823 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8824 | break; |
| 8825 | case PLANE_CTL_TILED_X: |
| 8826 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8827 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8828 | break; |
| 8829 | case PLANE_CTL_TILED_Y: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8830 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8831 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 8832 | else |
| 8833 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8834 | break; |
| 8835 | case PLANE_CTL_TILED_YF: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8836 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8837 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 8838 | else |
| 8839 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8840 | break; |
| 8841 | default: |
| 8842 | MISSING_CASE(tiling); |
| 8843 | goto error; |
| 8844 | } |
| 8845 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8846 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8847 | plane_config->base = base; |
| 8848 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8849 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8850 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8851 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8852 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8853 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8854 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8855 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8856 | stride_mult = intel_fb_stride_alignment(fb, 0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8857 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8858 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8859 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8860 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8861 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8862 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8863 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8864 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 8865 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8866 | plane_config->size); |
| 8867 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8868 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8869 | return; |
| 8870 | |
| 8871 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 8872 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8873 | } |
| 8874 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8875 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8876 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8877 | { |
| 8878 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8879 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8880 | uint32_t tmp; |
| 8881 | |
| 8882 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 8883 | |
| 8884 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 8885 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8886 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 8887 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8888 | |
| 8889 | /* We currently do not free assignements of panel fitters on |
| 8890 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 8891 | * differentiates them) so just WARN about this case for now. */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 8892 | if (IS_GEN7(dev_priv)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8893 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 8894 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 8895 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8896 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8897 | } |
| 8898 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8899 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8900 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8901 | { |
| 8902 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8903 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8904 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8905 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8906 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8907 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8908 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8909 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8910 | return false; |
| 8911 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8912 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8913 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8914 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8915 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8916 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8917 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8918 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8919 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8920 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8921 | case PIPECONF_6BPC: |
| 8922 | pipe_config->pipe_bpp = 18; |
| 8923 | break; |
| 8924 | case PIPECONF_8BPC: |
| 8925 | pipe_config->pipe_bpp = 24; |
| 8926 | break; |
| 8927 | case PIPECONF_10BPC: |
| 8928 | pipe_config->pipe_bpp = 30; |
| 8929 | break; |
| 8930 | case PIPECONF_12BPC: |
| 8931 | pipe_config->pipe_bpp = 36; |
| 8932 | break; |
| 8933 | default: |
| 8934 | break; |
| 8935 | } |
| 8936 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8937 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8938 | pipe_config->limited_color_range = true; |
| 8939 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8940 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8941 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8942 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8943 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8944 | pipe_config->has_pch_encoder = true; |
| 8945 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8946 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8947 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8948 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8949 | |
| 8950 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8951 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 8952 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 8953 | /* |
| 8954 | * The pipe->pch transcoder and pch transcoder->pll |
| 8955 | * mapping is fixed. |
| 8956 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8957 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8958 | } else { |
| 8959 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8960 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8961 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8962 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8963 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8964 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8965 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8966 | pipe_config->shared_dpll = |
| 8967 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 8968 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8969 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 8970 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 8971 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8972 | |
| 8973 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8974 | pipe_config->pixel_multiplier = |
| 8975 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8976 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8977 | |
| 8978 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8979 | } else { |
| 8980 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8981 | } |
| 8982 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8983 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8984 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8985 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8986 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8987 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8988 | ret = true; |
| 8989 | |
| 8990 | out: |
| 8991 | intel_display_power_put(dev_priv, power_domain); |
| 8992 | |
| 8993 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8994 | } |
| 8995 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8996 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 8997 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 8998 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8999 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9000 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9001 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9002 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9003 | pipe_name(crtc->pipe)); |
| 9004 | |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 9005 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2), |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 9006 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9007 | 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] | 9008 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9009 | 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] | 9010 | 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] | 9011 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9012 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9013 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9014 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9015 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9016 | 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] | 9017 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9018 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9019 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9020 | 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] | 9021 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9022 | /* |
| 9023 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9024 | * interrupts remain enabled. We used to check for that, but since it's |
| 9025 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9026 | * the interrupts, the check below should be enough. |
| 9027 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9028 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9029 | } |
| 9030 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9031 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9032 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9033 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9034 | return I915_READ(D_COMP_HSW); |
| 9035 | else |
| 9036 | return I915_READ(D_COMP_BDW); |
| 9037 | } |
| 9038 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9039 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9040 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9041 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9042 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9043 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9044 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 9045 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9046 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9047 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9048 | I915_WRITE(D_COMP_BDW, val); |
| 9049 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9050 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9051 | } |
| 9052 | |
| 9053 | /* |
| 9054 | * This function implements pieces of two sequences from BSpec: |
| 9055 | * - Sequence for display software to disable LCPLL |
| 9056 | * - Sequence for display software to allow package C8+ |
| 9057 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9058 | * register. Callers should take care of disabling all the display engine |
| 9059 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9060 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9061 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9062 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9063 | { |
| 9064 | uint32_t val; |
| 9065 | |
| 9066 | assert_can_disable_lcpll(dev_priv); |
| 9067 | |
| 9068 | val = I915_READ(LCPLL_CTL); |
| 9069 | |
| 9070 | if (switch_to_fclk) { |
| 9071 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9072 | I915_WRITE(LCPLL_CTL, val); |
| 9073 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9074 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9075 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9076 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9077 | |
| 9078 | val = I915_READ(LCPLL_CTL); |
| 9079 | } |
| 9080 | |
| 9081 | val |= LCPLL_PLL_DISABLE; |
| 9082 | I915_WRITE(LCPLL_CTL, val); |
| 9083 | POSTING_READ(LCPLL_CTL); |
| 9084 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 9085 | 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] | 9086 | DRM_ERROR("LCPLL still locked\n"); |
| 9087 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9088 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9089 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9090 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9091 | ndelay(100); |
| 9092 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9093 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9094 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9095 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9096 | |
| 9097 | if (allow_power_down) { |
| 9098 | val = I915_READ(LCPLL_CTL); |
| 9099 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9100 | I915_WRITE(LCPLL_CTL, val); |
| 9101 | POSTING_READ(LCPLL_CTL); |
| 9102 | } |
| 9103 | } |
| 9104 | |
| 9105 | /* |
| 9106 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9107 | * source. |
| 9108 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9109 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9110 | { |
| 9111 | uint32_t val; |
| 9112 | |
| 9113 | val = I915_READ(LCPLL_CTL); |
| 9114 | |
| 9115 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9116 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9117 | return; |
| 9118 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9119 | /* |
| 9120 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9121 | * 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] | 9122 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9123 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9124 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9125 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9126 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9127 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9128 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9129 | } |
| 9130 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9131 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9132 | val |= D_COMP_COMP_FORCE; |
| 9133 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9134 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9135 | |
| 9136 | val = I915_READ(LCPLL_CTL); |
| 9137 | val &= ~LCPLL_PLL_DISABLE; |
| 9138 | I915_WRITE(LCPLL_CTL, val); |
| 9139 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9140 | if (intel_wait_for_register(dev_priv, |
| 9141 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9142 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9143 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9144 | |
| 9145 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9146 | val = I915_READ(LCPLL_CTL); |
| 9147 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9148 | I915_WRITE(LCPLL_CTL, val); |
| 9149 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9150 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9151 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9152 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9153 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9154 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9155 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9156 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9157 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9158 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9159 | } |
| 9160 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9161 | /* |
| 9162 | * Package states C8 and deeper are really deep PC states that can only be |
| 9163 | * reached when all the devices on the system allow it, so even if the graphics |
| 9164 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9165 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9166 | * |
| 9167 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9168 | * well is disabled and most interrupts are disabled, and these are also |
| 9169 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9170 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9171 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9172 | * hang the machine. |
| 9173 | * |
| 9174 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9175 | * the state of some registers, so when we come back from PC8+ we need to |
| 9176 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9177 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9178 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9179 | * because of the runtime PM support). |
| 9180 | * |
| 9181 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9182 | * documentation. |
| 9183 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9184 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9185 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9186 | uint32_t val; |
| 9187 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9188 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9189 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9190 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9191 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9192 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9193 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9194 | } |
| 9195 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9196 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9197 | hsw_disable_lcpll(dev_priv, true, true); |
| 9198 | } |
| 9199 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9200 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9201 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9202 | uint32_t val; |
| 9203 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9204 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9205 | |
| 9206 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9207 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9208 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9209 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9210 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9211 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9212 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9213 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9214 | } |
| 9215 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9216 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9217 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9218 | { |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9219 | struct intel_atomic_state *state = |
| 9220 | to_intel_atomic_state(crtc_state->base.state); |
| 9221 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9222 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9223 | struct intel_encoder *encoder = |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9224 | intel_get_crtc_new_encoder(state, crtc_state); |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9225 | |
| 9226 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 9227 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 9228 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9229 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9230 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9231 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9232 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9233 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9234 | } |
| 9235 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9236 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9237 | enum port port, |
| 9238 | struct intel_crtc_state *pipe_config) |
| 9239 | { |
| 9240 | enum intel_dpll_id id; |
| 9241 | u32 temp; |
| 9242 | |
| 9243 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9244 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9245 | |
| 9246 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9247 | return; |
| 9248 | |
| 9249 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9250 | } |
| 9251 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9252 | static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9253 | enum port port, |
| 9254 | struct intel_crtc_state *pipe_config) |
| 9255 | { |
| 9256 | enum intel_dpll_id id; |
| 9257 | u32 temp; |
| 9258 | |
| 9259 | /* TODO: TBT pll not implemented. */ |
| 9260 | switch (port) { |
| 9261 | case PORT_A: |
| 9262 | case PORT_B: |
| 9263 | temp = I915_READ(DPCLKA_CFGCR0_ICL) & |
| 9264 | DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
| 9265 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
| 9266 | |
| 9267 | if (WARN_ON(id != DPLL_ID_ICL_DPLL0 && id != DPLL_ID_ICL_DPLL1)) |
| 9268 | return; |
| 9269 | break; |
| 9270 | case PORT_C: |
| 9271 | id = DPLL_ID_ICL_MGPLL1; |
| 9272 | break; |
| 9273 | case PORT_D: |
| 9274 | id = DPLL_ID_ICL_MGPLL2; |
| 9275 | break; |
| 9276 | case PORT_E: |
| 9277 | id = DPLL_ID_ICL_MGPLL3; |
| 9278 | break; |
| 9279 | case PORT_F: |
| 9280 | id = DPLL_ID_ICL_MGPLL4; |
| 9281 | break; |
| 9282 | default: |
| 9283 | MISSING_CASE(port); |
| 9284 | return; |
| 9285 | } |
| 9286 | |
| 9287 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9288 | } |
| 9289 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9290 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9291 | enum port port, |
| 9292 | struct intel_crtc_state *pipe_config) |
| 9293 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9294 | enum intel_dpll_id id; |
| 9295 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9296 | switch (port) { |
| 9297 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9298 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9299 | break; |
| 9300 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9301 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9302 | break; |
| 9303 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9304 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9305 | break; |
| 9306 | default: |
| 9307 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9308 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9309 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9310 | |
| 9311 | 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] | 9312 | } |
| 9313 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9314 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9315 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9316 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9317 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9318 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9319 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9320 | |
| 9321 | 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] | 9322 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9323 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9324 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9325 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9326 | |
| 9327 | 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] | 9328 | } |
| 9329 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9330 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9331 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9332 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9333 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9334 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9335 | 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] | 9336 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9337 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9338 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9339 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9340 | break; |
| 9341 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9342 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9343 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9344 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9345 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9346 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9347 | case PORT_CLK_SEL_LCPLL_810: |
| 9348 | id = DPLL_ID_LCPLL_810; |
| 9349 | break; |
| 9350 | case PORT_CLK_SEL_LCPLL_1350: |
| 9351 | id = DPLL_ID_LCPLL_1350; |
| 9352 | break; |
| 9353 | case PORT_CLK_SEL_LCPLL_2700: |
| 9354 | id = DPLL_ID_LCPLL_2700; |
| 9355 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9356 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9357 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9358 | /* fall through */ |
| 9359 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9360 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9361 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9362 | |
| 9363 | 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] | 9364 | } |
| 9365 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9366 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9367 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9368 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9369 | { |
| 9370 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9371 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9372 | enum intel_display_power_domain power_domain; |
| 9373 | u32 tmp; |
| 9374 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9375 | /* |
| 9376 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
| 9377 | * transcoder handled below. |
| 9378 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9379 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9380 | |
| 9381 | /* |
| 9382 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9383 | * consistency and less surprising code; it's in always on power). |
| 9384 | */ |
| 9385 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9386 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9387 | enum pipe trans_edp_pipe; |
| 9388 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9389 | default: |
| 9390 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 9391 | /* fall through */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9392 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9393 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9394 | trans_edp_pipe = PIPE_A; |
| 9395 | break; |
| 9396 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9397 | trans_edp_pipe = PIPE_B; |
| 9398 | break; |
| 9399 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9400 | trans_edp_pipe = PIPE_C; |
| 9401 | break; |
| 9402 | } |
| 9403 | |
| 9404 | if (trans_edp_pipe == crtc->pipe) |
| 9405 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9406 | } |
| 9407 | |
| 9408 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9409 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9410 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9411 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9412 | |
| 9413 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9414 | |
| 9415 | return tmp & PIPECONF_ENABLE; |
| 9416 | } |
| 9417 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9418 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9419 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9420 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9421 | { |
| 9422 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9423 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9424 | enum intel_display_power_domain power_domain; |
| 9425 | enum port port; |
| 9426 | enum transcoder cpu_transcoder; |
| 9427 | u32 tmp; |
| 9428 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9429 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9430 | if (port == PORT_A) |
| 9431 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9432 | else |
| 9433 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9434 | |
| 9435 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9436 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9437 | continue; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9438 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9439 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9440 | /* |
| 9441 | * The PLL needs to be enabled with a valid divider |
| 9442 | * configuration, otherwise accessing DSI registers will hang |
| 9443 | * the machine. See BSpec North Display Engine |
| 9444 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9445 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9446 | */ |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 9447 | if (!bxt_dsi_pll_is_enabled(dev_priv)) |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9448 | break; |
| 9449 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9450 | /* XXX: this works for video mode only */ |
| 9451 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9452 | if (!(tmp & DPI_ENABLE)) |
| 9453 | continue; |
| 9454 | |
| 9455 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9456 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9457 | continue; |
| 9458 | |
| 9459 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9460 | break; |
| 9461 | } |
| 9462 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9463 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9464 | } |
| 9465 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9466 | 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] | 9467 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9468 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9469 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9470 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9471 | enum port port; |
| 9472 | uint32_t tmp; |
| 9473 | |
| 9474 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9475 | |
| 9476 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9477 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9478 | if (IS_ICELAKE(dev_priv)) |
| 9479 | icelake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9480 | else if (IS_CANNONLAKE(dev_priv)) |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9481 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9482 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9483 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9484 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9485 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9486 | else |
| 9487 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9488 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9489 | pll = pipe_config->shared_dpll; |
| 9490 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9491 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9492 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9493 | } |
| 9494 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9495 | /* |
| 9496 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9497 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9498 | * the PCH transcoder is on. |
| 9499 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9500 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9501 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9502 | pipe_config->has_pch_encoder = true; |
| 9503 | |
| 9504 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9505 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9506 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9507 | |
| 9508 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9509 | } |
| 9510 | } |
| 9511 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9512 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9513 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9514 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9515 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9516 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9517 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9518 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9519 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9520 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9521 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9522 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9523 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9524 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9525 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9526 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9527 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9528 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9529 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9530 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9531 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9532 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9533 | WARN_ON(active); |
| 9534 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9535 | } |
| 9536 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9537 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9538 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9539 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9540 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9541 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9542 | intel_get_pipe_timings(crtc, pipe_config); |
| 9543 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9544 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9545 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9546 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9547 | pipe_config->gamma_mode = |
| 9548 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9549 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 9550 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 9551 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 9552 | bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV; |
| 9553 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 9554 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 9555 | bool blend_mode_420 = tmp & |
| 9556 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 9557 | |
| 9558 | pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE; |
| 9559 | if (pipe_config->ycbcr420 != clrspace_yuv || |
| 9560 | pipe_config->ycbcr420 != blend_mode_420) |
| 9561 | DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp); |
| 9562 | } else if (clrspace_yuv) { |
| 9563 | DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n"); |
| 9564 | } |
| 9565 | } |
| 9566 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9567 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9568 | 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] | 9569 | power_domain_mask |= BIT_ULL(power_domain); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9570 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9571 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9572 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9573 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9574 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9575 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9576 | if (hsw_crtc_supports_ips(crtc)) { |
| 9577 | if (IS_HASWELL(dev_priv)) |
| 9578 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9579 | else { |
| 9580 | /* |
| 9581 | * We cannot readout IPS state on broadwell, set to |
| 9582 | * true so we can set it to a defined state on first |
| 9583 | * commit. |
| 9584 | */ |
| 9585 | pipe_config->ips_enabled = true; |
| 9586 | } |
| 9587 | } |
| 9588 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9589 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9590 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9591 | pipe_config->pixel_multiplier = |
| 9592 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9593 | } else { |
| 9594 | pipe_config->pixel_multiplier = 1; |
| 9595 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9596 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9597 | out: |
| 9598 | for_each_power_domain(power_domain, power_domain_mask) |
| 9599 | intel_display_power_put(dev_priv, power_domain); |
| 9600 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9601 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9602 | } |
| 9603 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9604 | 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] | 9605 | { |
| 9606 | struct drm_i915_private *dev_priv = |
| 9607 | to_i915(plane_state->base.plane->dev); |
| 9608 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9609 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9610 | u32 base; |
| 9611 | |
| 9612 | if (INTEL_INFO(dev_priv)->cursor_needs_physical) |
| 9613 | base = obj->phys_handle->busaddr; |
| 9614 | else |
| 9615 | base = intel_plane_ggtt_offset(plane_state); |
| 9616 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 9617 | base += plane_state->color_plane[0].offset; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9618 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9619 | /* ILK+ do this automagically */ |
| 9620 | if (HAS_GMCH_DISPLAY(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9621 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9622 | base += (plane_state->base.crtc_h * |
| 9623 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9624 | |
| 9625 | return base; |
| 9626 | } |
| 9627 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9628 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9629 | { |
| 9630 | int x = plane_state->base.crtc_x; |
| 9631 | int y = plane_state->base.crtc_y; |
| 9632 | u32 pos = 0; |
| 9633 | |
| 9634 | if (x < 0) { |
| 9635 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9636 | x = -x; |
| 9637 | } |
| 9638 | pos |= x << CURSOR_X_SHIFT; |
| 9639 | |
| 9640 | if (y < 0) { |
| 9641 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9642 | y = -y; |
| 9643 | } |
| 9644 | pos |= y << CURSOR_Y_SHIFT; |
| 9645 | |
| 9646 | return pos; |
| 9647 | } |
| 9648 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9649 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9650 | { |
| 9651 | const struct drm_mode_config *config = |
| 9652 | &plane_state->base.plane->dev->mode_config; |
| 9653 | int width = plane_state->base.crtc_w; |
| 9654 | int height = plane_state->base.crtc_h; |
| 9655 | |
| 9656 | return width > 0 && width <= config->cursor_width && |
| 9657 | height > 0 && height <= config->cursor_height; |
| 9658 | } |
| 9659 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9660 | 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] | 9661 | { |
| 9662 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9663 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9664 | int src_x, src_y; |
| 9665 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9666 | int ret; |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9667 | |
| 9668 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
| 9669 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 9670 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9671 | ret = intel_plane_check_stride(plane_state); |
| 9672 | if (ret) |
| 9673 | return ret; |
| 9674 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9675 | src_x = plane_state->base.src_x >> 16; |
| 9676 | src_y = plane_state->base.src_y >> 16; |
| 9677 | |
| 9678 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 9679 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 9680 | plane_state, 0); |
| 9681 | |
| 9682 | if (src_x != 0 || src_y != 0) { |
| 9683 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 9684 | return -EINVAL; |
| 9685 | } |
| 9686 | |
| 9687 | plane_state->color_plane[0].offset = offset; |
| 9688 | |
| 9689 | return 0; |
| 9690 | } |
| 9691 | |
| 9692 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 9693 | struct intel_plane_state *plane_state) |
| 9694 | { |
| 9695 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9696 | int ret; |
| 9697 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9698 | if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 9699 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 9700 | return -EINVAL; |
| 9701 | } |
| 9702 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9703 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 9704 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9705 | DRM_PLANE_HELPER_NO_SCALING, |
| 9706 | DRM_PLANE_HELPER_NO_SCALING, |
| 9707 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9708 | if (ret) |
| 9709 | return ret; |
| 9710 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9711 | if (!plane_state->base.visible) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9712 | return 0; |
| 9713 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9714 | ret = intel_plane_check_src_coordinates(plane_state); |
| 9715 | if (ret) |
| 9716 | return ret; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9717 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9718 | ret = intel_cursor_check_surface(plane_state); |
| 9719 | if (ret) |
| 9720 | return ret; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9721 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9722 | return 0; |
| 9723 | } |
| 9724 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 9725 | static unsigned int |
| 9726 | i845_cursor_max_stride(struct intel_plane *plane, |
| 9727 | u32 pixel_format, u64 modifier, |
| 9728 | unsigned int rotation) |
| 9729 | { |
| 9730 | return 2048; |
| 9731 | } |
| 9732 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9733 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9734 | const struct intel_plane_state *plane_state) |
| 9735 | { |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9736 | return CURSOR_ENABLE | |
| 9737 | CURSOR_GAMMA_ENABLE | |
| 9738 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9739 | CURSOR_STRIDE(plane_state->color_plane[0].stride); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9740 | } |
| 9741 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9742 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9743 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9744 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9745 | |
| 9746 | /* |
| 9747 | * 845g/865g are only limited by the width of their cursors, |
| 9748 | * the height is arbitrary up to the precision of the register. |
| 9749 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9750 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9751 | } |
| 9752 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9753 | static int i845_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9754 | struct intel_plane_state *plane_state) |
| 9755 | { |
| 9756 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9757 | int ret; |
| 9758 | |
| 9759 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9760 | if (ret) |
| 9761 | return ret; |
| 9762 | |
| 9763 | /* 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] | 9764 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9765 | return 0; |
| 9766 | |
| 9767 | /* Check for which cursor types we support */ |
| 9768 | if (!i845_cursor_size_ok(plane_state)) { |
| 9769 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9770 | plane_state->base.crtc_w, |
| 9771 | plane_state->base.crtc_h); |
| 9772 | return -EINVAL; |
| 9773 | } |
| 9774 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9775 | WARN_ON(plane_state->base.visible && |
| 9776 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 9777 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9778 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9779 | case 256: |
| 9780 | case 512: |
| 9781 | case 1024: |
| 9782 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9783 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9784 | default: |
| 9785 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 9786 | fb->pitches[0]); |
| 9787 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9788 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9789 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9790 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 9791 | |
| 9792 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9793 | } |
| 9794 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9795 | static void i845_update_cursor(struct intel_plane *plane, |
| 9796 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9797 | const struct intel_plane_state *plane_state) |
| 9798 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9799 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9800 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 9801 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9802 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 9803 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9804 | unsigned int width = plane_state->base.crtc_w; |
| 9805 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9806 | |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 9807 | cntl = plane_state->ctl; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9808 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9809 | |
| 9810 | base = intel_cursor_base(plane_state); |
| 9811 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9812 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9813 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9814 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 9815 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9816 | /* On these chipsets we can only modify the base/size/stride |
| 9817 | * whilst the cursor is disabled. |
| 9818 | */ |
| 9819 | if (plane->cursor.base != base || |
| 9820 | plane->cursor.size != size || |
| 9821 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9822 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9823 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9824 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9825 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9826 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9827 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9828 | plane->cursor.base = base; |
| 9829 | plane->cursor.size = size; |
| 9830 | plane->cursor.cntl = cntl; |
| 9831 | } else { |
| 9832 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9833 | } |
| 9834 | |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9835 | POSTING_READ_FW(CURCNTR(PIPE_A)); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9836 | |
| 9837 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 9838 | } |
| 9839 | |
| 9840 | static void i845_disable_cursor(struct intel_plane *plane, |
| 9841 | struct intel_crtc *crtc) |
| 9842 | { |
| 9843 | i845_update_cursor(plane, NULL, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9844 | } |
| 9845 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9846 | static bool i845_cursor_get_hw_state(struct intel_plane *plane, |
| 9847 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9848 | { |
| 9849 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9850 | enum intel_display_power_domain power_domain; |
| 9851 | bool ret; |
| 9852 | |
| 9853 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
| 9854 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9855 | return false; |
| 9856 | |
| 9857 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 9858 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9859 | *pipe = PIPE_A; |
| 9860 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 9861 | intel_display_power_put(dev_priv, power_domain); |
| 9862 | |
| 9863 | return ret; |
| 9864 | } |
| 9865 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 9866 | static unsigned int |
| 9867 | i9xx_cursor_max_stride(struct intel_plane *plane, |
| 9868 | u32 pixel_format, u64 modifier, |
| 9869 | unsigned int rotation) |
| 9870 | { |
| 9871 | return plane->base.dev->mode_config.cursor_width * 4; |
| 9872 | } |
| 9873 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9874 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9875 | const struct intel_plane_state *plane_state) |
| 9876 | { |
| 9877 | struct drm_i915_private *dev_priv = |
| 9878 | to_i915(plane_state->base.plane->dev); |
| 9879 | 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] | 9880 | u32 cntl = 0; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9881 | |
Ville Syrjälä | e876b78 | 2018-01-30 22:38:05 +0200 | [diff] [blame] | 9882 | if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
| 9883 | cntl |= MCURSOR_TRICKLE_FEED_DISABLE; |
| 9884 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9885 | if (INTEL_GEN(dev_priv) <= 10) { |
| 9886 | cntl |= MCURSOR_GAMMA_ENABLE; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9887 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9888 | if (HAS_DDI(dev_priv)) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9889 | cntl |= MCURSOR_PIPE_CSC_ENABLE; |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 9890 | } |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9891 | |
Ville Syrjälä | 32ea06b | 2018-01-30 22:38:01 +0200 | [diff] [blame] | 9892 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 9893 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9894 | |
| 9895 | switch (plane_state->base.crtc_w) { |
| 9896 | case 64: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9897 | cntl |= MCURSOR_MODE_64_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9898 | break; |
| 9899 | case 128: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9900 | cntl |= MCURSOR_MODE_128_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9901 | break; |
| 9902 | case 256: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9903 | cntl |= MCURSOR_MODE_256_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9904 | break; |
| 9905 | default: |
| 9906 | MISSING_CASE(plane_state->base.crtc_w); |
| 9907 | return 0; |
| 9908 | } |
| 9909 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 9910 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 9911 | cntl |= MCURSOR_ROTATE_180; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9912 | |
| 9913 | return cntl; |
| 9914 | } |
| 9915 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9916 | 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] | 9917 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9918 | struct drm_i915_private *dev_priv = |
| 9919 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9920 | int width = plane_state->base.crtc_w; |
| 9921 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9922 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9923 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9924 | return false; |
| 9925 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9926 | /* Cursor width is limited to a few power-of-two sizes */ |
| 9927 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9928 | case 256: |
| 9929 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9930 | case 64: |
| 9931 | break; |
| 9932 | default: |
| 9933 | return false; |
| 9934 | } |
| 9935 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9936 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9937 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 9938 | * height from 8 lines up to the cursor width, when the |
| 9939 | * cursor is not rotated. Everything else requires square |
| 9940 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9941 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9942 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9943 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9944 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9945 | return false; |
| 9946 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 9947 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9948 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9949 | } |
| 9950 | |
| 9951 | return true; |
| 9952 | } |
| 9953 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9954 | static int i9xx_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9955 | struct intel_plane_state *plane_state) |
| 9956 | { |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9957 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9958 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 9959 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9960 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9961 | int ret; |
| 9962 | |
| 9963 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9964 | if (ret) |
| 9965 | return ret; |
| 9966 | |
| 9967 | /* 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] | 9968 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9969 | return 0; |
| 9970 | |
| 9971 | /* Check for which cursor types we support */ |
| 9972 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 9973 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9974 | plane_state->base.crtc_w, |
| 9975 | plane_state->base.crtc_h); |
| 9976 | return -EINVAL; |
| 9977 | } |
| 9978 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9979 | WARN_ON(plane_state->base.visible && |
| 9980 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 9981 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9982 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 9983 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 9984 | fb->pitches[0], plane_state->base.crtc_w); |
| 9985 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9986 | } |
| 9987 | |
| 9988 | /* |
| 9989 | * There's something wrong with the cursor on CHV pipe C. |
| 9990 | * If it straddles the left edge of the screen then |
| 9991 | * moving it away from the edge or disabling it often |
| 9992 | * results in a pipe underrun, and often that can lead to |
| 9993 | * dead pipe (constant underrun reported, and it scans |
| 9994 | * out just a solid color). To recover from that, the |
| 9995 | * display power well must be turned off and on again. |
| 9996 | * Refuse the put the cursor into that compromised position. |
| 9997 | */ |
| 9998 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 9999 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 10000 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 10001 | return -EINVAL; |
| 10002 | } |
| 10003 | |
| 10004 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 10005 | |
| 10006 | return 0; |
| 10007 | } |
| 10008 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10009 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 10010 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10011 | const struct intel_plane_state *plane_state) |
| 10012 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10013 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10014 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10015 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10016 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10017 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10018 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 10019 | cntl = plane_state->ctl; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10020 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10021 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 10022 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 10023 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10024 | base = intel_cursor_base(plane_state); |
| 10025 | pos = intel_cursor_position(plane_state); |
| 10026 | } |
| 10027 | |
| 10028 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10029 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10030 | /* |
| 10031 | * On some platforms writing CURCNTR first will also |
| 10032 | * cause CURPOS to be armed by the CURBASE write. |
| 10033 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10034 | * arm itself. Thus we always start the full update |
| 10035 | * with a CURCNTR write. |
| 10036 | * |
| 10037 | * On other platforms CURPOS always requires the |
| 10038 | * CURBASE write to arm the update. Additonally |
| 10039 | * a write to any of the cursor register will cancel |
| 10040 | * an already armed cursor update. Thus leaving out |
| 10041 | * the CURBASE write after CURPOS could lead to a |
| 10042 | * cursor that doesn't appear to move, or even change |
| 10043 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10044 | * |
| 10045 | * CURCNTR and CUR_FBC_CTL are always |
| 10046 | * armed by the CURBASE write only. |
| 10047 | */ |
| 10048 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10049 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10050 | plane->cursor.cntl != cntl) { |
| 10051 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
| 10052 | if (HAS_CUR_FBC(dev_priv)) |
| 10053 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
| 10054 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10055 | I915_WRITE_FW(CURBASE(pipe), base); |
| 10056 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10057 | plane->cursor.base = base; |
| 10058 | plane->cursor.size = fbc_ctl; |
| 10059 | plane->cursor.cntl = cntl; |
| 10060 | } else { |
| 10061 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10062 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10063 | } |
| 10064 | |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10065 | POSTING_READ_FW(CURBASE(pipe)); |
| 10066 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10067 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10068 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10069 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10070 | static void i9xx_disable_cursor(struct intel_plane *plane, |
| 10071 | struct intel_crtc *crtc) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10072 | { |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10073 | i9xx_update_cursor(plane, NULL, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10074 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 10075 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10076 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane, |
| 10077 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10078 | { |
| 10079 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10080 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10081 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10082 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10083 | |
| 10084 | /* |
| 10085 | * Not 100% correct for planes that can move between pipes, |
| 10086 | * but that's only the case for gen2-3 which don't have any |
| 10087 | * display power wells. |
| 10088 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10089 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10090 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10091 | return false; |
| 10092 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10093 | val = I915_READ(CURCNTR(plane->pipe)); |
| 10094 | |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10095 | ret = val & MCURSOR_MODE; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10096 | |
| 10097 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 10098 | *pipe = plane->pipe; |
| 10099 | else |
| 10100 | *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >> |
| 10101 | MCURSOR_PIPE_SELECT_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10102 | |
| 10103 | intel_display_power_put(dev_priv, power_domain); |
| 10104 | |
| 10105 | return ret; |
| 10106 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10107 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10108 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10109 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10110 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10111 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10112 | }; |
| 10113 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10114 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10115 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 10116 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10117 | { |
| 10118 | struct intel_framebuffer *intel_fb; |
| 10119 | int ret; |
| 10120 | |
| 10121 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10122 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10123 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10124 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10125 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10126 | if (ret) |
| 10127 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10128 | |
| 10129 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10130 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10131 | err: |
| 10132 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10133 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10134 | } |
| 10135 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10136 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 10137 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10138 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10139 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10140 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10141 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10142 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10143 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10144 | if (ret) |
| 10145 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10146 | |
| 10147 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 10148 | if (plane_state->crtc != crtc) |
| 10149 | continue; |
| 10150 | |
| 10151 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 10152 | if (ret) |
| 10153 | return ret; |
| 10154 | |
| 10155 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 10156 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10157 | |
| 10158 | return 0; |
| 10159 | } |
| 10160 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10161 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10162 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10163 | struct intel_load_detect_pipe *old, |
| 10164 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10165 | { |
| 10166 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10167 | struct intel_encoder *intel_encoder = |
| 10168 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10169 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10170 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10171 | struct drm_crtc *crtc = NULL; |
| 10172 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10173 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10174 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10175 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10176 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10177 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10178 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10179 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10180 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10181 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10182 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10183 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10184 | old->restore_state = NULL; |
| 10185 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10186 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10187 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10188 | /* |
| 10189 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10190 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10191 | * - if the connector already has an assigned crtc, use it (but make |
| 10192 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10193 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10194 | * - try to find the first unused crtc that can drive this connector, |
| 10195 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10196 | */ |
| 10197 | |
| 10198 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10199 | if (connector->state->crtc) { |
| 10200 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10201 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10202 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10203 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10204 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10205 | |
| 10206 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10207 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10208 | } |
| 10209 | |
| 10210 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10211 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10212 | i++; |
| 10213 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10214 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10215 | |
| 10216 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10217 | if (ret) |
| 10218 | goto fail; |
| 10219 | |
| 10220 | if (possible_crtc->state->enable) { |
| 10221 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10222 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10223 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10224 | |
| 10225 | crtc = possible_crtc; |
| 10226 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10227 | } |
| 10228 | |
| 10229 | /* |
| 10230 | * If we didn't find an unused CRTC, don't use any. |
| 10231 | */ |
| 10232 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10233 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10234 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10235 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10236 | } |
| 10237 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10238 | found: |
| 10239 | intel_crtc = to_intel_crtc(crtc); |
| 10240 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10241 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10242 | restore_state = drm_atomic_state_alloc(dev); |
| 10243 | if (!state || !restore_state) { |
| 10244 | ret = -ENOMEM; |
| 10245 | goto fail; |
| 10246 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10247 | |
| 10248 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10249 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10250 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10251 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10252 | if (IS_ERR(connector_state)) { |
| 10253 | ret = PTR_ERR(connector_state); |
| 10254 | goto fail; |
| 10255 | } |
| 10256 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10257 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10258 | if (ret) |
| 10259 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10260 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10261 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10262 | if (IS_ERR(crtc_state)) { |
| 10263 | ret = PTR_ERR(crtc_state); |
| 10264 | goto fail; |
| 10265 | } |
| 10266 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10267 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10268 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10269 | if (!mode) |
| 10270 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10271 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10272 | 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] | 10273 | if (ret) |
| 10274 | goto fail; |
| 10275 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10276 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10277 | if (ret) |
| 10278 | goto fail; |
| 10279 | |
| 10280 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10281 | if (!ret) |
| 10282 | 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] | 10283 | if (!ret) |
| 10284 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10285 | if (ret) { |
| 10286 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10287 | goto fail; |
| 10288 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10289 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10290 | ret = drm_atomic_commit(state); |
| 10291 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10292 | 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] | 10293 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10294 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10295 | |
| 10296 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10297 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10298 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10299 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10300 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10301 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10302 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10303 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10304 | if (state) { |
| 10305 | drm_atomic_state_put(state); |
| 10306 | state = NULL; |
| 10307 | } |
| 10308 | if (restore_state) { |
| 10309 | drm_atomic_state_put(restore_state); |
| 10310 | restore_state = NULL; |
| 10311 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10312 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10313 | if (ret == -EDEADLK) |
| 10314 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10315 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10316 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10317 | } |
| 10318 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10319 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10320 | struct intel_load_detect_pipe *old, |
| 10321 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10322 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10323 | struct intel_encoder *intel_encoder = |
| 10324 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10325 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10326 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10327 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10328 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10329 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10330 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10331 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10332 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10333 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10334 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10335 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10336 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10337 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10338 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10339 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10340 | } |
| 10341 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10342 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10343 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10344 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10345 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10346 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10347 | |
| 10348 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10349 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10350 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10351 | return 120000; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 10352 | else if (!IS_GEN2(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10353 | return 96000; |
| 10354 | else |
| 10355 | return 48000; |
| 10356 | } |
| 10357 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10358 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10359 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10360 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10361 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10362 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10363 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10364 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10365 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10366 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10367 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10368 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10369 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10370 | |
| 10371 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10372 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10373 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10374 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10375 | |
| 10376 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10377 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10378 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10379 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10380 | } else { |
| 10381 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10382 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10383 | } |
| 10384 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 10385 | if (!IS_GEN2(dev_priv)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10386 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10387 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10388 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10389 | else |
| 10390 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10391 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10392 | |
| 10393 | switch (dpll & DPLL_MODE_MASK) { |
| 10394 | case DPLLB_MODE_DAC_SERIAL: |
| 10395 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10396 | 5 : 10; |
| 10397 | break; |
| 10398 | case DPLLB_MODE_LVDS: |
| 10399 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10400 | 7 : 14; |
| 10401 | break; |
| 10402 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10403 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10404 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10405 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10406 | } |
| 10407 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10408 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10409 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10410 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10411 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10412 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10413 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10414 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10415 | |
| 10416 | if (is_lvds) { |
| 10417 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10418 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10419 | |
| 10420 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10421 | clock.p2 = 7; |
| 10422 | else |
| 10423 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10424 | } else { |
| 10425 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10426 | clock.p1 = 2; |
| 10427 | else { |
| 10428 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10429 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10430 | } |
| 10431 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10432 | clock.p2 = 4; |
| 10433 | else |
| 10434 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10435 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10436 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10437 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10438 | } |
| 10439 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10440 | /* |
| 10441 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10442 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10443 | * encoder's get_config() function. |
| 10444 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10445 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10446 | } |
| 10447 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10448 | int intel_dotclock_calculate(int link_freq, |
| 10449 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10450 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10451 | /* |
| 10452 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10453 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10454 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10455 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10456 | * |
| 10457 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10458 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10459 | */ |
| 10460 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10461 | if (!m_n->link_n) |
| 10462 | return 0; |
| 10463 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10464 | 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] | 10465 | } |
| 10466 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10467 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10468 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10469 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10470 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10471 | |
| 10472 | /* read out port_clock from the DPLL */ |
| 10473 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10474 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10475 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10476 | * In case there is an active pipe without active ports, |
| 10477 | * we may need some idea for the dotclock anyway. |
| 10478 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10479 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10480 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10481 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10482 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10483 | } |
| 10484 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10485 | /* Returns the currently programmed mode of the given encoder. */ |
| 10486 | struct drm_display_mode * |
| 10487 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10488 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10489 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10490 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10491 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10492 | struct intel_crtc *crtc; |
| 10493 | enum pipe pipe; |
| 10494 | |
| 10495 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10496 | return NULL; |
| 10497 | |
| 10498 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10499 | |
| 10500 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10501 | if (!mode) |
| 10502 | return NULL; |
| 10503 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10504 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10505 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10506 | kfree(mode); |
| 10507 | return NULL; |
| 10508 | } |
| 10509 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10510 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10511 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10512 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10513 | kfree(crtc_state); |
| 10514 | kfree(mode); |
| 10515 | return NULL; |
| 10516 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10517 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10518 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10519 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10520 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10521 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10522 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10523 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10524 | return mode; |
| 10525 | } |
| 10526 | |
| 10527 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10528 | { |
| 10529 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10530 | |
| 10531 | drm_crtc_cleanup(crtc); |
| 10532 | kfree(intel_crtc); |
| 10533 | } |
| 10534 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10535 | /** |
| 10536 | * intel_wm_need_update - Check whether watermarks need updating |
| 10537 | * @plane: drm plane |
| 10538 | * @state: new plane state |
| 10539 | * |
| 10540 | * Check current plane state versus the new one to determine whether |
| 10541 | * watermarks need to be recalculated. |
| 10542 | * |
| 10543 | * Returns true or false. |
| 10544 | */ |
| 10545 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 10546 | struct drm_plane_state *state) |
| 10547 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10548 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 10549 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 10550 | |
| 10551 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10552 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10553 | return true; |
| 10554 | |
| 10555 | if (!cur->base.fb || !new->base.fb) |
| 10556 | return false; |
| 10557 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10558 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10559 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10560 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10561 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10562 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10563 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10564 | return true; |
| 10565 | |
| 10566 | return false; |
| 10567 | } |
| 10568 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10569 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10570 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10571 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10572 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10573 | int dst_w = drm_rect_width(&state->base.dst); |
| 10574 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10575 | |
| 10576 | return (src_w != dst_w || src_h != dst_h); |
| 10577 | } |
| 10578 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10579 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10580 | struct drm_crtc_state *crtc_state, |
| 10581 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10582 | struct drm_plane_state *plane_state) |
| 10583 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10584 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10585 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10586 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10587 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10588 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10589 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10590 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10591 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10592 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10593 | bool turn_off, turn_on, visible, was_visible; |
| 10594 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10595 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10596 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10597 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10598 | ret = skl_update_scaler_plane( |
| 10599 | to_intel_crtc_state(crtc_state), |
| 10600 | to_intel_plane_state(plane_state)); |
| 10601 | if (ret) |
| 10602 | return ret; |
| 10603 | } |
| 10604 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10605 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10606 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10607 | |
| 10608 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10609 | was_visible = false; |
| 10610 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10611 | /* |
| 10612 | * Visibility is calculated as if the crtc was on, but |
| 10613 | * after scaler setup everything depends on it being off |
| 10614 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10615 | * |
| 10616 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10617 | * be computed as if the pipe would be active. Perhaps move |
| 10618 | * per-plane wm computation to the .check_plane() hook, and |
| 10619 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10620 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10621 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10622 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10623 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10624 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10625 | |
| 10626 | if (!was_visible && !visible) |
| 10627 | return 0; |
| 10628 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10629 | if (fb != old_plane_state->base.fb) |
| 10630 | pipe_config->fb_changed = true; |
| 10631 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10632 | turn_off = was_visible && (!visible || mode_changed); |
| 10633 | turn_on = visible && (!was_visible || mode_changed); |
| 10634 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10635 | 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] | 10636 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 10637 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10638 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10639 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10640 | 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] | 10641 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10642 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10643 | turn_off, turn_on, mode_changed); |
| 10644 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10645 | if (turn_on) { |
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 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10648 | |
| 10649 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10650 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10651 | pipe_config->disable_cxsr = true; |
| 10652 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10653 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10654 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10655 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10656 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10657 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10658 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10659 | } else if (intel_wm_need_update(&plane->base, plane_state)) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10660 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10661 | /* FIXME bollocks */ |
| 10662 | pipe_config->update_wm_pre = true; |
| 10663 | pipe_config->update_wm_post = true; |
| 10664 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10665 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10666 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 10667 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10668 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10669 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10670 | /* |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10671 | * ILK/SNB DVSACNTR/Sprite Enable |
| 10672 | * IVB SPR_CTL/Sprite Enable |
| 10673 | * "When in Self Refresh Big FIFO mode, a write to enable the |
| 10674 | * plane will be internally buffered and delayed while Big FIFO |
| 10675 | * mode is exiting." |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10676 | * |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10677 | * Which means that enabling the sprite can take an extra frame |
| 10678 | * when we start in big FIFO mode (LP1+). Thus we need to drop |
| 10679 | * down to LP0 and wait for vblank in order to make sure the |
| 10680 | * sprite gets enabled on the next vblank after the register write. |
| 10681 | * Doing otherwise would risk enabling the sprite one frame after |
| 10682 | * we've already signalled flip completion. We can resume LP1+ |
| 10683 | * once the sprite has been enabled. |
| 10684 | * |
| 10685 | * |
| 10686 | * WaCxSRDisabledForSpriteScaling:ivb |
| 10687 | * IVB SPR_SCALE/Scaling Enable |
| 10688 | * "Low Power watermarks must be disabled for at least one |
| 10689 | * frame before enabling sprite scaling, and kept disabled |
| 10690 | * until sprite scaling is disabled." |
| 10691 | * |
| 10692 | * ILK/SNB DVSASCALE/Scaling Enable |
| 10693 | * "When in Self Refresh Big FIFO mode, scaling enable will be |
| 10694 | * masked off while Big FIFO mode is exiting." |
| 10695 | * |
| 10696 | * Despite the w/a only being listed for IVB we assume that |
| 10697 | * the ILK/SNB note has similar ramifications, hence we apply |
| 10698 | * the w/a on all three platforms. |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10699 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10700 | if (plane->id == PLANE_SPRITE0 && |
| 10701 | (IS_GEN5(dev_priv) || IS_GEN6(dev_priv) || |
| 10702 | IS_IVYBRIDGE(dev_priv)) && |
| 10703 | (turn_on || (!needs_scaling(old_plane_state) && |
| 10704 | needs_scaling(to_intel_plane_state(plane_state))))) |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10705 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10706 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10707 | return 0; |
| 10708 | } |
| 10709 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10710 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10711 | const struct intel_encoder *b) |
| 10712 | { |
| 10713 | /* masks could be asymmetric, so check both ways */ |
| 10714 | return a == b || (a->cloneable & (1 << b->type) && |
| 10715 | b->cloneable & (1 << a->type)); |
| 10716 | } |
| 10717 | |
| 10718 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 10719 | struct intel_crtc *crtc, |
| 10720 | struct intel_encoder *encoder) |
| 10721 | { |
| 10722 | struct intel_encoder *source_encoder; |
| 10723 | struct drm_connector *connector; |
| 10724 | struct drm_connector_state *connector_state; |
| 10725 | int i; |
| 10726 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10727 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10728 | if (connector_state->crtc != &crtc->base) |
| 10729 | continue; |
| 10730 | |
| 10731 | source_encoder = |
| 10732 | to_intel_encoder(connector_state->best_encoder); |
| 10733 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10734 | return false; |
| 10735 | } |
| 10736 | |
| 10737 | return true; |
| 10738 | } |
| 10739 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10740 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 10741 | struct drm_crtc_state *crtc_state) |
| 10742 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10743 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10744 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10745 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 10746 | struct intel_crtc_state *pipe_config = |
| 10747 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10748 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 10749 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10750 | bool mode_changed = needs_modeset(crtc_state); |
| 10751 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10752 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10753 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 10754 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10755 | if (mode_changed && crtc_state->enable && |
| 10756 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10757 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 10758 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 10759 | pipe_config); |
| 10760 | if (ret) |
| 10761 | return ret; |
| 10762 | } |
| 10763 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10764 | if (crtc_state->color_mgmt_changed) { |
| 10765 | ret = intel_color_check(crtc, crtc_state); |
| 10766 | if (ret) |
| 10767 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 10768 | |
| 10769 | /* |
| 10770 | * Changing color management on Intel hardware is |
| 10771 | * handled as part of planes update. |
| 10772 | */ |
| 10773 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 10774 | } |
| 10775 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10776 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10777 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 10778 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10779 | if (ret) { |
| 10780 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10781 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10782 | } |
| 10783 | } |
| 10784 | |
| 10785 | if (dev_priv->display.compute_intermediate_wm && |
| 10786 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 10787 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 10788 | return 0; |
| 10789 | |
| 10790 | /* |
| 10791 | * Calculate 'intermediate' watermarks that satisfy both the |
| 10792 | * old state and the new state. We can program these |
| 10793 | * immediately. |
| 10794 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10795 | ret = dev_priv->display.compute_intermediate_wm(dev, |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10796 | intel_crtc, |
| 10797 | pipe_config); |
| 10798 | if (ret) { |
| 10799 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 10800 | return ret; |
| 10801 | } |
Ville Syrjälä | e3d5457 | 2016-05-13 10:10:42 -0700 | [diff] [blame] | 10802 | } else if (dev_priv->display.compute_intermediate_wm) { |
| 10803 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) |
| 10804 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 10805 | } |
| 10806 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10807 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10808 | if (mode_changed) |
| 10809 | ret = skl_update_scaler_crtc(pipe_config); |
| 10810 | |
| 10811 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 10812 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 10813 | pipe_config); |
| 10814 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 10815 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10816 | pipe_config); |
| 10817 | } |
| 10818 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 10819 | if (HAS_IPS(dev_priv)) |
| 10820 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 10821 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 10822 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10823 | } |
| 10824 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 10825 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10826 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10827 | }; |
| 10828 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10829 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 10830 | { |
| 10831 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10832 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10833 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10834 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 10835 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10836 | if (connector->base.state->crtc) |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 10837 | drm_connector_put(&connector->base); |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10838 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10839 | if (connector->base.encoder) { |
| 10840 | connector->base.state->best_encoder = |
| 10841 | connector->base.encoder; |
| 10842 | connector->base.state->crtc = |
| 10843 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 10844 | |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 10845 | drm_connector_get(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10846 | } else { |
| 10847 | connector->base.state->best_encoder = NULL; |
| 10848 | connector->base.state->crtc = NULL; |
| 10849 | } |
| 10850 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 10851 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10852 | } |
| 10853 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10854 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10855 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10856 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10857 | { |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10858 | const struct drm_display_info *info = &connector->base.display_info; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10859 | int bpp = pipe_config->pipe_bpp; |
| 10860 | |
| 10861 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10862 | connector->base.base.id, |
| 10863 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10864 | |
| 10865 | /* Don't use an invalid EDID bpc value */ |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10866 | if (info->bpc != 0 && info->bpc * 3 < bpp) { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10867 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10868 | bpp, info->bpc * 3); |
| 10869 | pipe_config->pipe_bpp = info->bpc * 3; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10870 | } |
| 10871 | |
Mario Kleiner | 196f954 | 2016-07-06 12:05:45 +0200 | [diff] [blame] | 10872 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 10873 | if (info->bpc == 0 && bpp > 24) { |
Mario Kleiner | 196f954 | 2016-07-06 12:05:45 +0200 | [diff] [blame] | 10874 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 10875 | bpp); |
| 10876 | pipe_config->pipe_bpp = 24; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10877 | } |
| 10878 | } |
| 10879 | |
| 10880 | static int |
| 10881 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10882 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10883 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10884 | 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] | 10885 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10886 | struct drm_connector *connector; |
| 10887 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10888 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10889 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10890 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 10891 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10892 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 10893 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 10894 | bpp = 12*3; |
| 10895 | else |
| 10896 | bpp = 8*3; |
| 10897 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10898 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10899 | pipe_config->pipe_bpp = bpp; |
| 10900 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10901 | state = pipe_config->base.state; |
| 10902 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10903 | /* Clamp display bpp to EDID value */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10904 | 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] | 10905 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10906 | continue; |
| 10907 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 10908 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 10909 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10910 | } |
| 10911 | |
| 10912 | return bpp; |
| 10913 | } |
| 10914 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10915 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10916 | { |
| 10917 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10918 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10919 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10920 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10921 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10922 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10923 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10924 | } |
| 10925 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10926 | static inline void |
| 10927 | 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] | 10928 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10929 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 10930 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10931 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 10932 | m_n->gmch_m, m_n->gmch_n, |
| 10933 | m_n->link_m, m_n->link_n, m_n->tu); |
| 10934 | } |
| 10935 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10936 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 10937 | |
| 10938 | static const char * const output_type_str[] = { |
| 10939 | OUTPUT_TYPE(UNUSED), |
| 10940 | OUTPUT_TYPE(ANALOG), |
| 10941 | OUTPUT_TYPE(DVO), |
| 10942 | OUTPUT_TYPE(SDVO), |
| 10943 | OUTPUT_TYPE(LVDS), |
| 10944 | OUTPUT_TYPE(TVOUT), |
| 10945 | OUTPUT_TYPE(HDMI), |
| 10946 | OUTPUT_TYPE(DP), |
| 10947 | OUTPUT_TYPE(EDP), |
| 10948 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 10949 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10950 | OUTPUT_TYPE(DP_MST), |
| 10951 | }; |
| 10952 | |
| 10953 | #undef OUTPUT_TYPE |
| 10954 | |
| 10955 | static void snprintf_output_types(char *buf, size_t len, |
| 10956 | unsigned int output_types) |
| 10957 | { |
| 10958 | char *str = buf; |
| 10959 | int i; |
| 10960 | |
| 10961 | str[0] = '\0'; |
| 10962 | |
| 10963 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 10964 | int r; |
| 10965 | |
| 10966 | if ((output_types & BIT(i)) == 0) |
| 10967 | continue; |
| 10968 | |
| 10969 | r = snprintf(str, len, "%s%s", |
| 10970 | str != buf ? "," : "", output_type_str[i]); |
| 10971 | if (r >= len) |
| 10972 | break; |
| 10973 | str += r; |
| 10974 | len -= r; |
| 10975 | |
| 10976 | output_types &= ~BIT(i); |
| 10977 | } |
| 10978 | |
| 10979 | WARN_ON_ONCE(output_types != 0); |
| 10980 | } |
| 10981 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10982 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10983 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10984 | const char *context) |
| 10985 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10986 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 10987 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10988 | struct drm_plane *plane; |
| 10989 | struct intel_plane *intel_plane; |
| 10990 | struct intel_plane_state *state; |
| 10991 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10992 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10993 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 10994 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 10995 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10996 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 10997 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 10998 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 10999 | buf, pipe_config->output_types); |
| 11000 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11001 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 11002 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11003 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11004 | |
| 11005 | if (pipe_config->has_pch_encoder) |
| 11006 | intel_dump_m_n_config(pipe_config, "fdi", |
| 11007 | pipe_config->fdi_lanes, |
| 11008 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11009 | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 11010 | if (pipe_config->ycbcr420) |
| 11011 | DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n"); |
| 11012 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11013 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11014 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 11015 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 11016 | if (pipe_config->has_drrs) |
| 11017 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 11018 | pipe_config->lane_count, |
| 11019 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11020 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11021 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11022 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11023 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11024 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11025 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11026 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11027 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11028 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11029 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11030 | 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] | 11031 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11032 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 11033 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11034 | |
| 11035 | if (INTEL_GEN(dev_priv) >= 9) |
| 11036 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11037 | crtc->num_scalers, |
| 11038 | pipe_config->scaler_state.scaler_users, |
| 11039 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11040 | |
| 11041 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 11042 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11043 | pipe_config->gmch_pfit.control, |
| 11044 | pipe_config->gmch_pfit.pgm_ratios, |
| 11045 | pipe_config->gmch_pfit.lvds_border_bits); |
| 11046 | else |
| 11047 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 11048 | pipe_config->pch_pfit.pos, |
| 11049 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 11050 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11051 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11052 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 11053 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11054 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 11055 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11056 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11057 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11058 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11059 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11060 | intel_plane = to_intel_plane(plane); |
| 11061 | if (intel_plane->pipe != crtc->pipe) |
| 11062 | continue; |
| 11063 | |
| 11064 | state = to_intel_plane_state(plane->state); |
| 11065 | fb = state->base.fb; |
| 11066 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 11067 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 11068 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11069 | continue; |
| 11070 | } |
| 11071 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11072 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 11073 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11074 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 11075 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11076 | if (INTEL_GEN(dev_priv) >= 9) |
| 11077 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 11078 | state->scaler_id, |
| 11079 | state->base.src.x1 >> 16, |
| 11080 | state->base.src.y1 >> 16, |
| 11081 | drm_rect_width(&state->base.src) >> 16, |
| 11082 | drm_rect_height(&state->base.src) >> 16, |
| 11083 | state->base.dst.x1, state->base.dst.y1, |
| 11084 | drm_rect_width(&state->base.dst), |
| 11085 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11086 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11087 | } |
| 11088 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11089 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11090 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11091 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11092 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11093 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11094 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11095 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11096 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11097 | |
| 11098 | /* |
| 11099 | * Walk the connector list instead of the encoder |
| 11100 | * list to detect the problem on ddi platforms |
| 11101 | * where there's just one encoder per digital port. |
| 11102 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11103 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11104 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11105 | struct drm_connector_state *connector_state; |
| 11106 | struct intel_encoder *encoder; |
| 11107 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 11108 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11109 | if (!connector_state) |
| 11110 | connector_state = connector->state; |
| 11111 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11112 | if (!connector_state->best_encoder) |
| 11113 | continue; |
| 11114 | |
| 11115 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11116 | |
| 11117 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11118 | |
| 11119 | switch (encoder->type) { |
| 11120 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11121 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11122 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11123 | break; |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 11124 | /* else: fall through */ |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 11125 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11126 | case INTEL_OUTPUT_HDMI: |
| 11127 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11128 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11129 | |
| 11130 | /* the same port mustn't appear more than once */ |
| 11131 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11132 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11133 | |
| 11134 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11135 | break; |
| 11136 | case INTEL_OUTPUT_DP_MST: |
| 11137 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11138 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11139 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11140 | default: |
| 11141 | break; |
| 11142 | } |
| 11143 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11144 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11145 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11146 | /* can't mix MST and SST/HDMI on the same port */ |
| 11147 | if (used_ports & used_mst_ports) |
| 11148 | return false; |
| 11149 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11150 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11151 | } |
| 11152 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11153 | static void |
| 11154 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11155 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11156 | struct drm_i915_private *dev_priv = |
| 11157 | to_i915(crtc_state->base.crtc->dev); |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11158 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11159 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11160 | struct intel_shared_dpll *shared_dpll; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11161 | struct intel_crtc_wm_state wm_state; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11162 | bool force_thru, ips_force_disable; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11163 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 11164 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 11165 | * kzalloc'd. Code that depends on any field being zero should be |
| 11166 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 11167 | * only fields that are know to not cause problems are preserved. */ |
| 11168 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11169 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11170 | shared_dpll = crtc_state->shared_dpll; |
| 11171 | dpll_hw_state = crtc_state->dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11172 | force_thru = crtc_state->pch_pfit.force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11173 | ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11174 | if (IS_G4X(dev_priv) || |
| 11175 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11176 | wm_state = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11177 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11178 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 11179 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
| 11180 | memset(&crtc_state->base + 1, 0, |
| 11181 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11182 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11183 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11184 | crtc_state->shared_dpll = shared_dpll; |
| 11185 | crtc_state->dpll_hw_state = dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11186 | crtc_state->pch_pfit.force_thru = force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11187 | crtc_state->ips_force_disable = ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11188 | if (IS_G4X(dev_priv) || |
| 11189 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11190 | crtc_state->wm = wm_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11191 | } |
| 11192 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11193 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11194 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11195 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11196 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11197 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11198 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11199 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11200 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11201 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11202 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11203 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11204 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11205 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11206 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11207 | pipe_config->cpu_transcoder = |
| 11208 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11209 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11210 | /* |
| 11211 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11212 | * positive or negative polarity is requested, treat this as meaning |
| 11213 | * negative polarity. |
| 11214 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11215 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11216 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11217 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11218 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11219 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11220 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11221 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11222 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11223 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11224 | pipe_config); |
| 11225 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11226 | goto fail; |
| 11227 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11228 | /* |
| 11229 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11230 | * increase the actual pipe size due to the frame doubling and |
| 11231 | * insertion of additional space for blanks between the frame. This |
| 11232 | * is stored in the crtc timings. We use the requested mode to do this |
| 11233 | * computation to clearly distinguish it from the adjusted mode, which |
| 11234 | * can be changed by the connectors in the below retry loop. |
| 11235 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 11236 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11237 | &pipe_config->pipe_src_w, |
| 11238 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11239 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11240 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11241 | if (connector_state->crtc != crtc) |
| 11242 | continue; |
| 11243 | |
| 11244 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11245 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11246 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11247 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 11248 | goto fail; |
| 11249 | } |
| 11250 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11251 | /* |
| 11252 | * Determine output_types before calling the .compute_config() |
| 11253 | * hooks so that the hooks can use this information safely. |
| 11254 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11255 | if (encoder->compute_output_type) |
| 11256 | pipe_config->output_types |= |
| 11257 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11258 | connector_state)); |
| 11259 | else |
| 11260 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11261 | } |
| 11262 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11263 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11264 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11265 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11266 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11267 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11268 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11269 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11270 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11271 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11272 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11273 | * adjust it according to limitations or connector properties, and also |
| 11274 | * a chance to reject the mode entirely. |
| 11275 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11276 | 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] | 11277 | if (connector_state->crtc != crtc) |
| 11278 | continue; |
| 11279 | |
| 11280 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11281 | |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 11282 | if (!(encoder->compute_config(encoder, pipe_config, connector_state))) { |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 11283 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11284 | goto fail; |
| 11285 | } |
| 11286 | } |
| 11287 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11288 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11289 | * done afterwards in case the encoder adjusts the mode. */ |
| 11290 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11291 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11292 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11293 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11294 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11295 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11296 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 11297 | goto fail; |
| 11298 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11299 | |
| 11300 | if (ret == RETRY) { |
| 11301 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 11302 | ret = -EINVAL; |
| 11303 | goto fail; |
| 11304 | } |
| 11305 | |
| 11306 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11307 | retry = false; |
| 11308 | goto encoder_retry; |
| 11309 | } |
| 11310 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11311 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11312 | * only enable it on 6bpc panels and when its not a compliance |
| 11313 | * test requesting 6bpc video pattern. |
| 11314 | */ |
| 11315 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11316 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11317 | 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] | 11318 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11319 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11320 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11321 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11322 | } |
| 11323 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11324 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11325 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11326 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11327 | |
| 11328 | if (clock1 == clock2) |
| 11329 | return true; |
| 11330 | |
| 11331 | if (!clock1 || !clock2) |
| 11332 | return false; |
| 11333 | |
| 11334 | diff = abs(clock1 - clock2); |
| 11335 | |
| 11336 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11337 | return true; |
| 11338 | |
| 11339 | return false; |
| 11340 | } |
| 11341 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11342 | static bool |
| 11343 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11344 | unsigned int m2, unsigned int n2, |
| 11345 | bool exact) |
| 11346 | { |
| 11347 | if (m == m2 && n == n2) |
| 11348 | return true; |
| 11349 | |
| 11350 | if (exact || !m || !n || !m2 || !n2) |
| 11351 | return false; |
| 11352 | |
| 11353 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11354 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11355 | if (n > n2) { |
| 11356 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11357 | m2 <<= 1; |
| 11358 | n2 <<= 1; |
| 11359 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11360 | } else if (n < n2) { |
| 11361 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11362 | m <<= 1; |
| 11363 | n <<= 1; |
| 11364 | } |
| 11365 | } |
| 11366 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11367 | if (n != n2) |
| 11368 | return false; |
| 11369 | |
| 11370 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11371 | } |
| 11372 | |
| 11373 | static bool |
| 11374 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11375 | struct intel_link_m_n *m2_n2, |
| 11376 | bool adjust) |
| 11377 | { |
| 11378 | if (m_n->tu == m2_n2->tu && |
| 11379 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11380 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11381 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11382 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11383 | if (adjust) |
| 11384 | *m2_n2 = *m_n; |
| 11385 | |
| 11386 | return true; |
| 11387 | } |
| 11388 | |
| 11389 | return false; |
| 11390 | } |
| 11391 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11392 | static void __printf(3, 4) |
| 11393 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11394 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11395 | struct va_format vaf; |
| 11396 | va_list args; |
| 11397 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11398 | va_start(args, format); |
| 11399 | vaf.fmt = format; |
| 11400 | vaf.va = &args; |
| 11401 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11402 | if (adjust) |
| 11403 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11404 | else |
| 11405 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11406 | |
| 11407 | va_end(args); |
| 11408 | } |
| 11409 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11410 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11411 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11412 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11413 | struct intel_crtc_state *pipe_config, |
| 11414 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11415 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11416 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11417 | bool fixup_inherited = adjust && |
| 11418 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11419 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11420 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11421 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11422 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11423 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11424 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11425 | current_config->name, \ |
| 11426 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11427 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11428 | } \ |
| 11429 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11430 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11431 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11432 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11433 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11434 | "(expected %i, found %i)\n", \ |
| 11435 | current_config->name, \ |
| 11436 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11437 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11438 | } \ |
| 11439 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11440 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11441 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11442 | if (current_config->name != pipe_config->name) { \ |
| 11443 | pipe_config_err(adjust, __stringify(name), \ |
| 11444 | "(expected %s, found %s)\n", \ |
| 11445 | yesno(current_config->name), \ |
| 11446 | yesno(pipe_config->name)); \ |
| 11447 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11448 | } \ |
| 11449 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11450 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11451 | /* |
| 11452 | * Checks state where we only read out the enabling, but not the entire |
| 11453 | * state itself (like full infoframes or ELD for audio). These states |
| 11454 | * require a full modeset on bootup to fix up. |
| 11455 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11456 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11457 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11458 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11459 | } else { \ |
| 11460 | pipe_config_err(adjust, __stringify(name), \ |
| 11461 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11462 | yesno(current_config->name), \ |
| 11463 | yesno(pipe_config->name)); \ |
| 11464 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11465 | } \ |
| 11466 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11467 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11468 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11469 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11470 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11471 | "(expected %p, found %p)\n", \ |
| 11472 | current_config->name, \ |
| 11473 | pipe_config->name); \ |
| 11474 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11475 | } \ |
| 11476 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11477 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11478 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11479 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11480 | &pipe_config->name,\ |
| 11481 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11482 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11483 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11484 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11485 | current_config->name.tu, \ |
| 11486 | current_config->name.gmch_m, \ |
| 11487 | current_config->name.gmch_n, \ |
| 11488 | current_config->name.link_m, \ |
| 11489 | current_config->name.link_n, \ |
| 11490 | pipe_config->name.tu, \ |
| 11491 | pipe_config->name.gmch_m, \ |
| 11492 | pipe_config->name.gmch_n, \ |
| 11493 | pipe_config->name.link_m, \ |
| 11494 | pipe_config->name.link_n); \ |
| 11495 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11496 | } \ |
| 11497 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11498 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 11499 | /* This is required for BDW+ where there is only one set of registers for |
| 11500 | * switching between high and low RR. |
| 11501 | * This macro can be used whenever a comparison has to be made between one |
| 11502 | * hw state and multiple sw state variables. |
| 11503 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11504 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11505 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11506 | &pipe_config->name, adjust) && \ |
| 11507 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 11508 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11509 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11510 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11511 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 11512 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11513 | current_config->name.tu, \ |
| 11514 | current_config->name.gmch_m, \ |
| 11515 | current_config->name.gmch_n, \ |
| 11516 | current_config->name.link_m, \ |
| 11517 | current_config->name.link_n, \ |
| 11518 | current_config->alt_name.tu, \ |
| 11519 | current_config->alt_name.gmch_m, \ |
| 11520 | current_config->alt_name.gmch_n, \ |
| 11521 | current_config->alt_name.link_m, \ |
| 11522 | current_config->alt_name.link_n, \ |
| 11523 | pipe_config->name.tu, \ |
| 11524 | pipe_config->name.gmch_m, \ |
| 11525 | pipe_config->name.gmch_n, \ |
| 11526 | pipe_config->name.link_m, \ |
| 11527 | pipe_config->name.link_n); \ |
| 11528 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11529 | } \ |
| 11530 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11531 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11532 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11533 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11534 | pipe_config_err(adjust, __stringify(name), \ |
| 11535 | "(%x) (expected %i, found %i)\n", \ |
| 11536 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11537 | current_config->name & (mask), \ |
| 11538 | pipe_config->name & (mask)); \ |
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) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11542 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11543 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11544 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11545 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11546 | "(expected %i, found %i)\n", \ |
| 11547 | current_config->name, \ |
| 11548 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11549 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11550 | } \ |
| 11551 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11552 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11553 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11554 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11555 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11556 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11557 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11558 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11559 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11560 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11561 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11562 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 11563 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11564 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11565 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11566 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11567 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11568 | if (current_config->has_drrs) |
| 11569 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 11570 | } else |
| 11571 | 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] | 11572 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11573 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 11574 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11575 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11576 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11577 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11578 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11579 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11580 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11581 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11582 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11583 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11584 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11585 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11586 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11587 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11588 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11589 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11590 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 11591 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 11592 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11593 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 11594 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11595 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 11596 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11597 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11598 | PIPE_CONF_CHECK_BOOL(ycbcr420); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11599 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11600 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11601 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11602 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11603 | DRM_MODE_FLAG_INTERLACE); |
| 11604 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11605 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11606 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11607 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11608 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11609 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11610 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11611 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11612 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11613 | DRM_MODE_FLAG_NVSYNC); |
| 11614 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11615 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11616 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 11617 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11618 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 11619 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11620 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11621 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11622 | if (!adjust) { |
| 11623 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11624 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 11625 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11626 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11627 | if (current_config->pch_pfit.enabled) { |
| 11628 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 11629 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 11630 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11631 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11632 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11633 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11634 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 11635 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11636 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11637 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11638 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11639 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11640 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11641 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11642 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11643 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 11644 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11645 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11646 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11647 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 11648 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 11649 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 11650 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 11651 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 11652 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 11653 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 11654 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 11655 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 11656 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 11657 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 11658 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 11659 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 11660 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 11661 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 11662 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 11663 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 11664 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 11665 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 11666 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 11667 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 11668 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 11669 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11670 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 11671 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 11672 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 11673 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11674 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11675 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11676 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11677 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11678 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11679 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 11680 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 11681 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11682 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11683 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11684 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11685 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11686 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11687 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11688 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11689 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11690 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11691 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11692 | } |
| 11693 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11694 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 11695 | const struct intel_crtc_state *pipe_config) |
| 11696 | { |
| 11697 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 11698 | 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] | 11699 | &pipe_config->fdi_m_n); |
| 11700 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 11701 | |
| 11702 | /* |
| 11703 | * FDI already provided one idea for the dotclock. |
| 11704 | * Yell if the encoder disagrees. |
| 11705 | */ |
| 11706 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 11707 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 11708 | fdi_dotclock, dotclock); |
| 11709 | } |
| 11710 | } |
| 11711 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11712 | static void verify_wm_state(struct drm_crtc *crtc, |
| 11713 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11714 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11715 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11716 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11717 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 11718 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 11719 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11720 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11721 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11722 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11723 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11724 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11725 | return; |
| 11726 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11727 | skl_pipe_wm_get_hw_state(crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 11728 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11729 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11730 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11731 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11732 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 11733 | if (INTEL_GEN(dev_priv) >= 11) |
| 11734 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 11735 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 11736 | sw_ddb->enabled_slices, |
| 11737 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11738 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 11739 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11740 | hw_plane_wm = &hw_wm.planes[plane]; |
| 11741 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11742 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11743 | /* Watermarks */ |
| 11744 | for (level = 0; level <= max_level; level++) { |
| 11745 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 11746 | &sw_plane_wm->wm[level])) |
| 11747 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11748 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11749 | 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", |
| 11750 | pipe_name(pipe), plane + 1, level, |
| 11751 | sw_plane_wm->wm[level].plane_en, |
| 11752 | sw_plane_wm->wm[level].plane_res_b, |
| 11753 | sw_plane_wm->wm[level].plane_res_l, |
| 11754 | hw_plane_wm->wm[level].plane_en, |
| 11755 | hw_plane_wm->wm[level].plane_res_b, |
| 11756 | hw_plane_wm->wm[level].plane_res_l); |
| 11757 | } |
| 11758 | |
| 11759 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 11760 | &sw_plane_wm->trans_wm)) { |
| 11761 | 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", |
| 11762 | pipe_name(pipe), plane + 1, |
| 11763 | sw_plane_wm->trans_wm.plane_en, |
| 11764 | sw_plane_wm->trans_wm.plane_res_b, |
| 11765 | sw_plane_wm->trans_wm.plane_res_l, |
| 11766 | hw_plane_wm->trans_wm.plane_en, |
| 11767 | hw_plane_wm->trans_wm.plane_res_b, |
| 11768 | hw_plane_wm->trans_wm.plane_res_l); |
| 11769 | } |
| 11770 | |
| 11771 | /* DDB */ |
| 11772 | hw_ddb_entry = &hw_ddb.plane[pipe][plane]; |
| 11773 | sw_ddb_entry = &sw_ddb->plane[pipe][plane]; |
| 11774 | |
| 11775 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 11776 | 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] | 11777 | pipe_name(pipe), plane + 1, |
| 11778 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 11779 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 11780 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11781 | } |
| 11782 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 11783 | /* |
| 11784 | * cursor |
| 11785 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 11786 | * allocation. In that case since the ddb allocation will be updated |
| 11787 | * once the plane becomes visible, we can skip this check |
| 11788 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 11789 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11790 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 11791 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11792 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11793 | /* Watermarks */ |
| 11794 | for (level = 0; level <= max_level; level++) { |
| 11795 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 11796 | &sw_plane_wm->wm[level])) |
| 11797 | continue; |
| 11798 | |
| 11799 | 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", |
| 11800 | pipe_name(pipe), level, |
| 11801 | sw_plane_wm->wm[level].plane_en, |
| 11802 | sw_plane_wm->wm[level].plane_res_b, |
| 11803 | sw_plane_wm->wm[level].plane_res_l, |
| 11804 | hw_plane_wm->wm[level].plane_en, |
| 11805 | hw_plane_wm->wm[level].plane_res_b, |
| 11806 | hw_plane_wm->wm[level].plane_res_l); |
| 11807 | } |
| 11808 | |
| 11809 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 11810 | &sw_plane_wm->trans_wm)) { |
| 11811 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 11812 | pipe_name(pipe), |
| 11813 | sw_plane_wm->trans_wm.plane_en, |
| 11814 | sw_plane_wm->trans_wm.plane_res_b, |
| 11815 | sw_plane_wm->trans_wm.plane_res_l, |
| 11816 | hw_plane_wm->trans_wm.plane_en, |
| 11817 | hw_plane_wm->trans_wm.plane_res_b, |
| 11818 | hw_plane_wm->trans_wm.plane_res_l); |
| 11819 | } |
| 11820 | |
| 11821 | /* DDB */ |
| 11822 | hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 11823 | sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
| 11824 | |
| 11825 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 11826 | 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] | 11827 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 11828 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 11829 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 11830 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11831 | } |
| 11832 | } |
| 11833 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11834 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11835 | verify_connector_state(struct drm_device *dev, |
| 11836 | struct drm_atomic_state *state, |
| 11837 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11838 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11839 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11840 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 11841 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11842 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11843 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11844 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11845 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11846 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11847 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11848 | continue; |
| 11849 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11850 | if (crtc) |
| 11851 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 11852 | |
| 11853 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11854 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11855 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 11856 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11857 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11858 | } |
| 11859 | |
| 11860 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11861 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11862 | { |
| 11863 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11864 | struct drm_connector *connector; |
| 11865 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 11866 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11867 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11868 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11869 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11870 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11871 | |
| 11872 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 11873 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11874 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11875 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11876 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 11877 | new_conn_state, i) { |
| 11878 | if (old_conn_state->best_encoder == &encoder->base) |
| 11879 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11880 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11881 | if (new_conn_state->best_encoder != &encoder->base) |
| 11882 | continue; |
| 11883 | found = enabled = true; |
| 11884 | |
| 11885 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11886 | encoder->base.crtc, |
| 11887 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11888 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 11889 | |
| 11890 | if (!found) |
| 11891 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11892 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11893 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11894 | "encoder's enabled state mismatch " |
| 11895 | "(expected %i, found %i)\n", |
| 11896 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11897 | |
| 11898 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11899 | bool active; |
| 11900 | |
| 11901 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11902 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11903 | "encoder detached but still enabled on pipe %c.\n", |
| 11904 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 11905 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11906 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11907 | } |
| 11908 | |
| 11909 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11910 | verify_crtc_state(struct drm_crtc *crtc, |
| 11911 | struct drm_crtc_state *old_crtc_state, |
| 11912 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11913 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11914 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11915 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11916 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11917 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11918 | struct intel_crtc_state *pipe_config, *sw_config; |
| 11919 | struct drm_atomic_state *old_state; |
| 11920 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11921 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11922 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 11923 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11924 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 11925 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 11926 | pipe_config->base.crtc = crtc; |
| 11927 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11928 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 11929 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11930 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11931 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11932 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 11933 | /* we keep both pipes enabled on 830 */ |
| 11934 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11935 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11936 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11937 | I915_STATE_WARN(new_crtc_state->active != active, |
| 11938 | "crtc active state doesn't match with hw state " |
| 11939 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11940 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11941 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 11942 | "transitional active state does not match atomic hw state " |
| 11943 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11944 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11945 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 11946 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11947 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11948 | active = encoder->get_hw_state(encoder, &pipe); |
| 11949 | I915_STATE_WARN(active != new_crtc_state->active, |
| 11950 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 11951 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11952 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11953 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 11954 | "Encoder connected to wrong pipe %c\n", |
| 11955 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11956 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 11957 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11958 | encoder->get_config(encoder, pipe_config); |
| 11959 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11960 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11961 | intel_crtc_compute_pixel_rate(pipe_config); |
| 11962 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11963 | if (!new_crtc_state->active) |
| 11964 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11965 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11966 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11967 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 11968 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11969 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11970 | pipe_config, false)) { |
| 11971 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 11972 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 11973 | "[hw state]"); |
| 11974 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 11975 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11976 | } |
| 11977 | } |
| 11978 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11979 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 11980 | intel_verify_planes(struct intel_atomic_state *state) |
| 11981 | { |
| 11982 | struct intel_plane *plane; |
| 11983 | const struct intel_plane_state *plane_state; |
| 11984 | int i; |
| 11985 | |
| 11986 | for_each_new_intel_plane_in_state(state, plane, |
| 11987 | plane_state, i) |
| 11988 | assert_plane(plane, plane_state->base.visible); |
| 11989 | } |
| 11990 | |
| 11991 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11992 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 11993 | struct intel_shared_dpll *pll, |
| 11994 | struct drm_crtc *crtc, |
| 11995 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11996 | { |
| 11997 | struct intel_dpll_hw_state dpll_hw_state; |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 11998 | unsigned int crtc_mask; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 11999 | bool active; |
| 12000 | |
| 12001 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12002 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 12003 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12004 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 12005 | 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] | 12006 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 12007 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12008 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12009 | "pll in active use but not on in sw tracking\n"); |
| 12010 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12011 | "pll is on but not used by any active crtc\n"); |
| 12012 | I915_STATE_WARN(pll->on != active, |
| 12013 | "pll on state mismatch (expected %i, found %i)\n", |
| 12014 | pll->on, active); |
| 12015 | } |
| 12016 | |
| 12017 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12018 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12019 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12020 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12021 | |
| 12022 | return; |
| 12023 | } |
| 12024 | |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12025 | crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12026 | |
| 12027 | if (new_state->active) |
| 12028 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 12029 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 12030 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12031 | else |
| 12032 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12033 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 12034 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12035 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12036 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12037 | "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] | 12038 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12039 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12040 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12041 | &dpll_hw_state, |
| 12042 | sizeof(dpll_hw_state)), |
| 12043 | "pll hw state mismatch\n"); |
| 12044 | } |
| 12045 | |
| 12046 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12047 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 12048 | struct drm_crtc_state *old_crtc_state, |
| 12049 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12050 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12051 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12052 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 12053 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 12054 | |
| 12055 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12056 | 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] | 12057 | |
| 12058 | if (old_state->shared_dpll && |
| 12059 | old_state->shared_dpll != new_state->shared_dpll) { |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12060 | unsigned int crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12061 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 12062 | |
| 12063 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12064 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 12065 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12066 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12067 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 12068 | pipe_name(drm_crtc_index(crtc))); |
| 12069 | } |
| 12070 | } |
| 12071 | |
| 12072 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12073 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12074 | struct drm_atomic_state *state, |
| 12075 | struct drm_crtc_state *old_state, |
| 12076 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12077 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12078 | if (!needs_modeset(new_state) && |
| 12079 | !to_intel_crtc_state(new_state)->update_pipe) |
| 12080 | return; |
| 12081 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12082 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12083 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12084 | verify_crtc_state(crtc, old_state, new_state); |
| 12085 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12086 | } |
| 12087 | |
| 12088 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12089 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12090 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12091 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12092 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12093 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12094 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12095 | 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] | 12096 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12097 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12098 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12099 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 12100 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12101 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12102 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12103 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12104 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12105 | } |
| 12106 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12107 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 12108 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12109 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12110 | |
| 12111 | /* |
| 12112 | * The scanline counter increments at the leading edge of hsync. |
| 12113 | * |
| 12114 | * On most platforms it starts counting from vtotal-1 on the |
| 12115 | * first active line. That means the scanline counter value is |
| 12116 | * always one less than what we would expect. Ie. just after |
| 12117 | * start of vblank, which also occurs at start of hsync (on the |
| 12118 | * last active line), the scanline counter will read vblank_start-1. |
| 12119 | * |
| 12120 | * On gen2 the scanline counter starts counting from 1 instead |
| 12121 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12122 | * to keep the value positive), instead of adding one. |
| 12123 | * |
| 12124 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12125 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12126 | * there's an extra 1 line difference. So we need to add two instead of |
| 12127 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 12128 | * |
| 12129 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 12130 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 12131 | * that means we can't tell whether we're in vblank or not while |
| 12132 | * we're on that particular line. We must still set scanline_offset |
| 12133 | * to 1 so that the vblank timestamps come out correct when we query |
| 12134 | * the scanline counter from within the vblank interrupt handler. |
| 12135 | * However if queried just before the start of vblank we'll get an |
| 12136 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12137 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12138 | if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12139 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12140 | int vtotal; |
| 12141 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12142 | vtotal = adjusted_mode->crtc_vtotal; |
| 12143 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12144 | vtotal /= 2; |
| 12145 | |
| 12146 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12147 | } else if (HAS_DDI(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 12148 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12149 | crtc->scanline_offset = 2; |
| 12150 | } else |
| 12151 | crtc->scanline_offset = 1; |
| 12152 | } |
| 12153 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12154 | 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] | 12155 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12156 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12157 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12158 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12159 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12160 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12161 | |
| 12162 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12163 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12164 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12165 | 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] | 12166 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12167 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12168 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12169 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12170 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12171 | continue; |
| 12172 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12173 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12174 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12175 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12176 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12177 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 12178 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12179 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12180 | } |
| 12181 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12182 | /* |
| 12183 | * This implements the workaround described in the "notes" section of the mode |
| 12184 | * set sequence documentation. When going from no pipes or single pipe to |
| 12185 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12186 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12187 | */ |
| 12188 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12189 | { |
| 12190 | struct drm_crtc_state *crtc_state; |
| 12191 | struct intel_crtc *intel_crtc; |
| 12192 | struct drm_crtc *crtc; |
| 12193 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12194 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12195 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12196 | int i; |
| 12197 | |
| 12198 | /* 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] | 12199 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12200 | intel_crtc = to_intel_crtc(crtc); |
| 12201 | |
| 12202 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12203 | continue; |
| 12204 | |
| 12205 | if (first_crtc_state) { |
| 12206 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12207 | break; |
| 12208 | } else { |
| 12209 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12210 | first_pipe = intel_crtc->pipe; |
| 12211 | } |
| 12212 | } |
| 12213 | |
| 12214 | /* No workaround needed? */ |
| 12215 | if (!first_crtc_state) |
| 12216 | return 0; |
| 12217 | |
| 12218 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12219 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12220 | struct intel_crtc_state *pipe_config; |
| 12221 | |
| 12222 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12223 | if (IS_ERR(pipe_config)) |
| 12224 | return PTR_ERR(pipe_config); |
| 12225 | |
| 12226 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12227 | |
| 12228 | if (!pipe_config->base.active || |
| 12229 | needs_modeset(&pipe_config->base)) |
| 12230 | continue; |
| 12231 | |
| 12232 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12233 | if (enabled_pipe != INVALID_PIPE) |
| 12234 | return 0; |
| 12235 | |
| 12236 | enabled_pipe = intel_crtc->pipe; |
| 12237 | } |
| 12238 | |
| 12239 | if (enabled_pipe != INVALID_PIPE) |
| 12240 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12241 | else if (other_crtc_state) |
| 12242 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12243 | |
| 12244 | return 0; |
| 12245 | } |
| 12246 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12247 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12248 | { |
| 12249 | struct drm_crtc *crtc; |
| 12250 | |
| 12251 | /* Add all pipes to the state */ |
| 12252 | for_each_crtc(state->dev, crtc) { |
| 12253 | struct drm_crtc_state *crtc_state; |
| 12254 | |
| 12255 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12256 | if (IS_ERR(crtc_state)) |
| 12257 | return PTR_ERR(crtc_state); |
| 12258 | } |
| 12259 | |
| 12260 | return 0; |
| 12261 | } |
| 12262 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12263 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12264 | { |
| 12265 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12266 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12267 | /* |
| 12268 | * Add all pipes to the state, and force |
| 12269 | * a modeset on all the active ones. |
| 12270 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12271 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12272 | struct drm_crtc_state *crtc_state; |
| 12273 | int ret; |
| 12274 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12275 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12276 | if (IS_ERR(crtc_state)) |
| 12277 | return PTR_ERR(crtc_state); |
| 12278 | |
| 12279 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12280 | continue; |
| 12281 | |
| 12282 | crtc_state->mode_changed = true; |
| 12283 | |
| 12284 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12285 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12286 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12287 | |
| 12288 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12289 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12290 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12291 | } |
| 12292 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12293 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12294 | } |
| 12295 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12296 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12297 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12298 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12299 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12300 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12301 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12302 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12303 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12304 | if (!check_digital_port_conflicts(state)) { |
| 12305 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12306 | return -EINVAL; |
| 12307 | } |
| 12308 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12309 | intel_state->modeset = true; |
| 12310 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12311 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12312 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12313 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12314 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12315 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12316 | intel_state->active_crtcs |= 1 << i; |
| 12317 | else |
| 12318 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12319 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12320 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12321 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12322 | } |
| 12323 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12324 | /* |
| 12325 | * See if the config requires any additional preparation, e.g. |
| 12326 | * to adjust global state with pipes off. We need to do this |
| 12327 | * here so we can get the modeset_pipe updated config for the new |
| 12328 | * mode set on this crtc. For other crtcs we need to use the |
| 12329 | * adjusted_mode bits in the crtc directly. |
| 12330 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12331 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12332 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12333 | if (ret < 0) |
| 12334 | return ret; |
| 12335 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12336 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12337 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12338 | * holding all the crtc locks, even if we don't end up |
| 12339 | * touching the hardware |
| 12340 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12341 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12342 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12343 | ret = intel_lock_all_pipes(state); |
| 12344 | if (ret < 0) |
| 12345 | return ret; |
| 12346 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12347 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12348 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12349 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12350 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12351 | ret = intel_modeset_all_pipes(state); |
| 12352 | if (ret < 0) |
| 12353 | return ret; |
| 12354 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12355 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12356 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12357 | intel_state->cdclk.logical.cdclk, |
| 12358 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12359 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12360 | intel_state->cdclk.logical.voltage_level, |
| 12361 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12362 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12363 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12364 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12365 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12366 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12367 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12368 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12369 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12370 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12371 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12372 | } |
| 12373 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12374 | /* |
| 12375 | * Handle calculation of various watermark data at the end of the atomic check |
| 12376 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12377 | * handlers to ensure that all derived state has been updated. |
| 12378 | */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12379 | static int calc_watermark_data(struct drm_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12380 | { |
| 12381 | struct drm_device *dev = state->dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12382 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12383 | |
| 12384 | /* Is there platform-specific watermark information to calculate? */ |
| 12385 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12386 | return dev_priv->display.compute_global_watermarks(state); |
| 12387 | |
| 12388 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12389 | } |
| 12390 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12391 | /** |
| 12392 | * intel_atomic_check - validate state object |
| 12393 | * @dev: drm device |
| 12394 | * @state: state to validate |
| 12395 | */ |
| 12396 | static int intel_atomic_check(struct drm_device *dev, |
| 12397 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12398 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12399 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12400 | 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] | 12401 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12402 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12403 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12404 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12405 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12406 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12407 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12408 | crtc_state, i) { |
| 12409 | if (crtc_state->mode.private_flags != |
| 12410 | old_crtc_state->mode.private_flags) |
| 12411 | crtc_state->mode_changed = true; |
| 12412 | } |
| 12413 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12414 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12415 | if (ret) |
| 12416 | return ret; |
| 12417 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12418 | 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] | 12419 | struct intel_crtc_state *pipe_config = |
| 12420 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12421 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12422 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12423 | continue; |
| 12424 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12425 | if (!crtc_state->enable) { |
| 12426 | any_ms = true; |
| 12427 | continue; |
| 12428 | } |
| 12429 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12430 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12431 | if (ret) { |
| 12432 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12433 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12434 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12435 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12436 | |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 12437 | if (i915_modparams.fastboot && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12438 | intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12439 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12440 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12441 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12442 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12443 | } |
| 12444 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12445 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12446 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12447 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12448 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12449 | needs_modeset(crtc_state) ? |
| 12450 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12451 | } |
| 12452 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12453 | if (any_ms) { |
| 12454 | ret = intel_modeset_checks(state); |
| 12455 | |
| 12456 | if (ret) |
| 12457 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12458 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12459 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12460 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12461 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12462 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12463 | if (ret) |
| 12464 | return ret; |
| 12465 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12466 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12467 | return calc_watermark_data(state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12468 | } |
| 12469 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12470 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12471 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12472 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12473 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12474 | } |
| 12475 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12476 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12477 | { |
| 12478 | struct drm_device *dev = crtc->base.dev; |
| 12479 | |
| 12480 | if (!dev->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 12481 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12482 | |
| 12483 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 12484 | } |
| 12485 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12486 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 12487 | struct drm_atomic_state *state, |
| 12488 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12489 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12490 | { |
| 12491 | struct drm_device *dev = crtc->dev; |
| 12492 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 12493 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12494 | 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] | 12495 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 12496 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12497 | struct intel_plane_state *new_plane_state = |
| 12498 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 12499 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12500 | |
| 12501 | if (modeset) { |
| 12502 | update_scanline_offset(intel_crtc); |
| 12503 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12504 | |
| 12505 | /* vblanks work again, re-enable pipe CRC. */ |
| 12506 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12507 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12508 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12509 | pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12510 | } |
| 12511 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12512 | if (new_plane_state) |
| 12513 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12514 | |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12515 | intel_begin_crtc_commit(crtc, old_crtc_state); |
| 12516 | |
| 12517 | intel_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc, |
| 12518 | old_intel_cstate, pipe_config); |
| 12519 | |
| 12520 | intel_finish_crtc_commit(crtc, old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12521 | } |
| 12522 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12523 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12524 | { |
| 12525 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12526 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12527 | int i; |
| 12528 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12529 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12530 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12531 | continue; |
| 12532 | |
| 12533 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12534 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12535 | } |
| 12536 | } |
| 12537 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12538 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12539 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12540 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12541 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 12542 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12543 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12544 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12545 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12546 | unsigned int updated = 0; |
| 12547 | bool progress; |
| 12548 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12549 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12550 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 12551 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12552 | |
| 12553 | const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {}; |
| 12554 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12555 | 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] | 12556 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12557 | if (new_crtc_state->active) |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12558 | entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12559 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12560 | /* If 2nd DBuf slice required, enable it here */ |
| 12561 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 12562 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 12563 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12564 | /* |
| 12565 | * Whenever the number of active pipes changes, we need to make sure we |
| 12566 | * update the pipes in the right order so that their ddb allocations |
| 12567 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 12568 | * cause pipe underruns and other bad stuff. |
| 12569 | */ |
| 12570 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12571 | progress = false; |
| 12572 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12573 | 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] | 12574 | bool vbl_wait = false; |
| 12575 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12576 | |
| 12577 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12578 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12579 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12580 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12581 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12582 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12583 | |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 12584 | if (skl_ddb_allocation_overlaps(dev_priv, |
| 12585 | entries, |
| 12586 | &cstate->wm.skl.ddb, |
| 12587 | i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12588 | continue; |
| 12589 | |
| 12590 | updated |= cmask; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12591 | entries[i] = &cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12592 | |
| 12593 | /* |
| 12594 | * If this is an already active pipe, it's DDB changed, |
| 12595 | * and this isn't the last pipe that needs updating |
| 12596 | * then we need to wait for a vblank to pass for the |
| 12597 | * new ddb allocation to take effect. |
| 12598 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12599 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 12600 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12601 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12602 | intel_state->wm_results.dirty_pipes != updated) |
| 12603 | vbl_wait = true; |
| 12604 | |
| 12605 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12606 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12607 | |
| 12608 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12609 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12610 | |
| 12611 | progress = true; |
| 12612 | } |
| 12613 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12614 | |
| 12615 | /* If 2nd DBuf slice is no more required disable it */ |
| 12616 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 12617 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12618 | } |
| 12619 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 12620 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 12621 | { |
| 12622 | struct intel_atomic_state *state, *next; |
| 12623 | struct llist_node *freed; |
| 12624 | |
| 12625 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 12626 | llist_for_each_entry_safe(state, next, freed, freed) |
| 12627 | drm_atomic_state_put(&state->base); |
| 12628 | } |
| 12629 | |
| 12630 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 12631 | { |
| 12632 | struct drm_i915_private *dev_priv = |
| 12633 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 12634 | |
| 12635 | intel_atomic_helper_free_state(dev_priv); |
| 12636 | } |
| 12637 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12638 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 12639 | { |
| 12640 | struct wait_queue_entry wait_fence, wait_reset; |
| 12641 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 12642 | |
| 12643 | init_wait_entry(&wait_fence, 0); |
| 12644 | init_wait_entry(&wait_reset, 0); |
| 12645 | for (;;) { |
| 12646 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 12647 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 12648 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 12649 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 12650 | |
| 12651 | |
| 12652 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 12653 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 12654 | break; |
| 12655 | |
| 12656 | schedule(); |
| 12657 | } |
| 12658 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 12659 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 12660 | } |
| 12661 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 12662 | static void intel_atomic_cleanup_work(struct work_struct *work) |
| 12663 | { |
| 12664 | struct drm_atomic_state *state = |
| 12665 | container_of(work, struct drm_atomic_state, commit_work); |
| 12666 | struct drm_i915_private *i915 = to_i915(state->dev); |
| 12667 | |
| 12668 | drm_atomic_helper_cleanup_planes(&i915->drm, state); |
| 12669 | drm_atomic_helper_commit_cleanup_done(state); |
| 12670 | drm_atomic_state_put(state); |
| 12671 | |
| 12672 | intel_atomic_helper_free_state(i915); |
| 12673 | } |
| 12674 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12675 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12676 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12677 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12678 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12679 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12680 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12681 | struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 12682 | struct drm_crtc *crtc; |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12683 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 12684 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 12685 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12686 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12687 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12688 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 12689 | drm_atomic_helper_wait_for_dependencies(state); |
| 12690 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12691 | if (intel_state->modeset) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12692 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12693 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12694 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12695 | old_intel_crtc_state = to_intel_crtc_state(old_crtc_state); |
| 12696 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 12697 | intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12698 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12699 | if (needs_modeset(new_crtc_state) || |
| 12700 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12701 | |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12702 | put_domains[intel_crtc->pipe] = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12703 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12704 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12705 | } |
| 12706 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12707 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12708 | continue; |
| 12709 | |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12710 | intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 12711 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 12712 | if (old_crtc_state->active) { |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 12713 | intel_crtc_disable_planes(intel_crtc, old_intel_crtc_state->active_planes); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12714 | |
| 12715 | /* |
| 12716 | * We need to disable pipe CRC before disabling the pipe, |
| 12717 | * or we race against vblank off. |
| 12718 | */ |
| 12719 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 12720 | |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12721 | dev_priv->display.crtc_disable(old_intel_crtc_state, state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12722 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 12723 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 12724 | intel_disable_shared_dpll(old_intel_crtc_state); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 12725 | |
| 12726 | /* |
| 12727 | * Underruns don't always raise |
| 12728 | * interrupts, so check manually. |
| 12729 | */ |
| 12730 | intel_check_cpu_fifo_underruns(dev_priv); |
| 12731 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 12732 | |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12733 | if (!new_crtc_state->active) { |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12734 | /* |
| 12735 | * Make sure we don't call initial_watermarks |
| 12736 | * for ILK-style watermark updates. |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 12737 | * |
| 12738 | * No clue what this is supposed to achieve. |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12739 | */ |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 12740 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12741 | dev_priv->display.initial_watermarks(intel_state, |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12742 | new_intel_crtc_state); |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 12743 | } |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12744 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12745 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12746 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 12747 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 12748 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 12749 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12750 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12751 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12752 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 12753 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 12754 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 12755 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12756 | /* |
| 12757 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 12758 | * have more then one pipe enabled |
| 12759 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 12760 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 12761 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12762 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12763 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12764 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 12765 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12766 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12767 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 12768 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 12769 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12770 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12771 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12772 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12773 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12774 | spin_unlock_irq(&dev->event_lock); |
| 12775 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12776 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 12777 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12778 | } |
| 12779 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12780 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12781 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12782 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12783 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 12784 | * already, but still need the state for the delayed optimization. To |
| 12785 | * fix this: |
| 12786 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 12787 | * - schedule that vblank worker _before_ calling hw_done |
| 12788 | * - at the start of commit_tail, cancel it _synchrously |
| 12789 | * - switch over to the vblank wait helper in the core after that since |
| 12790 | * we don't need out special handling any more. |
| 12791 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12792 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12793 | |
| 12794 | /* |
| 12795 | * Now that the vblank has passed, we can go ahead and program the |
| 12796 | * optimal watermarks on platforms that need two-step watermark |
| 12797 | * programming. |
| 12798 | * |
| 12799 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 12800 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12801 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12802 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12803 | |
| 12804 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 12805 | dev_priv->display.optimize_watermarks(intel_state, |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12806 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12807 | } |
| 12808 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12809 | 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] | 12810 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 12811 | |
| 12812 | if (put_domains[i]) |
| 12813 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 12814 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12815 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12816 | } |
| 12817 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12818 | if (intel_state->modeset) |
| 12819 | intel_verify_planes(intel_state); |
| 12820 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 12821 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 12822 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 12823 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12824 | drm_atomic_helper_commit_hw_done(state); |
| 12825 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 12826 | if (intel_state->modeset) { |
| 12827 | /* As one of the primary mmio accessors, KMS has a high |
| 12828 | * likelihood of triggering bugs in unclaimed access. After we |
| 12829 | * finish modesetting, see if an error has been flagged, and if |
| 12830 | * so enable debugging for the next modeset - and hope we catch |
| 12831 | * the culprit. |
| 12832 | */ |
| 12833 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12834 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 12835 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12836 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 12837 | /* |
| 12838 | * Defer the cleanup of the old state to a separate worker to not |
| 12839 | * impede the current task (userspace for blocking modesets) that |
| 12840 | * are executed inline. For out-of-line asynchronous modesets/flips, |
| 12841 | * deferring to a new worker seems overkill, but we would place a |
| 12842 | * schedule point (cond_resched()) here anyway to keep latencies |
| 12843 | * down. |
| 12844 | */ |
| 12845 | INIT_WORK(&state->commit_work, intel_atomic_cleanup_work); |
Chris Wilson | 41db645 | 2018-07-12 12:57:29 +0100 | [diff] [blame] | 12846 | queue_work(system_highpri_wq, &state->commit_work); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12847 | } |
| 12848 | |
| 12849 | static void intel_atomic_commit_work(struct work_struct *work) |
| 12850 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12851 | struct drm_atomic_state *state = |
| 12852 | container_of(work, struct drm_atomic_state, commit_work); |
| 12853 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12854 | intel_atomic_commit_tail(state); |
| 12855 | } |
| 12856 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12857 | static int __i915_sw_fence_call |
| 12858 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 12859 | enum i915_sw_fence_notify notify) |
| 12860 | { |
| 12861 | struct intel_atomic_state *state = |
| 12862 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 12863 | |
| 12864 | switch (notify) { |
| 12865 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12866 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12867 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12868 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 12869 | { |
| 12870 | struct intel_atomic_helper *helper = |
| 12871 | &to_i915(state->base.dev)->atomic_helper; |
| 12872 | |
| 12873 | if (llist_add(&state->freed, &helper->free_list)) |
| 12874 | schedule_work(&helper->free_work); |
| 12875 | break; |
| 12876 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12877 | } |
| 12878 | |
| 12879 | return NOTIFY_DONE; |
| 12880 | } |
| 12881 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12882 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 12883 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12884 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12885 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12886 | int i; |
| 12887 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12888 | 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] | 12889 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12890 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 12891 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12892 | } |
| 12893 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12894 | /** |
| 12895 | * intel_atomic_commit - commit validated state object |
| 12896 | * @dev: DRM device |
| 12897 | * @state: the top-level driver state object |
| 12898 | * @nonblock: nonblocking commit |
| 12899 | * |
| 12900 | * This function commits a top-level state object that has been validated |
| 12901 | * with drm_atomic_helper_check(). |
| 12902 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12903 | * RETURNS |
| 12904 | * Zero for success or -errno. |
| 12905 | */ |
| 12906 | static int intel_atomic_commit(struct drm_device *dev, |
| 12907 | struct drm_atomic_state *state, |
| 12908 | bool nonblock) |
| 12909 | { |
| 12910 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12911 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12912 | int ret = 0; |
| 12913 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12914 | drm_atomic_state_get(state); |
| 12915 | i915_sw_fence_init(&intel_state->commit_ready, |
| 12916 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12917 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 12918 | /* |
| 12919 | * The intel_legacy_cursor_update() fast path takes care |
| 12920 | * of avoiding the vblank waits for simple cursor |
| 12921 | * movement and flips. For cursor on/off and size changes, |
| 12922 | * we want to perform the vblank waits so that watermark |
| 12923 | * updates happen during the correct frames. Gen9+ have |
| 12924 | * double buffered watermarks and so shouldn't need this. |
| 12925 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 12926 | * Unset state->legacy_cursor_update before the call to |
| 12927 | * drm_atomic_helper_setup_commit() because otherwise |
| 12928 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 12929 | * we get FIFO underruns because we didn't wait |
| 12930 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 12931 | * |
| 12932 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 12933 | * (assuming we had any) would solve these problems. |
| 12934 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 12935 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 12936 | struct intel_crtc_state *new_crtc_state; |
| 12937 | struct intel_crtc *crtc; |
| 12938 | int i; |
| 12939 | |
| 12940 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 12941 | if (new_crtc_state->wm.need_postvbl_update || |
| 12942 | new_crtc_state->update_wm_post) |
| 12943 | state->legacy_cursor_update = false; |
| 12944 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 12945 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 12946 | ret = intel_atomic_prepare_commit(dev, state); |
| 12947 | if (ret) { |
| 12948 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 12949 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 12950 | return ret; |
| 12951 | } |
| 12952 | |
| 12953 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 12954 | if (!ret) |
| 12955 | ret = drm_atomic_helper_swap_state(state, true); |
| 12956 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 12957 | if (ret) { |
| 12958 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 12959 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 12960 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 12961 | return ret; |
| 12962 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12963 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 12964 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 12965 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12966 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12967 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 12968 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 12969 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12970 | memcpy(dev_priv->min_voltage_level, |
| 12971 | intel_state->min_voltage_level, |
| 12972 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12973 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12974 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 12975 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12976 | } |
| 12977 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 12978 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12979 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 12980 | |
| 12981 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 12982 | if (nonblock && intel_state->modeset) { |
| 12983 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 12984 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12985 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 12986 | } else { |
| 12987 | if (intel_state->modeset) |
| 12988 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12989 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 12990 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 12991 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12992 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 12993 | } |
| 12994 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12995 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 12996 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12997 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12998 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 12999 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13000 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13001 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 13002 | .set_crc_source = intel_crtc_set_crc_source, |
Mahesh Kumar | a8c2083 | 2018-07-13 19:29:38 +0530 | [diff] [blame] | 13003 | .verify_crc_source = intel_crtc_verify_crc_source, |
Mahesh Kumar | 260bc55 | 2018-07-13 19:29:39 +0530 | [diff] [blame] | 13004 | .get_crc_sources = intel_crtc_get_crc_sources, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13005 | }; |
| 13006 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13007 | struct wait_rps_boost { |
| 13008 | struct wait_queue_entry wait; |
| 13009 | |
| 13010 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13011 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13012 | }; |
| 13013 | |
| 13014 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 13015 | unsigned mode, int sync, void *key) |
| 13016 | { |
| 13017 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13018 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13019 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13020 | /* |
| 13021 | * If we missed the vblank, but the request is already running it |
| 13022 | * is reasonable to assume that it will complete before the next |
| 13023 | * vblank without our intervention, so leave RPS alone. |
| 13024 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13025 | if (!i915_request_started(rq)) |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13026 | gen6_rps_boost(rq, NULL); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13027 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13028 | |
| 13029 | drm_crtc_vblank_put(wait->crtc); |
| 13030 | |
| 13031 | list_del(&wait->wait.entry); |
| 13032 | kfree(wait); |
| 13033 | return 1; |
| 13034 | } |
| 13035 | |
| 13036 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 13037 | struct dma_fence *fence) |
| 13038 | { |
| 13039 | struct wait_rps_boost *wait; |
| 13040 | |
| 13041 | if (!dma_fence_is_i915(fence)) |
| 13042 | return; |
| 13043 | |
| 13044 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 13045 | return; |
| 13046 | |
| 13047 | if (drm_crtc_vblank_get(crtc)) |
| 13048 | return; |
| 13049 | |
| 13050 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 13051 | if (!wait) { |
| 13052 | drm_crtc_vblank_put(crtc); |
| 13053 | return; |
| 13054 | } |
| 13055 | |
| 13056 | wait->request = to_request(dma_fence_get(fence)); |
| 13057 | wait->crtc = crtc; |
| 13058 | |
| 13059 | wait->wait.func = do_rps_boost; |
| 13060 | wait->wait.flags = 0; |
| 13061 | |
| 13062 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 13063 | } |
| 13064 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13065 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 13066 | { |
| 13067 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 13068 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 13069 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 13070 | struct i915_vma *vma; |
| 13071 | |
| 13072 | if (plane->id == PLANE_CURSOR && |
| 13073 | INTEL_INFO(dev_priv)->cursor_needs_physical) { |
| 13074 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13075 | const int align = intel_cursor_alignment(dev_priv); |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13076 | int err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13077 | |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13078 | err = i915_gem_object_attach_phys(obj, align); |
| 13079 | if (err) |
| 13080 | return err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13081 | } |
| 13082 | |
| 13083 | vma = intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 13084 | &plane_state->view, |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13085 | intel_plane_uses_fence(plane_state), |
| 13086 | &plane_state->flags); |
| 13087 | if (IS_ERR(vma)) |
| 13088 | return PTR_ERR(vma); |
| 13089 | |
| 13090 | plane_state->vma = vma; |
| 13091 | |
| 13092 | return 0; |
| 13093 | } |
| 13094 | |
| 13095 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 13096 | { |
| 13097 | struct i915_vma *vma; |
| 13098 | |
| 13099 | vma = fetch_and_zero(&old_plane_state->vma); |
| 13100 | if (vma) |
| 13101 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 13102 | } |
| 13103 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 13104 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 13105 | { |
| 13106 | struct i915_sched_attr attr = { |
| 13107 | .priority = I915_PRIORITY_DISPLAY, |
| 13108 | }; |
| 13109 | |
| 13110 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 13111 | } |
| 13112 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13113 | /** |
| 13114 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13115 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13116 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13117 | * |
| 13118 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13119 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13120 | * bits. Some older platforms need special physical address handling for |
| 13121 | * cursor planes. |
| 13122 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13123 | * Must be called with struct_mutex held. |
| 13124 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13125 | * Returns 0 on success, negative error code on failure. |
| 13126 | */ |
| 13127 | int |
| 13128 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13129 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13130 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13131 | struct intel_atomic_state *intel_state = |
| 13132 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 13133 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13134 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13135 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13136 | 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] | 13137 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13138 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13139 | if (old_obj) { |
| 13140 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13141 | drm_atomic_get_new_crtc_state(new_state->state, |
| 13142 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13143 | |
| 13144 | /* Big Hammer, we also need to ensure that any pending |
| 13145 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13146 | * current scanout is retired before unpinning the old |
| 13147 | * framebuffer. Note that we rely on userspace rendering |
| 13148 | * into the buffer attached to the pipe they are waiting |
| 13149 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13150 | * point to the MI_WAIT_FOR_EVENT. |
| 13151 | * |
| 13152 | * This should only fail upon a hung GPU, in which case we |
| 13153 | * can safely continue. |
| 13154 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13155 | if (needs_modeset(crtc_state)) { |
| 13156 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13157 | old_obj->resv, NULL, |
| 13158 | false, 0, |
| 13159 | GFP_KERNEL); |
| 13160 | if (ret < 0) |
| 13161 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13162 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13163 | } |
| 13164 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13165 | if (new_state->fence) { /* explicit fencing */ |
| 13166 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 13167 | new_state->fence, |
| 13168 | I915_FENCE_TIMEOUT, |
| 13169 | GFP_KERNEL); |
| 13170 | if (ret < 0) |
| 13171 | return ret; |
| 13172 | } |
| 13173 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 13174 | if (!obj) |
| 13175 | return 0; |
| 13176 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13177 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13178 | if (ret) |
| 13179 | return ret; |
| 13180 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13181 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13182 | if (ret) { |
| 13183 | i915_gem_object_unpin_pages(obj); |
| 13184 | return ret; |
| 13185 | } |
| 13186 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13187 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13188 | |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13189 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13190 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13191 | if (ret) |
| 13192 | return ret; |
| 13193 | |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 13194 | fb_obj_bump_render_priority(obj); |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13195 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 13196 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13197 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13198 | struct dma_fence *fence; |
| 13199 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13200 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13201 | obj->resv, NULL, |
| 13202 | false, I915_FENCE_TIMEOUT, |
| 13203 | GFP_KERNEL); |
| 13204 | if (ret < 0) |
| 13205 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13206 | |
| 13207 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 13208 | if (fence) { |
| 13209 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 13210 | dma_fence_put(fence); |
| 13211 | } |
| 13212 | } else { |
| 13213 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13214 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13215 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13216 | /* |
| 13217 | * We declare pageflips to be interactive and so merit a small bias |
| 13218 | * towards upclocking to deliver the frame on time. By only changing |
| 13219 | * the RPS thresholds to sample more regularly and aim for higher |
| 13220 | * clocks we can hopefully deliver low power workloads (like kodi) |
| 13221 | * that are not quite steady state without resorting to forcing |
| 13222 | * maximum clocks following a vblank miss (see do_rps_boost()). |
| 13223 | */ |
| 13224 | if (!intel_state->rps_interactive) { |
| 13225 | intel_rps_mark_interactive(dev_priv, true); |
| 13226 | intel_state->rps_interactive = true; |
| 13227 | } |
| 13228 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 13229 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13230 | } |
| 13231 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13232 | /** |
| 13233 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13234 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13235 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13236 | * |
| 13237 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13238 | * |
| 13239 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13240 | */ |
| 13241 | void |
| 13242 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13243 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13244 | { |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13245 | struct intel_atomic_state *intel_state = |
| 13246 | to_intel_atomic_state(old_state->state); |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13247 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13248 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13249 | if (intel_state->rps_interactive) { |
| 13250 | intel_rps_mark_interactive(dev_priv, false); |
| 13251 | intel_state->rps_interactive = false; |
| 13252 | } |
| 13253 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 13254 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13255 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 13256 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 13257 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13258 | } |
| 13259 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13260 | int |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13261 | skl_max_scale(const struct intel_crtc_state *crtc_state, |
| 13262 | u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13263 | { |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13264 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 13265 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13266 | int max_scale, mult; |
| 13267 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13268 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13269 | if (!crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13270 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13271 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13272 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 13273 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 13274 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 13275 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13276 | max_dotclk *= 2; |
| 13277 | |
| 13278 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13279 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13280 | |
| 13281 | /* |
| 13282 | * skl max scale is lower of: |
| 13283 | * close to 3 but not 3, -1 is for that purpose |
| 13284 | * or |
| 13285 | * cdclk/crtc_clock |
| 13286 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13287 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 13288 | tmpclk1 = (1 << 16) * mult - 1; |
| 13289 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 13290 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13291 | |
| 13292 | return max_scale; |
| 13293 | } |
| 13294 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13295 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13296 | struct drm_crtc_state *old_crtc_state) |
| 13297 | { |
| 13298 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13299 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13300 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13301 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13302 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13303 | struct intel_atomic_state *old_intel_state = |
| 13304 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13305 | struct intel_crtc_state *intel_cstate = |
| 13306 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13307 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13308 | |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13309 | if (!modeset && |
| 13310 | (intel_cstate->base.color_mgmt_changed || |
| 13311 | intel_cstate->update_pipe)) { |
Ville Syrjälä | 5c857e6 | 2017-08-23 18:22:20 +0300 | [diff] [blame] | 13312 | intel_color_set_csc(&intel_cstate->base); |
| 13313 | intel_color_load_luts(&intel_cstate->base); |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13314 | } |
| 13315 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13316 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13317 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13318 | |
| 13319 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13320 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13321 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13322 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13323 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13324 | else if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 13325 | skl_detach_scalers(intel_cstate); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13326 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13327 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13328 | if (dev_priv->display.atomic_update_watermarks) |
| 13329 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13330 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13331 | } |
| 13332 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13333 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13334 | struct intel_crtc_state *crtc_state) |
| 13335 | { |
| 13336 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13337 | |
| 13338 | if (!IS_GEN2(dev_priv)) |
| 13339 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13340 | |
| 13341 | if (crtc_state->has_pch_encoder) { |
| 13342 | enum pipe pch_transcoder = |
| 13343 | intel_crtc_pch_transcoder(crtc); |
| 13344 | |
| 13345 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13346 | } |
| 13347 | } |
| 13348 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13349 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13350 | struct drm_crtc_state *old_crtc_state) |
| 13351 | { |
| 13352 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13353 | struct intel_atomic_state *old_intel_state = |
| 13354 | to_intel_atomic_state(old_crtc_state->state); |
| 13355 | struct intel_crtc_state *new_crtc_state = |
| 13356 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13357 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13358 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13359 | |
| 13360 | if (new_crtc_state->update_pipe && |
| 13361 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13362 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13363 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13364 | } |
| 13365 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13366 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13367 | * intel_plane_destroy - destroy a plane |
| 13368 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13369 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13370 | * Common destruction function for all types of planes (primary, cursor, |
| 13371 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13372 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13373 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13374 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13375 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13376 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13377 | } |
| 13378 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13379 | static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane, |
| 13380 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13381 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13382 | switch (modifier) { |
| 13383 | case DRM_FORMAT_MOD_LINEAR: |
| 13384 | case I915_FORMAT_MOD_X_TILED: |
| 13385 | break; |
| 13386 | default: |
| 13387 | return false; |
| 13388 | } |
| 13389 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13390 | switch (format) { |
| 13391 | case DRM_FORMAT_C8: |
| 13392 | case DRM_FORMAT_RGB565: |
| 13393 | case DRM_FORMAT_XRGB1555: |
| 13394 | case DRM_FORMAT_XRGB8888: |
| 13395 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13396 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13397 | default: |
| 13398 | return false; |
| 13399 | } |
| 13400 | } |
| 13401 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13402 | static bool i965_plane_format_mod_supported(struct drm_plane *_plane, |
| 13403 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13404 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13405 | switch (modifier) { |
| 13406 | case DRM_FORMAT_MOD_LINEAR: |
| 13407 | case I915_FORMAT_MOD_X_TILED: |
| 13408 | break; |
| 13409 | default: |
| 13410 | return false; |
| 13411 | } |
| 13412 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13413 | switch (format) { |
| 13414 | case DRM_FORMAT_C8: |
| 13415 | case DRM_FORMAT_RGB565: |
| 13416 | case DRM_FORMAT_XRGB8888: |
| 13417 | case DRM_FORMAT_XBGR8888: |
| 13418 | case DRM_FORMAT_XRGB2101010: |
| 13419 | case DRM_FORMAT_XBGR2101010: |
| 13420 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13421 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13422 | default: |
| 13423 | return false; |
| 13424 | } |
| 13425 | } |
| 13426 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13427 | static bool intel_cursor_format_mod_supported(struct drm_plane *_plane, |
| 13428 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13429 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13430 | return modifier == DRM_FORMAT_MOD_LINEAR && |
| 13431 | format == DRM_FORMAT_ARGB8888; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13432 | } |
| 13433 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13434 | static const struct drm_plane_funcs i965_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13435 | .update_plane = drm_atomic_helper_update_plane, |
| 13436 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13437 | .destroy = intel_plane_destroy, |
| 13438 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13439 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13440 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13441 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13442 | .format_mod_supported = i965_plane_format_mod_supported, |
| 13443 | }; |
| 13444 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13445 | static const struct drm_plane_funcs i8xx_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13446 | .update_plane = drm_atomic_helper_update_plane, |
| 13447 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13448 | .destroy = intel_plane_destroy, |
| 13449 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13450 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13451 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13452 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13453 | .format_mod_supported = i8xx_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13454 | }; |
| 13455 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13456 | static int |
| 13457 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13458 | struct drm_crtc *crtc, |
| 13459 | struct drm_framebuffer *fb, |
| 13460 | int crtc_x, int crtc_y, |
| 13461 | unsigned int crtc_w, unsigned int crtc_h, |
| 13462 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13463 | uint32_t src_w, uint32_t src_h, |
| 13464 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13465 | { |
| 13466 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13467 | int ret; |
| 13468 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13469 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13470 | struct drm_framebuffer *old_fb; |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13471 | struct intel_crtc_state *crtc_state = |
| 13472 | to_intel_crtc_state(crtc->state); |
| 13473 | struct intel_crtc_state *new_crtc_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13474 | |
| 13475 | /* |
| 13476 | * When crtc is inactive or there is a modeset pending, |
| 13477 | * wait for it to complete in the slowpath |
| 13478 | */ |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13479 | if (!crtc_state->base.active || needs_modeset(&crtc_state->base) || |
| 13480 | crtc_state->update_pipe) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13481 | goto slow; |
| 13482 | |
| 13483 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13484 | /* |
| 13485 | * Don't do an async update if there is an outstanding commit modifying |
| 13486 | * the plane. This prevents our async update's changes from getting |
| 13487 | * overridden by a previous synchronous update's state. |
| 13488 | */ |
| 13489 | if (old_plane_state->commit && |
| 13490 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 13491 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13492 | |
| 13493 | /* |
| 13494 | * If any parameters change that may affect watermarks, |
| 13495 | * take the slowpath. Only changing fb or position should be |
| 13496 | * in the fastpath. |
| 13497 | */ |
| 13498 | if (old_plane_state->crtc != crtc || |
| 13499 | old_plane_state->src_w != src_w || |
| 13500 | old_plane_state->src_h != src_h || |
| 13501 | old_plane_state->crtc_w != crtc_w || |
| 13502 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13503 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13504 | goto slow; |
| 13505 | |
| 13506 | new_plane_state = intel_plane_duplicate_state(plane); |
| 13507 | if (!new_plane_state) |
| 13508 | return -ENOMEM; |
| 13509 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13510 | new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc)); |
| 13511 | if (!new_crtc_state) { |
| 13512 | ret = -ENOMEM; |
| 13513 | goto out_free; |
| 13514 | } |
| 13515 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13516 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 13517 | |
| 13518 | new_plane_state->src_x = src_x; |
| 13519 | new_plane_state->src_y = src_y; |
| 13520 | new_plane_state->src_w = src_w; |
| 13521 | new_plane_state->src_h = src_h; |
| 13522 | new_plane_state->crtc_x = crtc_x; |
| 13523 | new_plane_state->crtc_y = crtc_y; |
| 13524 | new_plane_state->crtc_w = crtc_w; |
| 13525 | new_plane_state->crtc_h = crtc_h; |
| 13526 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13527 | ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state, |
| 13528 | to_intel_plane_state(old_plane_state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13529 | to_intel_plane_state(new_plane_state)); |
| 13530 | if (ret) |
| 13531 | goto out_free; |
| 13532 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13533 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13534 | if (ret) |
| 13535 | goto out_free; |
| 13536 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13537 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 13538 | if (ret) |
| 13539 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13540 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 13541 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13542 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13543 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13544 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 13545 | intel_plane->frontbuffer_bit); |
| 13546 | |
| 13547 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13548 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13549 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13550 | /* |
| 13551 | * We cannot swap crtc_state as it may be in use by an atomic commit or |
| 13552 | * page flip that's running simultaneously. If we swap crtc_state and |
| 13553 | * destroy the old state, we will cause a use-after-free there. |
| 13554 | * |
| 13555 | * Only update active_planes, which is needed for our internal |
| 13556 | * bookkeeping. Either value will do the right thing when updating |
| 13557 | * planes atomically. If the cursor was part of the atomic update then |
| 13558 | * we would have taken the slowpath. |
| 13559 | */ |
| 13560 | crtc_state->active_planes = new_crtc_state->active_planes; |
| 13561 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13562 | if (plane->state->visible) { |
| 13563 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13564 | intel_plane->update_plane(intel_plane, crtc_state, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13565 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13566 | } else { |
| 13567 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 282dbf9 | 2017-03-27 21:55:33 +0300 | [diff] [blame] | 13568 | intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13569 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13570 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13571 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13572 | |
| 13573 | out_unlock: |
| 13574 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 13575 | out_free: |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13576 | if (new_crtc_state) |
| 13577 | intel_crtc_destroy_state(crtc, &new_crtc_state->base); |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13578 | if (ret) |
| 13579 | intel_plane_destroy_state(plane, new_plane_state); |
| 13580 | else |
| 13581 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13582 | return ret; |
| 13583 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13584 | slow: |
| 13585 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 13586 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13587 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13588 | } |
| 13589 | |
| 13590 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 13591 | .update_plane = intel_legacy_cursor_update, |
| 13592 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13593 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13594 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13595 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13596 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13597 | .atomic_destroy_state = intel_plane_destroy_state, |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13598 | .format_mod_supported = intel_cursor_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13599 | }; |
| 13600 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13601 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 13602 | enum i9xx_plane_id i9xx_plane) |
| 13603 | { |
| 13604 | if (!HAS_FBC(dev_priv)) |
| 13605 | return false; |
| 13606 | |
| 13607 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 13608 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 13609 | else if (IS_IVYBRIDGE(dev_priv)) |
| 13610 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 13611 | i9xx_plane == PLANE_C; |
| 13612 | else if (INTEL_GEN(dev_priv) >= 4) |
| 13613 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 13614 | else |
| 13615 | return i9xx_plane == PLANE_A; |
| 13616 | } |
| 13617 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13618 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13619 | 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] | 13620 | { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13621 | struct intel_plane *plane; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13622 | const struct drm_plane_funcs *plane_funcs; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13623 | unsigned int supported_rotations; |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13624 | unsigned int possible_crtcs; |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13625 | const u64 *modifiers; |
| 13626 | const u32 *formats; |
| 13627 | int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13628 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13629 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13630 | if (INTEL_GEN(dev_priv) >= 9) |
| 13631 | return skl_universal_plane_create(dev_priv, pipe, |
| 13632 | PLANE_PRIMARY); |
| 13633 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13634 | plane = intel_plane_alloc(); |
| 13635 | if (IS_ERR(plane)) |
| 13636 | return plane; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13637 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13638 | plane->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13639 | /* |
| 13640 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 13641 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 13642 | */ |
| 13643 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13644 | plane->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13645 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13646 | plane->i9xx_plane = (enum i9xx_plane_id) pipe; |
| 13647 | plane->id = PLANE_PRIMARY; |
| 13648 | plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13649 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13650 | plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane); |
| 13651 | if (plane->has_fbc) { |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13652 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 13653 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13654 | fbc->possible_framebuffer_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13655 | } |
| 13656 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13657 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13658 | formats = i965_primary_formats; |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13659 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13660 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13661 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13662 | plane->max_stride = i9xx_plane_max_stride; |
| 13663 | plane->update_plane = i9xx_update_plane; |
| 13664 | plane->disable_plane = i9xx_disable_plane; |
| 13665 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13666 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13667 | |
| 13668 | plane_funcs = &i965_plane_funcs; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13669 | } else { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13670 | formats = i8xx_primary_formats; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13671 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13672 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13673 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13674 | plane->max_stride = i9xx_plane_max_stride; |
| 13675 | plane->update_plane = i9xx_update_plane; |
| 13676 | plane->disable_plane = i9xx_disable_plane; |
| 13677 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13678 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13679 | |
| 13680 | plane_funcs = &i8xx_plane_funcs; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13681 | } |
| 13682 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13683 | possible_crtcs = BIT(pipe); |
| 13684 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13685 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13686 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13687 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13688 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13689 | DRM_PLANE_TYPE_PRIMARY, |
| 13690 | "primary %c", pipe_name(pipe)); |
| 13691 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13692 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13693 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13694 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13695 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13696 | "plane %c", |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13697 | plane_name(plane->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13698 | if (ret) |
| 13699 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13700 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13701 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 13702 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13703 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 13704 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13705 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13706 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13707 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13708 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13709 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13710 | } |
| 13711 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13712 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13713 | drm_plane_create_rotation_property(&plane->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13714 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13715 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 13716 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13717 | drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13718 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13719 | return plane; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13720 | |
| 13721 | fail: |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame^] | 13722 | intel_plane_free(plane); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13723 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13724 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13725 | } |
| 13726 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13727 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13728 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 13729 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13730 | { |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13731 | unsigned int possible_crtcs; |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13732 | struct intel_plane *cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13733 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13734 | |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13735 | cursor = intel_plane_alloc(); |
| 13736 | if (IS_ERR(cursor)) |
| 13737 | return cursor; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13738 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13739 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13740 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 13741 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 13742 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13743 | |
| 13744 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 13745 | cursor->max_stride = i845_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13746 | cursor->update_plane = i845_update_cursor; |
| 13747 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13748 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 13749 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13750 | } else { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 13751 | cursor->max_stride = i9xx_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13752 | cursor->update_plane = i9xx_update_cursor; |
| 13753 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 13754 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 13755 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 13756 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13757 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 13758 | cursor->cursor.base = ~0; |
| 13759 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 13760 | |
| 13761 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 13762 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13763 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13764 | possible_crtcs = BIT(pipe); |
| 13765 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13766 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13767 | possible_crtcs, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13768 | intel_cursor_formats, |
| 13769 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13770 | cursor_format_modifiers, |
| 13771 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13772 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13773 | if (ret) |
| 13774 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13775 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 13776 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13777 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 13778 | DRM_MODE_ROTATE_0, |
| 13779 | DRM_MODE_ROTATE_0 | |
| 13780 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13781 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13782 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 13783 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13784 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13785 | |
| 13786 | fail: |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 13787 | intel_plane_free(cursor); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13788 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13789 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13790 | } |
| 13791 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13792 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 13793 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13794 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 13795 | struct intel_crtc_scaler_state *scaler_state = |
| 13796 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13797 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13798 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13799 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13800 | crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe]; |
| 13801 | if (!crtc->num_scalers) |
| 13802 | return; |
| 13803 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 13804 | for (i = 0; i < crtc->num_scalers; i++) { |
| 13805 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 13806 | |
| 13807 | scaler->in_use = 0; |
Maarten Lankhorst | 0aaf29b | 2018-09-21 16:44:37 +0200 | [diff] [blame] | 13808 | scaler->mode = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13809 | } |
| 13810 | |
| 13811 | scaler_state->scaler_id = -1; |
| 13812 | } |
| 13813 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 13814 | 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] | 13815 | { |
| 13816 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13817 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13818 | struct intel_plane *primary = NULL; |
| 13819 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13820 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13821 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 13822 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13823 | if (!intel_crtc) |
| 13824 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13825 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13826 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13827 | if (!crtc_state) { |
| 13828 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13829 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13830 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 13831 | intel_crtc->config = crtc_state; |
| 13832 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 13833 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13834 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13835 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13836 | if (IS_ERR(primary)) { |
| 13837 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13838 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13839 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13840 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13841 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13842 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13843 | struct intel_plane *plane; |
| 13844 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13845 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 13846 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13847 | ret = PTR_ERR(plane); |
| 13848 | goto fail; |
| 13849 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13850 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 13851 | } |
| 13852 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13853 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 13854 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13855 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13856 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13857 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 13858 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13859 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 13860 | 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] | 13861 | &primary->base, &cursor->base, |
| 13862 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 13863 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13864 | if (ret) |
| 13865 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13866 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13867 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13868 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 13869 | /* initialize shared scalers */ |
| 13870 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 13871 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 13872 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 13873 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 13874 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 13875 | |
| 13876 | if (INTEL_GEN(dev_priv) < 9) { |
| 13877 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 13878 | |
| 13879 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 13880 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 13881 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 13882 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 13883 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13884 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13885 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 13886 | intel_color_init(&intel_crtc->base); |
| 13887 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13888 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13889 | |
| 13890 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13891 | |
| 13892 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13893 | /* |
| 13894 | * drm_mode_config_cleanup() will free up any |
| 13895 | * crtcs/planes already initialized. |
| 13896 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13897 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13898 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13899 | |
| 13900 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13901 | } |
| 13902 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13903 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 13904 | { |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13905 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13906 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 13907 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13908 | |
Daniel Vetter | 51ec53d | 2017-03-01 10:52:24 +0100 | [diff] [blame] | 13909 | if (!connector->base.state->crtc) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13910 | return INVALID_PIPE; |
| 13911 | |
Daniel Vetter | 51ec53d | 2017-03-01 10:52:24 +0100 | [diff] [blame] | 13912 | return to_intel_crtc(connector->base.state->crtc)->pipe; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13913 | } |
| 13914 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 13915 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 13916 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13917 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13918 | 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] | 13919 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13920 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13921 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 13922 | 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] | 13923 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 13924 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13925 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13926 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13927 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13928 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13929 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13930 | } |
| 13931 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13932 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13933 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13934 | struct drm_device *dev = encoder->base.dev; |
| 13935 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13936 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13937 | int entry = 0; |
| 13938 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13939 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 13940 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13941 | index_mask |= (1 << entry); |
| 13942 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13943 | entry++; |
| 13944 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13945 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13946 | return index_mask; |
| 13947 | } |
| 13948 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 13949 | static bool has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13950 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 13951 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13952 | return false; |
| 13953 | |
| 13954 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 13955 | return false; |
| 13956 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 13957 | 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] | 13958 | return false; |
| 13959 | |
| 13960 | return true; |
| 13961 | } |
| 13962 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13963 | static bool intel_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13964 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13965 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 13966 | return false; |
| 13967 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 13968 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13969 | return false; |
| 13970 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 13971 | if (IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13972 | return false; |
| 13973 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13974 | if (HAS_PCH_LPT_H(dev_priv) && |
| 13975 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 13976 | return false; |
| 13977 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 13978 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13979 | 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] | 13980 | return false; |
| 13981 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 13982 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13983 | return false; |
| 13984 | |
| 13985 | return true; |
| 13986 | } |
| 13987 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 13988 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 13989 | { |
| 13990 | int pps_num; |
| 13991 | int pps_idx; |
| 13992 | |
| 13993 | if (HAS_DDI(dev_priv)) |
| 13994 | return; |
| 13995 | /* |
| 13996 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 13997 | * everywhere where registers can be write protected. |
| 13998 | */ |
| 13999 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14000 | pps_num = 2; |
| 14001 | else |
| 14002 | pps_num = 1; |
| 14003 | |
| 14004 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 14005 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 14006 | |
| 14007 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 14008 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 14009 | } |
| 14010 | } |
| 14011 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14012 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 14013 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 14014 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14015 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 14016 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14017 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 14018 | else |
| 14019 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14020 | |
| 14021 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14022 | } |
| 14023 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14024 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14025 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14026 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14027 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14028 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14029 | intel_pps_init(dev_priv); |
| 14030 | |
Chris Wilson | fc0c5a9 | 2018-08-15 21:12:07 +0100 | [diff] [blame] | 14031 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
| 14032 | return; |
| 14033 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 14034 | /* |
| 14035 | * intel_edp_init_connector() depends on this completing first, to |
| 14036 | * prevent the registeration of both eDP and LVDS and the incorrect |
| 14037 | * sharing of the PPS. |
| 14038 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14039 | intel_lvds_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14040 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14041 | if (intel_crt_present(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14042 | intel_crt_init(dev_priv); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14043 | |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14044 | if (IS_ICELAKE(dev_priv)) { |
| 14045 | intel_ddi_init(dev_priv, PORT_A); |
| 14046 | intel_ddi_init(dev_priv, PORT_B); |
| 14047 | intel_ddi_init(dev_priv, PORT_C); |
| 14048 | intel_ddi_init(dev_priv, PORT_D); |
| 14049 | intel_ddi_init(dev_priv, PORT_E); |
| 14050 | intel_ddi_init(dev_priv, PORT_F); |
| 14051 | } else if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14052 | /* |
| 14053 | * FIXME: Broxton doesn't support port detection via the |
| 14054 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14055 | * detect the ports. |
| 14056 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14057 | intel_ddi_init(dev_priv, PORT_A); |
| 14058 | intel_ddi_init(dev_priv, PORT_B); |
| 14059 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14060 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14061 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14062 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14063 | int found; |
| 14064 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14065 | /* |
| 14066 | * Haswell uses DDI functions to detect digital outputs. |
| 14067 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14068 | * it's there. |
| 14069 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14070 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14071 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14072 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14073 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14074 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14075 | /* 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] | 14076 | * register */ |
| 14077 | found = I915_READ(SFUSE_STRAP); |
| 14078 | |
| 14079 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14080 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14081 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14082 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14083 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14084 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14085 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 14086 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14087 | /* |
| 14088 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14089 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14090 | if (IS_GEN9_BC(dev_priv) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14091 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 14092 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 14093 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14094 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14095 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14096 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14097 | int found; |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14098 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14099 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14100 | if (has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14101 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14102 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14103 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14104 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14105 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14106 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14107 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14108 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14109 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14110 | } |
| 14111 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14112 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14113 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14114 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14115 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14116 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14117 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14118 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14119 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14120 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14121 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14122 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14123 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14124 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 14125 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14126 | /* |
| 14127 | * The DP_DETECTED bit is the latched state of the DDC |
| 14128 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14129 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14130 | * eDP ports may have been muxed to an alternate function. |
| 14131 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14132 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14133 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14134 | * |
| 14135 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 14136 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 14137 | * and VBT for the presence of the port. Additionally we can't |
| 14138 | * trust the port type the VBT declares as we've seen at least |
| 14139 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14140 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14141 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14142 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14143 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14144 | 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] | 14145 | 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] | 14146 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14147 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14148 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14149 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14150 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14151 | 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] | 14152 | 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] | 14153 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14154 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14155 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14156 | /* |
| 14157 | * eDP not supported on port D, |
| 14158 | * so no need to worry about it |
| 14159 | */ |
| 14160 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14161 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14162 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14163 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14164 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14165 | } |
| 14166 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14167 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14168 | } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14169 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14170 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14171 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14172 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14173 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14174 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14175 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14176 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14177 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14178 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14179 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14180 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14181 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14182 | |
| 14183 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14184 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14185 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14186 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14187 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14188 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14189 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14190 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14191 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14192 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14193 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14194 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14195 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14196 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14197 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14198 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14199 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14200 | 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] | 14201 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 14202 | } else if (IS_GEN2(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14203 | intel_dvo_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14204 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 14205 | if (SUPPORTS_TV(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14206 | intel_tv_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14207 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14208 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14209 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14210 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14211 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14212 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14213 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14214 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14215 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14216 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14217 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14218 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14219 | } |
| 14220 | |
| 14221 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14222 | { |
| 14223 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14224 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14225 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14226 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14227 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14228 | i915_gem_object_lock(obj); |
| 14229 | WARN_ON(!obj->framebuffer_references--); |
| 14230 | i915_gem_object_unlock(obj); |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14231 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14232 | i915_gem_object_put(obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14233 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14234 | kfree(intel_fb); |
| 14235 | } |
| 14236 | |
| 14237 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14238 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14239 | unsigned int *handle) |
| 14240 | { |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14241 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14242 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14243 | if (obj->userptr.mm) { |
| 14244 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14245 | return -EINVAL; |
| 14246 | } |
| 14247 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14248 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14249 | } |
| 14250 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14251 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14252 | struct drm_file *file, |
| 14253 | unsigned flags, unsigned color, |
| 14254 | struct drm_clip_rect *clips, |
| 14255 | unsigned num_clips) |
| 14256 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14257 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14258 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14259 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14260 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14261 | |
| 14262 | return 0; |
| 14263 | } |
| 14264 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14265 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14266 | .destroy = intel_user_framebuffer_destroy, |
| 14267 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14268 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14269 | }; |
| 14270 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14271 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14272 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
| 14273 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14274 | { |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14275 | struct intel_crtc *crtc; |
| 14276 | struct intel_plane *plane; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14277 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14278 | /* |
| 14279 | * We assume the primary plane for pipe A has |
| 14280 | * the highest stride limits of them all. |
| 14281 | */ |
| 14282 | crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A); |
| 14283 | plane = to_intel_plane(crtc->base.primary); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14284 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14285 | return plane->max_stride(plane, pixel_format, fb_modifier, |
| 14286 | DRM_MODE_ROTATE_0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14287 | } |
| 14288 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14289 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14290 | struct drm_i915_gem_object *obj, |
| 14291 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14292 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14293 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14294 | struct drm_framebuffer *fb = &intel_fb->base; |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 14295 | struct drm_format_name_buf format_name; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14296 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14297 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14298 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14299 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14300 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14301 | i915_gem_object_lock(obj); |
| 14302 | obj->framebuffer_references++; |
| 14303 | tiling = i915_gem_object_get_tiling(obj); |
| 14304 | stride = i915_gem_object_get_stride(obj); |
| 14305 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14306 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14307 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14308 | /* |
| 14309 | * If there's a fence, enforce that |
| 14310 | * the fb modifier and tiling mode match. |
| 14311 | */ |
| 14312 | if (tiling != I915_TILING_NONE && |
| 14313 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14314 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14315 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14316 | } |
| 14317 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14318 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14319 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14320 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14321 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14322 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14323 | } |
| 14324 | } |
| 14325 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14326 | /* Passed in modifier sanity checking. */ |
| 14327 | switch (mode_cmd->modifier[0]) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14328 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 14329 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 14330 | switch (mode_cmd->pixel_format) { |
| 14331 | case DRM_FORMAT_XBGR8888: |
| 14332 | case DRM_FORMAT_ABGR8888: |
| 14333 | case DRM_FORMAT_XRGB8888: |
| 14334 | case DRM_FORMAT_ARGB8888: |
| 14335 | break; |
| 14336 | default: |
| 14337 | DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n"); |
| 14338 | goto err; |
| 14339 | } |
| 14340 | /* fall through */ |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14341 | case I915_FORMAT_MOD_Y_TILED: |
| 14342 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14343 | if (INTEL_GEN(dev_priv) < 9) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14344 | DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n", |
| 14345 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14346 | goto err; |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14347 | } |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14348 | case DRM_FORMAT_MOD_LINEAR: |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14349 | case I915_FORMAT_MOD_X_TILED: |
| 14350 | break; |
| 14351 | default: |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14352 | DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n", |
| 14353 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14354 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14355 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14356 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14357 | /* |
| 14358 | * gen2/3 display engine uses the fence if present, |
| 14359 | * so the tiling mode must match the fb modifier exactly. |
| 14360 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14361 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14362 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14363 | 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] | 14364 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14365 | } |
| 14366 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14367 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14368 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14369 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14370 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14371 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14372 | "tiled" : "linear", |
| 14373 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14374 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14375 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14376 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14377 | /* |
| 14378 | * If there's a fence, enforce that |
| 14379 | * the fb pitch and fence stride match. |
| 14380 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14381 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14382 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14383 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14384 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14385 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14386 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14387 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14388 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14389 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14390 | case DRM_FORMAT_RGB565: |
| 14391 | case DRM_FORMAT_XRGB8888: |
| 14392 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14393 | break; |
| 14394 | case DRM_FORMAT_XRGB1555: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14395 | if (INTEL_GEN(dev_priv) > 3) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14396 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14397 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14398 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14399 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14400 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14401 | case DRM_FORMAT_ABGR8888: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14402 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14403 | INTEL_GEN(dev_priv) < 9) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14404 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14405 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14406 | goto err; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14407 | } |
| 14408 | break; |
| 14409 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14410 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14411 | case DRM_FORMAT_XBGR2101010: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14412 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14413 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14414 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14415 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14416 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14417 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14418 | case DRM_FORMAT_ABGR2101010: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14419 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14420 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14421 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14422 | goto err; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14423 | } |
| 14424 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14425 | case DRM_FORMAT_YUYV: |
| 14426 | case DRM_FORMAT_UYVY: |
| 14427 | case DRM_FORMAT_YVYU: |
| 14428 | case DRM_FORMAT_VYUY: |
Ville Syrjälä | ab33081 | 2017-04-21 21:14:32 +0300 | [diff] [blame] | 14429 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14430 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14431 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14432 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14433 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14434 | break; |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14435 | case DRM_FORMAT_NV12: |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14436 | if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) || |
Dhinakaran Pandiyan | b45649f | 2018-08-24 13:38:56 -0700 | [diff] [blame] | 14437 | IS_BROXTON(dev_priv) || INTEL_GEN(dev_priv) >= 11) { |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14438 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14439 | drm_get_format_name(mode_cmd->pixel_format, |
| 14440 | &format_name)); |
| 14441 | goto err; |
| 14442 | } |
| 14443 | break; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14444 | default: |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14445 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
| 14446 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14447 | goto err; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14448 | } |
| 14449 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14450 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14451 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14452 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14453 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14454 | 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] | 14455 | |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14456 | if (fb->format->format == DRM_FORMAT_NV12 && |
| 14457 | (fb->width < SKL_MIN_YUV_420_SRC_W || |
| 14458 | fb->height < SKL_MIN_YUV_420_SRC_H || |
| 14459 | (fb->width % 4) != 0 || (fb->height % 4) != 0)) { |
| 14460 | DRM_DEBUG_KMS("src dimensions not correct for NV12\n"); |
| 14461 | return -EINVAL; |
| 14462 | } |
| 14463 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14464 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14465 | u32 stride_alignment; |
| 14466 | |
| 14467 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14468 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14469 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14470 | } |
| 14471 | |
| 14472 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14473 | |
| 14474 | /* |
| 14475 | * Display WA #0531: skl,bxt,kbl,glk |
| 14476 | * |
| 14477 | * Render decompression and plane width > 3840 |
| 14478 | * combined with horizontal panning requires the |
| 14479 | * plane stride to be a multiple of 4. We'll just |
| 14480 | * require the entire fb to accommodate that to avoid |
| 14481 | * potential runtime errors at plane configuration time. |
| 14482 | */ |
| 14483 | if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 && |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 14484 | is_ccs_modifier(fb->modifier)) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14485 | stride_alignment *= 4; |
| 14486 | |
| 14487 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14488 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14489 | i, fb->pitches[i], stride_alignment); |
| 14490 | goto err; |
| 14491 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14492 | |
Daniel Stone | a268bcd | 2018-05-18 15:30:08 +0100 | [diff] [blame] | 14493 | fb->obj[i] = &obj->base; |
| 14494 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14495 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14496 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14497 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14498 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14499 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14500 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14501 | if (ret) { |
| 14502 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14503 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14504 | } |
| 14505 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14506 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14507 | |
| 14508 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14509 | i915_gem_object_lock(obj); |
| 14510 | obj->framebuffer_references--; |
| 14511 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14512 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14513 | } |
| 14514 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14515 | static struct drm_framebuffer * |
| 14516 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14517 | struct drm_file *filp, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14518 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14519 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14520 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14521 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14522 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14523 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14524 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14525 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14526 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14527 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14528 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14529 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14530 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14531 | |
| 14532 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14533 | } |
| 14534 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14535 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14536 | { |
| 14537 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14538 | |
| 14539 | drm_atomic_state_default_release(state); |
| 14540 | |
| 14541 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14542 | |
| 14543 | kfree(state); |
| 14544 | } |
| 14545 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14546 | static enum drm_mode_status |
| 14547 | intel_mode_valid(struct drm_device *dev, |
| 14548 | const struct drm_display_mode *mode) |
| 14549 | { |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14550 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14551 | int hdisplay_max, htotal_max; |
| 14552 | int vdisplay_max, vtotal_max; |
| 14553 | |
Ville Syrjälä | e4dd27a | 2018-05-24 15:54:03 +0300 | [diff] [blame] | 14554 | /* |
| 14555 | * Can't reject DBLSCAN here because Xorg ddxen can add piles |
| 14556 | * of DBLSCAN modes to the output's mode list when they detect |
| 14557 | * the scaling mode property on the connector. And they don't |
| 14558 | * ask the kernel to validate those modes in any way until |
| 14559 | * modeset time at which point the client gets a protocol error. |
| 14560 | * So in order to not upset those clients we silently ignore the |
| 14561 | * DBLSCAN flag on such connectors. For other connectors we will |
| 14562 | * reject modes with the DBLSCAN flag in encoder->compute_config(). |
| 14563 | * And we always reject DBLSCAN modes in connector->mode_valid() |
| 14564 | * as we never want such modes on the connector's mode list. |
| 14565 | */ |
| 14566 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14567 | if (mode->vscan > 1) |
| 14568 | return MODE_NO_VSCAN; |
| 14569 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14570 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 14571 | return MODE_H_ILLEGAL; |
| 14572 | |
| 14573 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 14574 | DRM_MODE_FLAG_NCSYNC | |
| 14575 | DRM_MODE_FLAG_PCSYNC)) |
| 14576 | return MODE_HSYNC; |
| 14577 | |
| 14578 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 14579 | DRM_MODE_FLAG_PIXMUX | |
| 14580 | DRM_MODE_FLAG_CLKDIV2)) |
| 14581 | return MODE_BAD; |
| 14582 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14583 | if (INTEL_GEN(dev_priv) >= 9 || |
| 14584 | IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { |
| 14585 | hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ |
| 14586 | vdisplay_max = 4096; |
| 14587 | htotal_max = 8192; |
| 14588 | vtotal_max = 8192; |
| 14589 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 14590 | hdisplay_max = 4096; |
| 14591 | vdisplay_max = 4096; |
| 14592 | htotal_max = 8192; |
| 14593 | vtotal_max = 8192; |
| 14594 | } else { |
| 14595 | hdisplay_max = 2048; |
| 14596 | vdisplay_max = 2048; |
| 14597 | htotal_max = 4096; |
| 14598 | vtotal_max = 4096; |
| 14599 | } |
| 14600 | |
| 14601 | if (mode->hdisplay > hdisplay_max || |
| 14602 | mode->hsync_start > htotal_max || |
| 14603 | mode->hsync_end > htotal_max || |
| 14604 | mode->htotal > htotal_max) |
| 14605 | return MODE_H_ILLEGAL; |
| 14606 | |
| 14607 | if (mode->vdisplay > vdisplay_max || |
| 14608 | mode->vsync_start > vtotal_max || |
| 14609 | mode->vsync_end > vtotal_max || |
| 14610 | mode->vtotal > vtotal_max) |
| 14611 | return MODE_V_ILLEGAL; |
| 14612 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14613 | return MODE_OK; |
| 14614 | } |
| 14615 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14616 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14617 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 14618 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14619 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14620 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14621 | .atomic_check = intel_atomic_check, |
| 14622 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14623 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14624 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14625 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14626 | }; |
| 14627 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14628 | /** |
| 14629 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14630 | * @dev_priv: device private |
| 14631 | */ |
| 14632 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14633 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 14634 | intel_init_cdclk_hooks(dev_priv); |
| 14635 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14636 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14637 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14638 | dev_priv->display.get_initial_plane_config = |
| 14639 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14640 | dev_priv->display.crtc_compute_clock = |
| 14641 | haswell_crtc_compute_clock; |
| 14642 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14643 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14644 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14645 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14646 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14647 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14648 | dev_priv->display.crtc_compute_clock = |
| 14649 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14650 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14651 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14652 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14653 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14654 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14655 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14656 | dev_priv->display.crtc_compute_clock = |
| 14657 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14658 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14659 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14660 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14661 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14662 | dev_priv->display.get_initial_plane_config = |
| 14663 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14664 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 14665 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14666 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14667 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 14668 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14669 | dev_priv->display.get_initial_plane_config = |
| 14670 | i9xx_get_initial_plane_config; |
| 14671 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14672 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14673 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 14674 | } else if (IS_G4X(dev_priv)) { |
| 14675 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14676 | dev_priv->display.get_initial_plane_config = |
| 14677 | i9xx_get_initial_plane_config; |
| 14678 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 14679 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14680 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 14681 | } else if (IS_PINEVIEW(dev_priv)) { |
| 14682 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14683 | dev_priv->display.get_initial_plane_config = |
| 14684 | i9xx_get_initial_plane_config; |
| 14685 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 14686 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14687 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14688 | } else if (!IS_GEN2(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14689 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14690 | dev_priv->display.get_initial_plane_config = |
| 14691 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14692 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14693 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14694 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14695 | } else { |
| 14696 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14697 | dev_priv->display.get_initial_plane_config = |
| 14698 | i9xx_get_initial_plane_config; |
| 14699 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 14700 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14701 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14702 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14703 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14704 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14705 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14706 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14707 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14708 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14709 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14710 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14711 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14712 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 14713 | } |
| 14714 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 14715 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14716 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 14717 | else |
| 14718 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14719 | } |
| 14720 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14721 | /* |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14722 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 14723 | */ |
| 14724 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 14725 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14726 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14727 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14728 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14729 | } |
| 14730 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14731 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14732 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 14733 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14734 | */ |
| 14735 | static void quirk_invert_brightness(struct drm_device *dev) |
| 14736 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14737 | struct drm_i915_private *dev_priv = to_i915(dev); |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 14738 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 14739 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14740 | } |
| 14741 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14742 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 14743 | static void quirk_backlight_present(struct drm_device *dev) |
| 14744 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14745 | struct drm_i915_private *dev_priv = to_i915(dev); |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 14746 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 14747 | DRM_INFO("applying backlight present quirk\n"); |
| 14748 | } |
| 14749 | |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 14750 | /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms |
| 14751 | * which is 300 ms greater than eDP spec T12 min. |
| 14752 | */ |
| 14753 | static void quirk_increase_t12_delay(struct drm_device *dev) |
| 14754 | { |
| 14755 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14756 | |
| 14757 | dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY; |
| 14758 | DRM_INFO("Applying T12 delay quirk\n"); |
| 14759 | } |
| 14760 | |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 14761 | /* |
| 14762 | * GeminiLake NUC HDMI outputs require additional off time |
| 14763 | * this allows the onboard retimer to correctly sync to signal |
| 14764 | */ |
| 14765 | static void quirk_increase_ddi_disabled_time(struct drm_device *dev) |
| 14766 | { |
| 14767 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14768 | |
| 14769 | dev_priv->quirks |= QUIRK_INCREASE_DDI_DISABLED_TIME; |
| 14770 | DRM_INFO("Applying Increase DDI Disabled quirk\n"); |
| 14771 | } |
| 14772 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14773 | struct intel_quirk { |
| 14774 | int device; |
| 14775 | int subsystem_vendor; |
| 14776 | int subsystem_device; |
| 14777 | void (*hook)(struct drm_device *dev); |
| 14778 | }; |
| 14779 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14780 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 14781 | struct intel_dmi_quirk { |
| 14782 | void (*hook)(struct drm_device *dev); |
| 14783 | const struct dmi_system_id (*dmi_id_list)[]; |
| 14784 | }; |
| 14785 | |
| 14786 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 14787 | { |
| 14788 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 14789 | return 1; |
| 14790 | } |
| 14791 | |
| 14792 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 14793 | { |
| 14794 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 14795 | { |
| 14796 | .callback = intel_dmi_reverse_brightness, |
| 14797 | .ident = "NCR Corporation", |
| 14798 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 14799 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 14800 | }, |
| 14801 | }, |
| 14802 | { } /* terminating entry */ |
| 14803 | }, |
| 14804 | .hook = quirk_invert_brightness, |
| 14805 | }, |
| 14806 | }; |
| 14807 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 14808 | static struct intel_quirk intel_quirks[] = { |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 14809 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 14810 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 14811 | |
| 14812 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 14813 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 14814 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 14815 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 14816 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 14817 | |
| 14818 | /* Acer/eMachines G725 */ |
| 14819 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 14820 | |
| 14821 | /* Acer/eMachines e725 */ |
| 14822 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 14823 | |
| 14824 | /* Acer/Packard Bell NCL20 */ |
| 14825 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 14826 | |
| 14827 | /* Acer Aspire 4736Z */ |
| 14828 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 14829 | |
| 14830 | /* Acer Aspire 5336 */ |
| 14831 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 14832 | |
| 14833 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 14834 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14835 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 14836 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 14837 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 14838 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 14839 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 14840 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 14841 | |
Jani Nikula | 1b9448b0 | 2015-11-05 11:49:59 +0200 | [diff] [blame] | 14842 | /* Apple Macbook 4,1 */ |
| 14843 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, |
| 14844 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 14845 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 14846 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 14847 | |
| 14848 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 14849 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 14850 | |
| 14851 | /* Dell Chromebook 11 */ |
| 14852 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jani Nikula | 9be64ee | 2015-10-30 14:50:24 +0200 | [diff] [blame] | 14853 | |
| 14854 | /* Dell Chromebook 11 (2015 version) */ |
| 14855 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, |
Manasi Navare | c99a259 | 2017-06-30 09:33:48 -0700 | [diff] [blame] | 14856 | |
| 14857 | /* Toshiba Satellite P50-C-18C */ |
| 14858 | { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay }, |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 14859 | |
| 14860 | /* GeminiLake NUC */ |
| 14861 | { 0x3185, 0x8086, 0x2072, quirk_increase_ddi_disabled_time }, |
| 14862 | { 0x3184, 0x8086, 0x2072, quirk_increase_ddi_disabled_time }, |
| 14863 | /* ASRock ITX*/ |
| 14864 | { 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time }, |
| 14865 | { 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14866 | }; |
| 14867 | |
| 14868 | static void intel_init_quirks(struct drm_device *dev) |
| 14869 | { |
| 14870 | struct pci_dev *d = dev->pdev; |
| 14871 | int i; |
| 14872 | |
| 14873 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 14874 | struct intel_quirk *q = &intel_quirks[i]; |
| 14875 | |
| 14876 | if (d->device == q->device && |
| 14877 | (d->subsystem_vendor == q->subsystem_vendor || |
| 14878 | q->subsystem_vendor == PCI_ANY_ID) && |
| 14879 | (d->subsystem_device == q->subsystem_device || |
| 14880 | q->subsystem_device == PCI_ANY_ID)) |
| 14881 | q->hook(dev); |
| 14882 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 14883 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 14884 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 14885 | intel_dmi_quirks[i].hook(dev); |
| 14886 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14887 | } |
| 14888 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14889 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 14890 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14891 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14892 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14893 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14894 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14895 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14896 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14897 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14898 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14899 | sr1 = inb(VGA_SR_DATA); |
| 14900 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14901 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14902 | udelay(300); |
| 14903 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14904 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14905 | POSTING_READ(vga_reg); |
| 14906 | } |
| 14907 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14908 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14909 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14910 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 14911 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 14912 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 14913 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 14914 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14915 | } |
| 14916 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14917 | /* |
| 14918 | * Calculate what we think the watermarks should be for the state we've read |
| 14919 | * out of the hardware and then immediately program those watermarks so that |
| 14920 | * we ensure the hardware settings match our internal state. |
| 14921 | * |
| 14922 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 14923 | * current state (which was constructed during hardware readout) and running it |
| 14924 | * through the atomic check code to calculate new watermark values in the |
| 14925 | * state object. |
| 14926 | */ |
| 14927 | static void sanitize_watermarks(struct drm_device *dev) |
| 14928 | { |
| 14929 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14930 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14931 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14932 | struct drm_crtc *crtc; |
| 14933 | struct drm_crtc_state *cstate; |
| 14934 | struct drm_modeset_acquire_ctx ctx; |
| 14935 | int ret; |
| 14936 | int i; |
| 14937 | |
| 14938 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14939 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14940 | return; |
| 14941 | |
| 14942 | /* |
| 14943 | * We need to hold connection_mutex before calling duplicate_state so |
| 14944 | * that the connector loop is protected. |
| 14945 | */ |
| 14946 | drm_modeset_acquire_init(&ctx, 0); |
| 14947 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14948 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14949 | if (ret == -EDEADLK) { |
| 14950 | drm_modeset_backoff(&ctx); |
| 14951 | goto retry; |
| 14952 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14953 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14954 | } |
| 14955 | |
| 14956 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 14957 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14958 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14959 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14960 | intel_state = to_intel_atomic_state(state); |
| 14961 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14962 | /* |
| 14963 | * Hardware readout is the only time we don't want to calculate |
| 14964 | * intermediate watermarks (since we don't trust the current |
| 14965 | * watermarks). |
| 14966 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 14967 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 14968 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14969 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14970 | ret = intel_atomic_check(dev, state); |
| 14971 | if (ret) { |
| 14972 | /* |
| 14973 | * If we fail here, it means that the hardware appears to be |
| 14974 | * programmed in a way that shouldn't be possible, given our |
| 14975 | * understanding of watermark requirements. This might mean a |
| 14976 | * mistake in the hardware readout code or a mistake in the |
| 14977 | * watermark calculations for a given platform. Raise a WARN |
| 14978 | * so that this is noticeable. |
| 14979 | * |
| 14980 | * If this actually happens, we'll have to just leave the |
| 14981 | * BIOS-programmed watermarks untouched and hope for the best. |
| 14982 | */ |
| 14983 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14984 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14985 | } |
| 14986 | |
| 14987 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 14988 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14989 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 14990 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14991 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14992 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 14993 | |
| 14994 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14995 | } |
| 14996 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 14997 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14998 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 14999 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15000 | drm_modeset_drop_locks(&ctx); |
| 15001 | drm_modeset_acquire_fini(&ctx); |
| 15002 | } |
| 15003 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15004 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 15005 | { |
| 15006 | if (IS_GEN5(dev_priv)) { |
| 15007 | u32 fdi_pll_clk = |
| 15008 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 15009 | |
| 15010 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
| 15011 | } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) { |
| 15012 | dev_priv->fdi_pll_freq = 270000; |
| 15013 | } else { |
| 15014 | return; |
| 15015 | } |
| 15016 | |
| 15017 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 15018 | } |
| 15019 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15020 | static int intel_initial_commit(struct drm_device *dev) |
| 15021 | { |
| 15022 | struct drm_atomic_state *state = NULL; |
| 15023 | struct drm_modeset_acquire_ctx ctx; |
| 15024 | struct drm_crtc *crtc; |
| 15025 | struct drm_crtc_state *crtc_state; |
| 15026 | int ret = 0; |
| 15027 | |
| 15028 | state = drm_atomic_state_alloc(dev); |
| 15029 | if (!state) |
| 15030 | return -ENOMEM; |
| 15031 | |
| 15032 | drm_modeset_acquire_init(&ctx, 0); |
| 15033 | |
| 15034 | retry: |
| 15035 | state->acquire_ctx = &ctx; |
| 15036 | |
| 15037 | drm_for_each_crtc(crtc, dev) { |
| 15038 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 15039 | if (IS_ERR(crtc_state)) { |
| 15040 | ret = PTR_ERR(crtc_state); |
| 15041 | goto out; |
| 15042 | } |
| 15043 | |
| 15044 | if (crtc_state->active) { |
| 15045 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 15046 | if (ret) |
| 15047 | goto out; |
| 15048 | } |
| 15049 | } |
| 15050 | |
| 15051 | ret = drm_atomic_commit(state); |
| 15052 | |
| 15053 | out: |
| 15054 | if (ret == -EDEADLK) { |
| 15055 | drm_atomic_state_clear(state); |
| 15056 | drm_modeset_backoff(&ctx); |
| 15057 | goto retry; |
| 15058 | } |
| 15059 | |
| 15060 | drm_atomic_state_put(state); |
| 15061 | |
| 15062 | drm_modeset_drop_locks(&ctx); |
| 15063 | drm_modeset_acquire_fini(&ctx); |
| 15064 | |
| 15065 | return ret; |
| 15066 | } |
| 15067 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15068 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15069 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15070 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15071 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15072 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15073 | struct intel_crtc *crtc; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15074 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15075 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15076 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 15077 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15078 | drm_mode_config_init(dev); |
| 15079 | |
| 15080 | dev->mode_config.min_width = 0; |
| 15081 | dev->mode_config.min_height = 0; |
| 15082 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15083 | dev->mode_config.preferred_depth = 24; |
| 15084 | dev->mode_config.prefer_shadow = 1; |
| 15085 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15086 | dev->mode_config.allow_fb_modifiers = true; |
| 15087 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15088 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15089 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 15090 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15091 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 15092 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15093 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15094 | intel_init_quirks(dev); |
| 15095 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 15096 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15097 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15098 | /* |
| 15099 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15100 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15101 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15102 | * indicates as much. |
| 15103 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15104 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15105 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15106 | DREF_SSC1_ENABLE); |
| 15107 | |
| 15108 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15109 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15110 | bios_lvds_use_ssc ? "en" : "dis", |
| 15111 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15112 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15113 | } |
| 15114 | } |
| 15115 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15116 | /* maximum framebuffer dimensions */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15117 | if (IS_GEN2(dev_priv)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15118 | dev->mode_config.max_width = 2048; |
| 15119 | dev->mode_config.max_height = 2048; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15120 | } else if (IS_GEN3(dev_priv)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15121 | dev->mode_config.max_width = 4096; |
| 15122 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15123 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15124 | dev->mode_config.max_width = 8192; |
| 15125 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15126 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15127 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 15128 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 15129 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15130 | dev->mode_config.cursor_height = 1023; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15131 | } else if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15132 | dev->mode_config.cursor_width = 64; |
| 15133 | dev->mode_config.cursor_height = 64; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15134 | } else { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15135 | dev->mode_config.cursor_width = 256; |
| 15136 | dev->mode_config.cursor_height = 256; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15137 | } |
| 15138 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 15139 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15140 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15141 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15142 | INTEL_INFO(dev_priv)->num_pipes, |
| 15143 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15144 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15145 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15146 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15147 | if (ret) { |
| 15148 | drm_mode_config_cleanup(dev); |
| 15149 | return ret; |
| 15150 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15151 | } |
| 15152 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15153 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15154 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15155 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 15156 | intel_update_czclk(dev_priv); |
| 15157 | intel_modeset_init_hw(dev); |
| 15158 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15159 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15160 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15161 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15162 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15163 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15164 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15165 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15166 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15167 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15168 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15169 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15170 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15171 | struct intel_initial_plane_config plane_config = {}; |
| 15172 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15173 | if (!crtc->active) |
| 15174 | continue; |
| 15175 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15176 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15177 | * Note that reserving the BIOS fb up front prevents us |
| 15178 | * from stuffing other stolen allocations like the ring |
| 15179 | * on top. This prevents some ugliness at boot time, and |
| 15180 | * can even allow for smooth boot transitions if the BIOS |
| 15181 | * fb is large enough for the active pipe configuration. |
| 15182 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15183 | dev_priv->display.get_initial_plane_config(crtc, |
| 15184 | &plane_config); |
| 15185 | |
| 15186 | /* |
| 15187 | * If the fb is shared between multiple heads, we'll |
| 15188 | * just get the first one. |
| 15189 | */ |
| 15190 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15191 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15192 | |
| 15193 | /* |
| 15194 | * Make sure hardware watermarks really match the state we read out. |
| 15195 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15196 | * since the watermark calculation done here will use pstate->fb. |
| 15197 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15198 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 15199 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15200 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15201 | /* |
| 15202 | * Force all active planes to recompute their states. So that on |
| 15203 | * mode_setcrtc after probe, all the intel_plane_state variables |
| 15204 | * are already calculated and there is no assert_plane warnings |
| 15205 | * during bootup. |
| 15206 | */ |
| 15207 | ret = intel_initial_commit(dev); |
| 15208 | if (ret) |
| 15209 | DRM_DEBUG_KMS("Initial commit in probe failed.\n"); |
| 15210 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15211 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15212 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15213 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15214 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15215 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15216 | 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] | 15217 | /* 640x480@60Hz, ~25175 kHz */ |
| 15218 | struct dpll clock = { |
| 15219 | .m1 = 18, |
| 15220 | .m2 = 7, |
| 15221 | .p1 = 13, |
| 15222 | .p2 = 4, |
| 15223 | .n = 2, |
| 15224 | }; |
| 15225 | u32 dpll, fp; |
| 15226 | int i; |
| 15227 | |
| 15228 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 15229 | |
| 15230 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 15231 | pipe_name(pipe), clock.vco, clock.dot); |
| 15232 | |
| 15233 | fp = i9xx_dpll_compute_fp(&clock); |
| 15234 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 15235 | DPLL_VGA_MODE_DIS | |
| 15236 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 15237 | PLL_P2_DIVIDE_BY_4 | |
| 15238 | PLL_REF_INPUT_DREFCLK | |
| 15239 | DPLL_VCO_ENABLE; |
| 15240 | |
| 15241 | I915_WRITE(FP0(pipe), fp); |
| 15242 | I915_WRITE(FP1(pipe), fp); |
| 15243 | |
| 15244 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15245 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15246 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15247 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15248 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15249 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15250 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15251 | |
| 15252 | /* |
| 15253 | * Apparently we need to have VGA mode enabled prior to changing |
| 15254 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15255 | * dividers, even though the register value does change. |
| 15256 | */ |
| 15257 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15258 | I915_WRITE(DPLL(pipe), dpll); |
| 15259 | |
| 15260 | /* Wait for the clocks to stabilize. */ |
| 15261 | POSTING_READ(DPLL(pipe)); |
| 15262 | udelay(150); |
| 15263 | |
| 15264 | /* The pixel multiplier can only be updated once the |
| 15265 | * DPLL is enabled and the clocks are stable. |
| 15266 | * |
| 15267 | * So write it again. |
| 15268 | */ |
| 15269 | I915_WRITE(DPLL(pipe), dpll); |
| 15270 | |
| 15271 | /* We do this three times for luck */ |
| 15272 | for (i = 0; i < 3 ; i++) { |
| 15273 | I915_WRITE(DPLL(pipe), dpll); |
| 15274 | POSTING_READ(DPLL(pipe)); |
| 15275 | udelay(150); /* wait for warmup */ |
| 15276 | } |
| 15277 | |
| 15278 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15279 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15280 | |
| 15281 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15282 | } |
| 15283 | |
| 15284 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15285 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15286 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15287 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15288 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15289 | pipe_name(pipe)); |
| 15290 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15291 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15292 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15293 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 15294 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE); |
| 15295 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15296 | |
| 15297 | I915_WRITE(PIPECONF(pipe), 0); |
| 15298 | POSTING_READ(PIPECONF(pipe)); |
| 15299 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15300 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15301 | |
| 15302 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15303 | POSTING_READ(DPLL(pipe)); |
| 15304 | } |
| 15305 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15306 | static void |
| 15307 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15308 | { |
| 15309 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15310 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15311 | if (INTEL_GEN(dev_priv) >= 4) |
| 15312 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15313 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15314 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15315 | struct intel_plane *plane = |
| 15316 | to_intel_plane(crtc->base.primary); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15317 | struct intel_crtc *plane_crtc; |
| 15318 | enum pipe pipe; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15319 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15320 | if (!plane->get_hw_state(plane, &pipe)) |
| 15321 | continue; |
| 15322 | |
| 15323 | if (pipe == crtc->pipe) |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15324 | continue; |
| 15325 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15326 | DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", |
| 15327 | plane->base.base.id, plane->base.name); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15328 | |
| 15329 | plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15330 | intel_plane_disable_noatomic(plane_crtc, plane); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15331 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15332 | } |
| 15333 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15334 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15335 | { |
| 15336 | struct drm_device *dev = crtc->base.dev; |
| 15337 | struct intel_encoder *encoder; |
| 15338 | |
| 15339 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15340 | return true; |
| 15341 | |
| 15342 | return false; |
| 15343 | } |
| 15344 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15345 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15346 | { |
| 15347 | struct drm_device *dev = encoder->base.dev; |
| 15348 | struct intel_connector *connector; |
| 15349 | |
| 15350 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15351 | return connector; |
| 15352 | |
| 15353 | return NULL; |
| 15354 | } |
| 15355 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15356 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15357 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15358 | { |
| 15359 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15360 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15361 | } |
| 15362 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15363 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15364 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15365 | { |
| 15366 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15367 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15368 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15369 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15370 | /* 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] | 15371 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15372 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15373 | |
| 15374 | I915_WRITE(reg, |
| 15375 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15376 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15377 | |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 15378 | if (crtc->active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15379 | struct intel_plane *plane; |
| 15380 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15381 | /* Disable everything but the primary plane */ |
| 15382 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15383 | const struct intel_plane_state *plane_state = |
| 15384 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15385 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15386 | if (plane_state->base.visible && |
| 15387 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15388 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15389 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15390 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15391 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15392 | /* Adjust the state of the output pipe according to whether we |
| 15393 | * have active connectors/encoders. */ |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 15394 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15395 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15396 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 15397 | if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15398 | /* |
| 15399 | * We start out with underrun reporting disabled to avoid races. |
| 15400 | * For correct bookkeeping mark this on active crtcs. |
| 15401 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15402 | * Also on gmch platforms we dont have any hardware bits to |
| 15403 | * disable the underrun reporting. Which means we need to start |
| 15404 | * out with underrun reporting disabled also on inactive pipes, |
| 15405 | * since otherwise we'll complain about the garbage we read when |
| 15406 | * e.g. coming up after runtime pm. |
| 15407 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15408 | * No protection against concurrent access is required - at |
| 15409 | * worst a fifo underrun happens which also sets this to false. |
| 15410 | */ |
| 15411 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15412 | /* |
| 15413 | * We track the PCH trancoder underrun reporting state |
| 15414 | * within the crtc. With crtc for pipe A housing the underrun |
| 15415 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15416 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15417 | * and marking underrun reporting as disabled for the non-existing |
| 15418 | * PCH transcoders B and C would prevent enabling the south |
| 15419 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15420 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15421 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15422 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15423 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15424 | } |
| 15425 | |
| 15426 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15427 | { |
| 15428 | struct intel_connector *connector; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15429 | |
| 15430 | /* We need to check both for a crtc link (meaning that the |
| 15431 | * encoder is active and trying to read from a pipe) and the |
| 15432 | * pipe itself being active. */ |
| 15433 | bool has_active_crtc = encoder->base.crtc && |
| 15434 | to_intel_crtc(encoder->base.crtc)->active; |
| 15435 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15436 | connector = intel_encoder_find_connector(encoder); |
| 15437 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15438 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15439 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15440 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15441 | |
| 15442 | /* Connector is active, but has no active pipe. This is |
| 15443 | * fallout from our resume register restoring. Disable |
| 15444 | * the encoder manually again. */ |
| 15445 | if (encoder->base.crtc) { |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15446 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
| 15447 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15448 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15449 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15450 | encoder->base.name); |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15451 | 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] | 15452 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15453 | 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] | 15454 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15455 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15456 | |
| 15457 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15458 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15459 | * in our code, like the register restore mess on resume. Clamp |
| 15460 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15461 | |
| 15462 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15463 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15464 | } |
Maarten Lankhorst | d6cae4a | 2018-05-16 10:50:38 +0200 | [diff] [blame] | 15465 | |
| 15466 | /* notify opregion of the sanitized encoder state */ |
| 15467 | intel_opregion_notify_encoder(encoder, connector && has_active_crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15468 | } |
| 15469 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15470 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15471 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15472 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15473 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15474 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15475 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15476 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15477 | } |
| 15478 | } |
| 15479 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15480 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15481 | { |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15482 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15483 | * at a very early point in our resume sequence, where the power well |
| 15484 | * structures are not yet restored. Since this function is at a very |
| 15485 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15486 | * level, just check if the power well is enabled instead of trying to |
| 15487 | * follow the "don't touch the power well if we don't need it" policy |
| 15488 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15489 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15490 | return; |
| 15491 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15492 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15493 | |
| 15494 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15495 | } |
| 15496 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15497 | /* FIXME read out full plane state for all planes */ |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15498 | static void readout_plane_state(struct drm_i915_private *dev_priv) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15499 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15500 | struct intel_plane *plane; |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15501 | struct intel_crtc *crtc; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15502 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15503 | for_each_intel_plane(&dev_priv->drm, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15504 | struct intel_plane_state *plane_state = |
| 15505 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15506 | struct intel_crtc_state *crtc_state; |
| 15507 | enum pipe pipe = PIPE_A; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 15508 | bool visible; |
| 15509 | |
| 15510 | visible = plane->get_hw_state(plane, &pipe); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15511 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15512 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15513 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15514 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15515 | intel_set_plane_visible(crtc_state, plane_state, visible); |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15516 | |
| 15517 | DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n", |
| 15518 | plane->base.base.id, plane->base.name, |
| 15519 | enableddisabled(visible), pipe_name(pipe)); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15520 | } |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15521 | |
| 15522 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15523 | struct intel_crtc_state *crtc_state = |
| 15524 | to_intel_crtc_state(crtc->base.state); |
| 15525 | |
| 15526 | fixup_active_planes(crtc_state); |
| 15527 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15528 | } |
| 15529 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15530 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15531 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15532 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15533 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15534 | struct intel_crtc *crtc; |
| 15535 | struct intel_encoder *encoder; |
| 15536 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15537 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15538 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15539 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15540 | dev_priv->active_crtcs = 0; |
| 15541 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15542 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15543 | struct intel_crtc_state *crtc_state = |
| 15544 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15545 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15546 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15547 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15548 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15549 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15550 | crtc_state->base.active = crtc_state->base.enable = |
| 15551 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15552 | |
| 15553 | crtc->base.enabled = crtc_state->base.enable; |
| 15554 | crtc->active = crtc_state->base.active; |
| 15555 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15556 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15557 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15558 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15559 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15560 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15561 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15562 | } |
| 15563 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15564 | readout_plane_state(dev_priv); |
| 15565 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15566 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15567 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15568 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15569 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15570 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15571 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15572 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15573 | struct intel_crtc_state *crtc_state = |
| 15574 | to_intel_crtc_state(crtc->base.state); |
| 15575 | |
| 15576 | if (crtc_state->base.active && |
| 15577 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15578 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15579 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15580 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15581 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15582 | 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] | 15583 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15584 | } |
| 15585 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15586 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15587 | pipe = 0; |
| 15588 | |
| 15589 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15590 | struct intel_crtc_state *crtc_state; |
| 15591 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15592 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15593 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15594 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15595 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15596 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15597 | } else { |
| 15598 | encoder->base.crtc = NULL; |
| 15599 | } |
| 15600 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15601 | 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] | 15602 | encoder->base.base.id, encoder->base.name, |
| 15603 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15604 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15605 | } |
| 15606 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15607 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15608 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15609 | if (connector->get_hw_state(connector)) { |
| 15610 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15611 | |
| 15612 | encoder = connector->encoder; |
| 15613 | connector->base.encoder = &encoder->base; |
| 15614 | |
| 15615 | if (encoder->base.crtc && |
| 15616 | encoder->base.crtc->state->active) { |
| 15617 | /* |
| 15618 | * This has to be done during hardware readout |
| 15619 | * because anything calling .crtc_disable may |
| 15620 | * rely on the connector_mask being accurate. |
| 15621 | */ |
| 15622 | encoder->base.crtc->state->connector_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15623 | drm_connector_mask(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15624 | encoder->base.crtc->state->encoder_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15625 | drm_encoder_mask(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15626 | } |
| 15627 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15628 | } else { |
| 15629 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15630 | connector->base.encoder = NULL; |
| 15631 | } |
| 15632 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15633 | connector->base.base.id, connector->base.name, |
| 15634 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15635 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15636 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15637 | |
| 15638 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15639 | struct intel_crtc_state *crtc_state = |
| 15640 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15641 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15642 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15643 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15644 | if (crtc_state->base.active) { |
| 15645 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15646 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15647 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15648 | 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] | 15649 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15650 | |
| 15651 | /* |
| 15652 | * The initial mode needs to be set in order to keep |
| 15653 | * the atomic core happy. It wants a valid mode if the |
| 15654 | * crtc's enabled, so we do the above call. |
| 15655 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 15656 | * But we don't set all the derived state fully, hence |
| 15657 | * set a flag to indicate that a full recalculation is |
| 15658 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15659 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15660 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15661 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 15662 | intel_crtc_compute_pixel_rate(crtc_state); |
| 15663 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15664 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15665 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15666 | if (WARN_ON(min_cdclk < 0)) |
| 15667 | min_cdclk = 0; |
| 15668 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15669 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 15670 | drm_calc_timestamping_constants(&crtc->base, |
| 15671 | &crtc_state->base.adjusted_mode); |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15672 | update_scanline_offset(crtc); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15673 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15674 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15675 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 15676 | dev_priv->min_voltage_level[crtc->pipe] = |
| 15677 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15678 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15679 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15680 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15681 | } |
| 15682 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15683 | static void |
| 15684 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 15685 | { |
| 15686 | struct intel_encoder *encoder; |
| 15687 | |
| 15688 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 15689 | u64 get_domains; |
| 15690 | enum intel_display_power_domain domain; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15691 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15692 | |
| 15693 | if (!encoder->get_power_domains) |
| 15694 | continue; |
| 15695 | |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15696 | /* |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15697 | * MST-primary and inactive encoders don't have a crtc state |
| 15698 | * and neither of these require any power domain references. |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15699 | */ |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15700 | if (!encoder->base.crtc) |
| 15701 | continue; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15702 | |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15703 | crtc_state = to_intel_crtc_state(encoder->base.crtc->state); |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15704 | get_domains = encoder->get_power_domains(encoder, crtc_state); |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15705 | for_each_power_domain(domain, get_domains) |
| 15706 | intel_display_power_get(dev_priv, domain); |
| 15707 | } |
| 15708 | } |
| 15709 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15710 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 15711 | { |
| 15712 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 15713 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 15714 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 15715 | DARBF_GATING_DIS); |
| 15716 | |
| 15717 | if (IS_HASWELL(dev_priv)) { |
| 15718 | /* |
| 15719 | * WaRsPkgCStateDisplayPMReq:hsw |
| 15720 | * System hang if this isn't done before disabling all planes! |
| 15721 | */ |
| 15722 | I915_WRITE(CHICKEN_PAR1_1, |
| 15723 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 15724 | } |
| 15725 | } |
| 15726 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15727 | /* Scan out the current hw modeset state, |
| 15728 | * and sanitizes it to the current state |
| 15729 | */ |
| 15730 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15731 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 15732 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15733 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15734 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15735 | struct intel_crtc *crtc; |
| 15736 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15737 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15738 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15739 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
| 15740 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15741 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15742 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15743 | |
| 15744 | /* 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] | 15745 | get_encoder_power_domains(dev_priv); |
| 15746 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15747 | /* |
| 15748 | * intel_sanitize_plane_mapping() may need to do vblank |
| 15749 | * waits, so we need vblank interrupts restored beforehand. |
| 15750 | */ |
| 15751 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15752 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15753 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15754 | if (crtc->active) |
| 15755 | drm_crtc_vblank_on(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15756 | } |
| 15757 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15758 | intel_sanitize_plane_mapping(dev_priv); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15759 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15760 | for_each_intel_encoder(dev, encoder) |
| 15761 | intel_sanitize_encoder(encoder); |
| 15762 | |
| 15763 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15764 | intel_sanitize_crtc(crtc, ctx); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15765 | intel_dump_pipe_config(crtc, crtc->config, |
| 15766 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15767 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15768 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15769 | intel_modeset_update_connector_atomic_state(dev); |
| 15770 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15771 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15772 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15773 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15774 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15775 | continue; |
| 15776 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 15777 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 15778 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15779 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15780 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15781 | pll->on = false; |
| 15782 | } |
| 15783 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15784 | if (IS_G4X(dev_priv)) { |
| 15785 | g4x_wm_get_hw_state(dev); |
| 15786 | g4x_wm_sanitize(dev_priv); |
| 15787 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 15788 | vlv_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15789 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 15790 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 15791 | skl_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15792 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 15793 | ilk_wm_get_hw_state(dev); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15794 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15795 | |
| 15796 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 15797 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15798 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 15799 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15800 | if (WARN_ON(put_domains)) |
| 15801 | modeset_put_power_domains(dev_priv, put_domains); |
| 15802 | } |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15803 | |
| 15804 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15805 | |
| 15806 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15807 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15808 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15809 | void intel_display_resume(struct drm_device *dev) |
| 15810 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15811 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15812 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15813 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15814 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15815 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15816 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15817 | if (state) |
| 15818 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15819 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15820 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15821 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15822 | while (1) { |
| 15823 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 15824 | if (ret != -EDEADLK) |
| 15825 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15826 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15827 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15828 | } |
| 15829 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15830 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 15831 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15832 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 15833 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15834 | drm_modeset_drop_locks(&ctx); |
| 15835 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15836 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15837 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15838 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 15839 | if (state) |
| 15840 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15841 | } |
| 15842 | |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 15843 | int intel_connector_register(struct drm_connector *connector) |
| 15844 | { |
| 15845 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 15846 | int ret; |
| 15847 | |
| 15848 | ret = intel_backlight_device_register(intel_connector); |
| 15849 | if (ret) |
| 15850 | goto err; |
| 15851 | |
| 15852 | return 0; |
| 15853 | |
| 15854 | err: |
| 15855 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15856 | } |
| 15857 | |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 15858 | void intel_connector_unregister(struct drm_connector *connector) |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15859 | { |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 15860 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15861 | |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 15862 | intel_backlight_device_unregister(intel_connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15863 | intel_panel_destroy_backlight(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15864 | } |
| 15865 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15866 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 15867 | { |
| 15868 | struct intel_connector *connector; |
| 15869 | struct drm_connector_list_iter conn_iter; |
| 15870 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 15871 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15872 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15873 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 15874 | if (connector->modeset_retry_work.func) |
| 15875 | cancel_work_sync(&connector->modeset_retry_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 15876 | if (connector->hdcp_shim) { |
| 15877 | cancel_delayed_work_sync(&connector->hdcp_check_work); |
| 15878 | cancel_work_sync(&connector->hdcp_prop_work); |
| 15879 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15880 | } |
| 15881 | drm_connector_list_iter_end(&conn_iter); |
| 15882 | } |
| 15883 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15884 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15885 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15886 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15887 | |
Chris Wilson | 8bcf9f7 | 2018-07-10 10:44:20 +0100 | [diff] [blame] | 15888 | flush_workqueue(dev_priv->modeset_wq); |
| 15889 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15890 | flush_work(&dev_priv->atomic_helper.free_work); |
| 15891 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 15892 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15893 | /* |
| 15894 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15895 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15896 | * experience fancy races otherwise. |
| 15897 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15898 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15899 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15900 | /* |
| 15901 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15902 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15903 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15904 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15905 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 15906 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 15907 | intel_fbdev_fini(dev_priv); |
| 15908 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15909 | intel_unregister_dsm_handler(); |
| 15910 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 15911 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 15912 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 15913 | /* flush any delayed tasks or pending work */ |
| 15914 | flush_scheduled_work(); |
| 15915 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15916 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 15917 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 15918 | intel_cleanup_overlay(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15919 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 15920 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15921 | |
| 15922 | destroy_workqueue(dev_priv->modeset_wq); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15923 | } |
| 15924 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 15925 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 15926 | struct intel_encoder *encoder) |
| 15927 | { |
| 15928 | connector->encoder = encoder; |
Daniel Vetter | cde4c44 | 2018-07-09 10:40:07 +0200 | [diff] [blame] | 15929 | drm_connector_attach_encoder(&connector->base, &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15930 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15931 | |
| 15932 | /* |
| 15933 | * set vga decode state - true == enable VGA decode |
| 15934 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15935 | 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] | 15936 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15937 | 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] | 15938 | u16 gmch_ctrl; |
| 15939 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15940 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 15941 | DRM_ERROR("failed to read control word\n"); |
| 15942 | return -EIO; |
| 15943 | } |
| 15944 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 15945 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 15946 | return 0; |
| 15947 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15948 | if (state) |
| 15949 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 15950 | else |
| 15951 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 15952 | |
| 15953 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 15954 | DRM_ERROR("failed to write control word\n"); |
| 15955 | return -EIO; |
| 15956 | } |
| 15957 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 15958 | return 0; |
| 15959 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15960 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 15961 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 15962 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15963 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 15964 | |
| 15965 | u32 power_well_driver; |
| 15966 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15967 | int num_transcoders; |
| 15968 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15969 | struct intel_cursor_error_state { |
| 15970 | u32 control; |
| 15971 | u32 position; |
| 15972 | u32 base; |
| 15973 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15974 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15975 | |
| 15976 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15977 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15978 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 15979 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15980 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 15981 | |
| 15982 | struct intel_plane_error_state { |
| 15983 | u32 control; |
| 15984 | u32 stride; |
| 15985 | u32 size; |
| 15986 | u32 pos; |
| 15987 | u32 addr; |
| 15988 | u32 surface; |
| 15989 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 15990 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15991 | |
| 15992 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 15993 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 15994 | enum transcoder cpu_transcoder; |
| 15995 | |
| 15996 | u32 conf; |
| 15997 | |
| 15998 | u32 htotal; |
| 15999 | u32 hblank; |
| 16000 | u32 hsync; |
| 16001 | u32 vtotal; |
| 16002 | u32 vblank; |
| 16003 | u32 vsync; |
| 16004 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16005 | }; |
| 16006 | |
| 16007 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16008 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16009 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16010 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16011 | int transcoders[] = { |
| 16012 | TRANSCODER_A, |
| 16013 | TRANSCODER_B, |
| 16014 | TRANSCODER_C, |
| 16015 | TRANSCODER_EDP, |
| 16016 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16017 | int i; |
| 16018 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16019 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16020 | return NULL; |
| 16021 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16022 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16023 | if (error == NULL) |
| 16024 | return NULL; |
| 16025 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16026 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 16027 | error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16028 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16029 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16030 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16031 | __intel_display_power_is_enabled(dev_priv, |
| 16032 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16033 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16034 | continue; |
| 16035 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16036 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16037 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16038 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16039 | |
| 16040 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16041 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16042 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16043 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16044 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16045 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16046 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16047 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16048 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16049 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16050 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16051 | } |
| 16052 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16053 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16054 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16055 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16056 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16057 | } |
| 16058 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16059 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16060 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 16061 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16062 | error->num_transcoders++; /* Account for eDP. */ |
| 16063 | |
| 16064 | for (i = 0; i < error->num_transcoders; i++) { |
| 16065 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16066 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16067 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16068 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16069 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16070 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16071 | continue; |
| 16072 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16073 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16074 | |
| 16075 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16076 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16077 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16078 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16079 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16080 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16081 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16082 | } |
| 16083 | |
| 16084 | return error; |
| 16085 | } |
| 16086 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16087 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16088 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16089 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16090 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16091 | struct intel_display_error_state *error) |
| 16092 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 16093 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16094 | int i; |
| 16095 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16096 | if (!error) |
| 16097 | return; |
| 16098 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16099 | 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] | 16100 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16101 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16102 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16103 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16104 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16105 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16106 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16107 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16108 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16109 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16110 | err_printf(m, "Plane [%d]:\n", i); |
| 16111 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16112 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16113 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16114 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16115 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16116 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 16117 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16118 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16119 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16120 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16121 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16122 | } |
| 16123 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16124 | err_printf(m, "Cursor [%d]:\n", i); |
| 16125 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16126 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16127 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16128 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16129 | |
| 16130 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16131 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16132 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16133 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16134 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16135 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16136 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16137 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16138 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16139 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16140 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16141 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16142 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16143 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16144 | |
| 16145 | #endif |