Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 27 | #include <linux/module.h> |
| 28 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 32 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 33 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/i915_drm.h> |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 35 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 36 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drm_dp_helper.h> |
| 38 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 39 | #include <drm/drm_plane_helper.h> |
| 40 | #include <drm/drm_rect.h> |
Daniel Vetter | 72fdb40c | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 41 | #include <drm/drm_atomic_uapi.h> |
Lu Baolu | daedaa3 | 2018-11-12 14:40:08 +0800 | [diff] [blame] | 42 | #include <linux/intel-iommu.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 43 | #include <linux/reservation.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 44 | |
Chris Wilson | 9f58892 | 2019-01-16 15:33:04 +0000 | [diff] [blame] | 45 | #include "intel_drv.h" |
| 46 | #include "intel_dsi.h" |
| 47 | #include "intel_frontbuffer.h" |
| 48 | |
| 49 | #include "i915_drv.h" |
| 50 | #include "i915_gem_clflush.h" |
| 51 | #include "i915_reset.h" |
| 52 | #include "i915_trace.h" |
| 53 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 54 | /* Primary plane formats for gen <= 3 */ |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 55 | static const u32 i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 56 | DRM_FORMAT_C8, |
| 57 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 58 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 59 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /* Primary plane formats for gen >= 4 */ |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 63 | static const u32 i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 64 | DRM_FORMAT_C8, |
| 65 | DRM_FORMAT_RGB565, |
| 66 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 67 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 68 | DRM_FORMAT_XRGB2101010, |
| 69 | DRM_FORMAT_XBGR2101010, |
| 70 | }; |
| 71 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 72 | static const u64 i9xx_format_modifiers[] = { |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 73 | I915_FORMAT_MOD_X_TILED, |
| 74 | DRM_FORMAT_MOD_LINEAR, |
| 75 | DRM_FORMAT_MOD_INVALID |
| 76 | }; |
| 77 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 78 | /* Cursor formats */ |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 79 | static const u32 intel_cursor_formats[] = { |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 80 | DRM_FORMAT_ARGB8888, |
| 81 | }; |
| 82 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 83 | static const u64 cursor_format_modifiers[] = { |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 84 | DRM_FORMAT_MOD_LINEAR, |
| 85 | DRM_FORMAT_MOD_INVALID |
| 86 | }; |
| 87 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 88 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 89 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 90 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 91 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 92 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 93 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
| 94 | struct drm_i915_gem_object *obj, |
| 95 | struct drm_mode_fb_cmd2 *mode_cmd); |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 96 | static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state); |
| 97 | static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 98 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 99 | const struct intel_link_m_n *m_n, |
| 100 | const struct intel_link_m_n *m2_n2); |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 101 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 102 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 103 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state); |
| 104 | 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] | 105 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 106 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 107 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 108 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 109 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 110 | 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] | 111 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 112 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 113 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state); |
| 114 | static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state); |
| 115 | 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] | 116 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 117 | struct drm_modeset_acquire_ctx *ctx); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 118 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 119 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 120 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 121 | struct { |
| 122 | int min, max; |
| 123 | } dot, vco, n, m, m1, m2, p, p1; |
| 124 | |
| 125 | struct { |
| 126 | int dot_limit; |
| 127 | int p2_slow, p2_fast; |
| 128 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 129 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 130 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 131 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 132 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 133 | { |
| 134 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 135 | |
| 136 | /* Obtain SKU information */ |
| 137 | mutex_lock(&dev_priv->sb_lock); |
| 138 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 139 | CCK_FUSE_HPLL_FREQ_MASK; |
| 140 | mutex_unlock(&dev_priv->sb_lock); |
| 141 | |
| 142 | return vco_freq[hpll_freq] * 1000; |
| 143 | } |
| 144 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 145 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 146 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 147 | { |
| 148 | u32 val; |
| 149 | int divider; |
| 150 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 151 | mutex_lock(&dev_priv->sb_lock); |
| 152 | val = vlv_cck_read(dev_priv, reg); |
| 153 | mutex_unlock(&dev_priv->sb_lock); |
| 154 | |
| 155 | divider = val & CCK_FREQUENCY_VALUES; |
| 156 | |
| 157 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 158 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 159 | "%s change in progress\n", name); |
| 160 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 161 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 162 | } |
| 163 | |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 164 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 165 | const char *name, u32 reg) |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 166 | { |
| 167 | if (dev_priv->hpll_freq == 0) |
Ville Syrjälä | 49cd97a | 2017-02-07 20:33:45 +0200 | [diff] [blame] | 168 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 169 | |
| 170 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 171 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 172 | } |
| 173 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 174 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 175 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 176 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 177 | return; |
| 178 | |
| 179 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 180 | CCK_CZ_CLOCK_CONTROL); |
| 181 | |
| 182 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 183 | } |
| 184 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 185 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 186 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 187 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 188 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 189 | if (HAS_DDI(dev_priv)) |
| 190 | return pipe_config->port_clock; /* SPLL */ |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 191 | else |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 192 | return dev_priv->fdi_pll_freq; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 193 | } |
| 194 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 195 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 196 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 197 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 198 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 199 | .m = { .min = 96, .max = 140 }, |
| 200 | .m1 = { .min = 18, .max = 26 }, |
| 201 | .m2 = { .min = 6, .max = 16 }, |
| 202 | .p = { .min = 4, .max = 128 }, |
| 203 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 204 | .p2 = { .dot_limit = 165000, |
| 205 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 208 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 209 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 210 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 211 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 212 | .m = { .min = 96, .max = 140 }, |
| 213 | .m1 = { .min = 18, .max = 26 }, |
| 214 | .m2 = { .min = 6, .max = 16 }, |
| 215 | .p = { .min = 4, .max = 128 }, |
| 216 | .p1 = { .min = 2, .max = 33 }, |
| 217 | .p2 = { .dot_limit = 165000, |
| 218 | .p2_slow = 4, .p2_fast = 4 }, |
| 219 | }; |
| 220 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 221 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 222 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 223 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 224 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 225 | .m = { .min = 96, .max = 140 }, |
| 226 | .m1 = { .min = 18, .max = 26 }, |
| 227 | .m2 = { .min = 6, .max = 16 }, |
| 228 | .p = { .min = 4, .max = 128 }, |
| 229 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 230 | .p2 = { .dot_limit = 165000, |
| 231 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 232 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 233 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 234 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 235 | .dot = { .min = 20000, .max = 400000 }, |
| 236 | .vco = { .min = 1400000, .max = 2800000 }, |
| 237 | .n = { .min = 1, .max = 6 }, |
| 238 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 239 | .m1 = { .min = 8, .max = 18 }, |
| 240 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 241 | .p = { .min = 5, .max = 80 }, |
| 242 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 243 | .p2 = { .dot_limit = 200000, |
| 244 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 247 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 248 | .dot = { .min = 20000, .max = 400000 }, |
| 249 | .vco = { .min = 1400000, .max = 2800000 }, |
| 250 | .n = { .min = 1, .max = 6 }, |
| 251 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 252 | .m1 = { .min = 8, .max = 18 }, |
| 253 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 254 | .p = { .min = 7, .max = 98 }, |
| 255 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 256 | .p2 = { .dot_limit = 112000, |
| 257 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 260 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 261 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 262 | .dot = { .min = 25000, .max = 270000 }, |
| 263 | .vco = { .min = 1750000, .max = 3500000}, |
| 264 | .n = { .min = 1, .max = 4 }, |
| 265 | .m = { .min = 104, .max = 138 }, |
| 266 | .m1 = { .min = 17, .max = 23 }, |
| 267 | .m2 = { .min = 5, .max = 11 }, |
| 268 | .p = { .min = 10, .max = 30 }, |
| 269 | .p1 = { .min = 1, .max = 3}, |
| 270 | .p2 = { .dot_limit = 270000, |
| 271 | .p2_slow = 10, |
| 272 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 273 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 274 | }; |
| 275 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 276 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 277 | .dot = { .min = 22000, .max = 400000 }, |
| 278 | .vco = { .min = 1750000, .max = 3500000}, |
| 279 | .n = { .min = 1, .max = 4 }, |
| 280 | .m = { .min = 104, .max = 138 }, |
| 281 | .m1 = { .min = 16, .max = 23 }, |
| 282 | .m2 = { .min = 5, .max = 11 }, |
| 283 | .p = { .min = 5, .max = 80 }, |
| 284 | .p1 = { .min = 1, .max = 8}, |
| 285 | .p2 = { .dot_limit = 165000, |
| 286 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 289 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 290 | .dot = { .min = 20000, .max = 115000 }, |
| 291 | .vco = { .min = 1750000, .max = 3500000 }, |
| 292 | .n = { .min = 1, .max = 3 }, |
| 293 | .m = { .min = 104, .max = 138 }, |
| 294 | .m1 = { .min = 17, .max = 23 }, |
| 295 | .m2 = { .min = 5, .max = 11 }, |
| 296 | .p = { .min = 28, .max = 112 }, |
| 297 | .p1 = { .min = 2, .max = 8 }, |
| 298 | .p2 = { .dot_limit = 0, |
| 299 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 300 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 303 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 304 | .dot = { .min = 80000, .max = 224000 }, |
| 305 | .vco = { .min = 1750000, .max = 3500000 }, |
| 306 | .n = { .min = 1, .max = 3 }, |
| 307 | .m = { .min = 104, .max = 138 }, |
| 308 | .m1 = { .min = 17, .max = 23 }, |
| 309 | .m2 = { .min = 5, .max = 11 }, |
| 310 | .p = { .min = 14, .max = 42 }, |
| 311 | .p1 = { .min = 2, .max = 6 }, |
| 312 | .p2 = { .dot_limit = 0, |
| 313 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 314 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 315 | }; |
| 316 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 317 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 318 | .dot = { .min = 20000, .max = 400000}, |
| 319 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 320 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 321 | .n = { .min = 3, .max = 6 }, |
| 322 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 323 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 324 | .m1 = { .min = 0, .max = 0 }, |
| 325 | .m2 = { .min = 0, .max = 254 }, |
| 326 | .p = { .min = 5, .max = 80 }, |
| 327 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 328 | .p2 = { .dot_limit = 200000, |
| 329 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 330 | }; |
| 331 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 332 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 333 | .dot = { .min = 20000, .max = 400000 }, |
| 334 | .vco = { .min = 1700000, .max = 3500000 }, |
| 335 | .n = { .min = 3, .max = 6 }, |
| 336 | .m = { .min = 2, .max = 256 }, |
| 337 | .m1 = { .min = 0, .max = 0 }, |
| 338 | .m2 = { .min = 0, .max = 254 }, |
| 339 | .p = { .min = 7, .max = 112 }, |
| 340 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 341 | .p2 = { .dot_limit = 112000, |
| 342 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 345 | /* Ironlake / Sandybridge |
| 346 | * |
| 347 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 348 | * the range value for them is (actual_value - 2). |
| 349 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 350 | static const struct intel_limit intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 351 | .dot = { .min = 25000, .max = 350000 }, |
| 352 | .vco = { .min = 1760000, .max = 3510000 }, |
| 353 | .n = { .min = 1, .max = 5 }, |
| 354 | .m = { .min = 79, .max = 127 }, |
| 355 | .m1 = { .min = 12, .max = 22 }, |
| 356 | .m2 = { .min = 5, .max = 9 }, |
| 357 | .p = { .min = 5, .max = 80 }, |
| 358 | .p1 = { .min = 1, .max = 8 }, |
| 359 | .p2 = { .dot_limit = 225000, |
| 360 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 363 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 364 | .dot = { .min = 25000, .max = 350000 }, |
| 365 | .vco = { .min = 1760000, .max = 3510000 }, |
| 366 | .n = { .min = 1, .max = 3 }, |
| 367 | .m = { .min = 79, .max = 118 }, |
| 368 | .m1 = { .min = 12, .max = 22 }, |
| 369 | .m2 = { .min = 5, .max = 9 }, |
| 370 | .p = { .min = 28, .max = 112 }, |
| 371 | .p1 = { .min = 2, .max = 8 }, |
| 372 | .p2 = { .dot_limit = 225000, |
| 373 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 374 | }; |
| 375 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 376 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 377 | .dot = { .min = 25000, .max = 350000 }, |
| 378 | .vco = { .min = 1760000, .max = 3510000 }, |
| 379 | .n = { .min = 1, .max = 3 }, |
| 380 | .m = { .min = 79, .max = 127 }, |
| 381 | .m1 = { .min = 12, .max = 22 }, |
| 382 | .m2 = { .min = 5, .max = 9 }, |
| 383 | .p = { .min = 14, .max = 56 }, |
| 384 | .p1 = { .min = 2, .max = 8 }, |
| 385 | .p2 = { .dot_limit = 225000, |
| 386 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 387 | }; |
| 388 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 389 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 390 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 391 | .dot = { .min = 25000, .max = 350000 }, |
| 392 | .vco = { .min = 1760000, .max = 3510000 }, |
| 393 | .n = { .min = 1, .max = 2 }, |
| 394 | .m = { .min = 79, .max = 126 }, |
| 395 | .m1 = { .min = 12, .max = 22 }, |
| 396 | .m2 = { .min = 5, .max = 9 }, |
| 397 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 398 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 399 | .p2 = { .dot_limit = 225000, |
| 400 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 401 | }; |
| 402 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 403 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 404 | .dot = { .min = 25000, .max = 350000 }, |
| 405 | .vco = { .min = 1760000, .max = 3510000 }, |
| 406 | .n = { .min = 1, .max = 3 }, |
| 407 | .m = { .min = 79, .max = 126 }, |
| 408 | .m1 = { .min = 12, .max = 22 }, |
| 409 | .m2 = { .min = 5, .max = 9 }, |
| 410 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 411 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 412 | .p2 = { .dot_limit = 225000, |
| 413 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 414 | }; |
| 415 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 416 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 417 | /* |
| 418 | * These are the data rate limits (measured in fast clocks) |
| 419 | * since those are the strictest limits we have. The fast |
| 420 | * clock and actual rate limits are more relaxed, so checking |
| 421 | * them would make no difference. |
| 422 | */ |
| 423 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 424 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 425 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 426 | .m1 = { .min = 2, .max = 3 }, |
| 427 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 428 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 429 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 430 | }; |
| 431 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 432 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 433 | /* |
| 434 | * These are the data rate limits (measured in fast clocks) |
| 435 | * since those are the strictest limits we have. The fast |
| 436 | * clock and actual rate limits are more relaxed, so checking |
| 437 | * them would make no difference. |
| 438 | */ |
| 439 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 440 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 441 | .n = { .min = 1, .max = 1 }, |
| 442 | .m1 = { .min = 2, .max = 2 }, |
| 443 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 444 | .p1 = { .min = 2, .max = 4 }, |
| 445 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 446 | }; |
| 447 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 448 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 449 | /* FIXME: find real dot limits */ |
| 450 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 451 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 452 | .n = { .min = 1, .max = 1 }, |
| 453 | .m1 = { .min = 2, .max = 2 }, |
| 454 | /* FIXME: find real m2 limits */ |
| 455 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 456 | .p1 = { .min = 2, .max = 4 }, |
| 457 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 458 | }; |
| 459 | |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 460 | static void |
| 461 | skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable) |
| 462 | { |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 463 | if (enable) |
| 464 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 465 | DUPS1_GATING_DIS | DUPS2_GATING_DIS); |
| 466 | else |
| 467 | I915_WRITE(CLKGATE_DIS_PSL(pipe), |
| 468 | I915_READ(CLKGATE_DIS_PSL(pipe)) & |
| 469 | ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); |
| 470 | } |
| 471 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 472 | static bool |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 473 | needs_modeset(const struct drm_crtc_state *state) |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 474 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 475 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 478 | /* |
| 479 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 480 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 481 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 482 | * The helpers' return value is the rate of the clock that is fed to the |
| 483 | * display engine's pipe which can be the above fast dot clock rate or a |
| 484 | * divided-down version of it. |
| 485 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 486 | /* 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] | 487 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 488 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 489 | clock->m = clock->m2 + 2; |
| 490 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 491 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 492 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 493 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 494 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 495 | |
| 496 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 497 | } |
| 498 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 499 | static u32 i9xx_dpll_compute_m(struct dpll *dpll) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 500 | { |
| 501 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 502 | } |
| 503 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 504 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 505 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 506 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 507 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 508 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 509 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 510 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 511 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 512 | |
| 513 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 516 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 517 | { |
| 518 | clock->m = clock->m1 * clock->m2; |
| 519 | clock->p = clock->p1 * clock->p2; |
| 520 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 521 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 522 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 523 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 524 | |
| 525 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 526 | } |
| 527 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 528 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 529 | { |
| 530 | clock->m = clock->m1 * clock->m2; |
| 531 | clock->p = clock->p1 * clock->p2; |
| 532 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 533 | return 0; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 534 | clock->vco = DIV_ROUND_CLOSEST_ULL((u64)refclk * clock->m, |
| 535 | clock->n << 22); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 536 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 537 | |
| 538 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 539 | } |
| 540 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 541 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 542 | |
| 543 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 544 | * Returns whether the given set of divisors are valid for a given refclk with |
| 545 | * the given connectors. |
| 546 | */ |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 547 | 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] | 548 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 549 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 550 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 551 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 552 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 553 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 554 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 555 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 556 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 557 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 558 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 559 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 560 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 561 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 562 | if (clock->m1 <= clock->m2) |
| 563 | INTELPllInvalid("m1 <= m2\n"); |
| 564 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 565 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 566 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 567 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 568 | INTELPllInvalid("p out of range\n"); |
| 569 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 570 | INTELPllInvalid("m out of range\n"); |
| 571 | } |
| 572 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 573 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 574 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 575 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 576 | * connector, etc., rather than just a single range. |
| 577 | */ |
| 578 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 579 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 580 | |
| 581 | return true; |
| 582 | } |
| 583 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 584 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 585 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 586 | const struct intel_crtc_state *crtc_state, |
| 587 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 588 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 589 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 590 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 591 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 592 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 593 | * For LVDS just rely on its current settings for dual-channel. |
| 594 | * We haven't figured out how to reliably set up different |
| 595 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 596 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 597 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 598 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 600 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 601 | } else { |
| 602 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 603 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 604 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 605 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 606 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 607 | } |
| 608 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 609 | /* |
| 610 | * Returns a set of divisors for the desired target clock with the given |
| 611 | * refclk, or FALSE. The returned values represent the clock equation: |
| 612 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 613 | * |
| 614 | * Target and reference clocks are specified in kHz. |
| 615 | * |
| 616 | * If match_clock is provided, then best_clock P divider must match the P |
| 617 | * divider from @match_clock used for LVDS downclocking. |
| 618 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 619 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 620 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 621 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 622 | int target, int refclk, struct dpll *match_clock, |
| 623 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 624 | { |
| 625 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 626 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 627 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 628 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 629 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 630 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 631 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 632 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 633 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 634 | clock.m1++) { |
| 635 | for (clock.m2 = limit->m2.min; |
| 636 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 637 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 638 | break; |
| 639 | for (clock.n = limit->n.min; |
| 640 | clock.n <= limit->n.max; clock.n++) { |
| 641 | for (clock.p1 = limit->p1.min; |
| 642 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 643 | int this_err; |
| 644 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 645 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 646 | if (!intel_PLL_is_valid(to_i915(dev), |
| 647 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 648 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 649 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 650 | if (match_clock && |
| 651 | clock.p != match_clock->p) |
| 652 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 653 | |
| 654 | this_err = abs(clock.dot - target); |
| 655 | if (this_err < err) { |
| 656 | *best_clock = clock; |
| 657 | err = this_err; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | return (err != target); |
| 665 | } |
| 666 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 667 | /* |
| 668 | * Returns a set of divisors for the desired target clock with the given |
| 669 | * refclk, or FALSE. The returned values represent the clock equation: |
| 670 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 671 | * |
| 672 | * Target and reference clocks are specified in kHz. |
| 673 | * |
| 674 | * If match_clock is provided, then best_clock P divider must match the P |
| 675 | * divider from @match_clock used for LVDS downclocking. |
| 676 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 677 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 678 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 679 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 680 | int target, int refclk, struct dpll *match_clock, |
| 681 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 682 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 683 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 684 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 685 | int err = target; |
| 686 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 687 | memset(best_clock, 0, sizeof(*best_clock)); |
| 688 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 689 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 690 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 691 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 692 | clock.m1++) { |
| 693 | for (clock.m2 = limit->m2.min; |
| 694 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 695 | for (clock.n = limit->n.min; |
| 696 | clock.n <= limit->n.max; clock.n++) { |
| 697 | for (clock.p1 = limit->p1.min; |
| 698 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 699 | int this_err; |
| 700 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 701 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 702 | if (!intel_PLL_is_valid(to_i915(dev), |
| 703 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 704 | &clock)) |
| 705 | continue; |
| 706 | if (match_clock && |
| 707 | clock.p != match_clock->p) |
| 708 | continue; |
| 709 | |
| 710 | this_err = abs(clock.dot - target); |
| 711 | if (this_err < err) { |
| 712 | *best_clock = clock; |
| 713 | err = this_err; |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | return (err != target); |
| 721 | } |
| 722 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 723 | /* |
| 724 | * Returns a set of divisors for the desired target clock with the given |
| 725 | * refclk, or FALSE. The returned values represent the clock equation: |
| 726 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 727 | * |
| 728 | * Target and reference clocks are specified in kHz. |
| 729 | * |
| 730 | * If match_clock is provided, then best_clock P divider must match the P |
| 731 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 732 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 733 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 734 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 735 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 736 | int target, int refclk, struct dpll *match_clock, |
| 737 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 738 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 739 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 740 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 741 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 742 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 743 | /* approximately equals target * 0.00585 */ |
| 744 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 745 | |
| 746 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 747 | |
| 748 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 749 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 750 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 751 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 752 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 753 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 754 | for (clock.m1 = limit->m1.max; |
| 755 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 756 | for (clock.m2 = limit->m2.max; |
| 757 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 758 | for (clock.p1 = limit->p1.max; |
| 759 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 760 | int this_err; |
| 761 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 762 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 763 | if (!intel_PLL_is_valid(to_i915(dev), |
| 764 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 765 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 766 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 767 | |
| 768 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 769 | if (this_err < err_most) { |
| 770 | *best_clock = clock; |
| 771 | err_most = this_err; |
| 772 | max_n = clock.n; |
| 773 | found = true; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 779 | return found; |
| 780 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 781 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 782 | /* |
| 783 | * Check if the calculated PLL configuration is more optimal compared to the |
| 784 | * best configuration and error found so far. Return the calculated error. |
| 785 | */ |
| 786 | 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] | 787 | const struct dpll *calculated_clock, |
| 788 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 789 | unsigned int best_error_ppm, |
| 790 | unsigned int *error_ppm) |
| 791 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 792 | /* |
| 793 | * For CHV ignore the error and consider only the P value. |
| 794 | * Prefer a bigger P value based on HW requirements. |
| 795 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 796 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 797 | *error_ppm = 0; |
| 798 | |
| 799 | return calculated_clock->p > best_clock->p; |
| 800 | } |
| 801 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 802 | if (WARN_ON_ONCE(!target_freq)) |
| 803 | return false; |
| 804 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 805 | *error_ppm = div_u64(1000000ULL * |
| 806 | abs(target_freq - calculated_clock->dot), |
| 807 | target_freq); |
| 808 | /* |
| 809 | * Prefer a better P value over a better (smaller) error if the error |
| 810 | * is small. Ensure this preference for future configurations too by |
| 811 | * setting the error to 0. |
| 812 | */ |
| 813 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 814 | *error_ppm = 0; |
| 815 | |
| 816 | return true; |
| 817 | } |
| 818 | |
| 819 | return *error_ppm + 10 < best_error_ppm; |
| 820 | } |
| 821 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 822 | /* |
| 823 | * Returns a set of divisors for the desired target clock with the given |
| 824 | * refclk, or FALSE. The returned values represent the clock equation: |
| 825 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 826 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 827 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 828 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 829 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 830 | int target, int refclk, struct dpll *match_clock, |
| 831 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 832 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 833 | 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] | 834 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 835 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 836 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 837 | /* min update 19.2 MHz */ |
| 838 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 839 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 840 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 841 | target *= 5; /* fast clock */ |
| 842 | |
| 843 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 844 | |
| 845 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 846 | 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] | 847 | 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] | 848 | 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] | 849 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 850 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 851 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 852 | 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] | 853 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 854 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 855 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 856 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 857 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 858 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 859 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 860 | if (!intel_PLL_is_valid(to_i915(dev), |
| 861 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 862 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 863 | continue; |
| 864 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 865 | if (!vlv_PLL_is_optimal(dev, target, |
| 866 | &clock, |
| 867 | best_clock, |
| 868 | bestppm, &ppm)) |
| 869 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 870 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 871 | *best_clock = clock; |
| 872 | bestppm = ppm; |
| 873 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | } |
| 877 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 878 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 879 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 880 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 881 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 882 | /* |
| 883 | * Returns a set of divisors for the desired target clock with the given |
| 884 | * refclk, or FALSE. The returned values represent the clock equation: |
| 885 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 886 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 887 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 888 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 889 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 890 | int target, int refclk, struct dpll *match_clock, |
| 891 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 892 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 893 | 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] | 894 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 895 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 896 | struct dpll clock; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 897 | u64 m2; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 898 | int found = false; |
| 899 | |
| 900 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 901 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 902 | |
| 903 | /* |
| 904 | * Based on hardware doc, the n always set to 1, and m1 always |
| 905 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 906 | * revisit this because n may not 1 anymore. |
| 907 | */ |
| 908 | clock.n = 1, clock.m1 = 2; |
| 909 | target *= 5; /* fast clock */ |
| 910 | |
| 911 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 912 | for (clock.p2 = limit->p2.p2_fast; |
| 913 | clock.p2 >= limit->p2.p2_slow; |
| 914 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 915 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 916 | |
| 917 | clock.p = clock.p1 * clock.p2; |
| 918 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 919 | m2 = DIV_ROUND_CLOSEST_ULL(((u64)target * clock.p * |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 920 | clock.n) << 22, refclk * clock.m1); |
| 921 | |
| 922 | if (m2 > INT_MAX/clock.m1) |
| 923 | continue; |
| 924 | |
| 925 | clock.m2 = m2; |
| 926 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 927 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 928 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 929 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 930 | continue; |
| 931 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 932 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 933 | best_error_ppm, &error_ppm)) |
| 934 | continue; |
| 935 | |
| 936 | *best_clock = clock; |
| 937 | best_error_ppm = error_ppm; |
| 938 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | return found; |
| 943 | } |
| 944 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 945 | 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] | 946 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 947 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 948 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 949 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 950 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 951 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 952 | target_clock, refclk, NULL, best_clock); |
| 953 | } |
| 954 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 955 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 956 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 957 | /* Be paranoid as we can arrive here with only partial |
| 958 | * state retrieved from the hardware during setup. |
| 959 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 960 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 961 | * as Haswell has gained clock readout/fastboot support. |
| 962 | * |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 963 | * 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] | 964 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 965 | * |
| 966 | * FIXME: The intel_crtc->active here should be switched to |
| 967 | * crtc->state->active once we have proper CRTC states wired up |
| 968 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 969 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 970 | return crtc->active && crtc->base.primary->state->fb && |
| 971 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 972 | } |
| 973 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 974 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 975 | enum pipe pipe) |
| 976 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 977 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 978 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 979 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 980 | } |
| 981 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 982 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
| 983 | enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 984 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 985 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 986 | u32 line1, line2; |
| 987 | u32 line_mask; |
| 988 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 989 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 990 | line_mask = DSL_LINEMASK_GEN2; |
| 991 | else |
| 992 | line_mask = DSL_LINEMASK_GEN3; |
| 993 | |
| 994 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 995 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 996 | line2 = I915_READ(reg) & line_mask; |
| 997 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 998 | return line1 != line2; |
| 999 | } |
| 1000 | |
| 1001 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) |
| 1002 | { |
| 1003 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1004 | enum pipe pipe = crtc->pipe; |
| 1005 | |
| 1006 | /* Wait for the display line to settle/start moving */ |
| 1007 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) |
| 1008 | DRM_ERROR("pipe %c scanline %s wait timed out\n", |
| 1009 | pipe_name(pipe), onoff(state)); |
| 1010 | } |
| 1011 | |
| 1012 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) |
| 1013 | { |
| 1014 | wait_for_pipe_scanline_moving(crtc, false); |
| 1015 | } |
| 1016 | |
| 1017 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) |
| 1018 | { |
| 1019 | wait_for_pipe_scanline_moving(crtc, true); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1020 | } |
| 1021 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1022 | static void |
| 1023 | 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] | 1024 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1025 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1026 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1027 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1028 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1029 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1030 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1031 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1032 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1033 | if (intel_wait_for_register(dev_priv, |
| 1034 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1035 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1036 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1037 | } else { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1038 | intel_wait_for_pipe_scanline_stopped(crtc); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1039 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1042 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1043 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1044 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1045 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1046 | u32 val; |
| 1047 | bool cur_state; |
| 1048 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1049 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1050 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1051 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1052 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1053 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1054 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1055 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1056 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1057 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1058 | { |
| 1059 | u32 val; |
| 1060 | bool cur_state; |
| 1061 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1062 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1063 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1064 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1065 | |
| 1066 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1067 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1068 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1069 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1070 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1071 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1072 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1073 | enum pipe pipe, bool state) |
| 1074 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1075 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1076 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1077 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1078 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1079 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1080 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1081 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1082 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1083 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1084 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1085 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1086 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1087 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1088 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1089 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1090 | } |
| 1091 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1092 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1093 | |
| 1094 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1095 | enum pipe pipe, bool state) |
| 1096 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1097 | u32 val; |
| 1098 | bool cur_state; |
| 1099 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1100 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1101 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1102 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1103 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1104 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1105 | } |
| 1106 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1107 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1108 | |
| 1109 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1110 | enum pipe pipe) |
| 1111 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1112 | u32 val; |
| 1113 | |
| 1114 | /* ILK FDI PLL is always enabled */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1115 | if (IS_GEN(dev_priv, 5)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1116 | return; |
| 1117 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1118 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1119 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1120 | return; |
| 1121 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1122 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1123 | 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] | 1124 | } |
| 1125 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1126 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1127 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1128 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1129 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1130 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1131 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1132 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1133 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1134 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1135 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1136 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1139 | 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] | 1140 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1141 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1142 | u32 val; |
Ville Syrjälä | 10ed55e | 2018-05-23 17:57:18 +0300 | [diff] [blame] | 1143 | enum pipe panel_pipe = INVALID_PIPE; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1144 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1145 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1146 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1147 | return; |
| 1148 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1149 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1150 | u32 port_sel; |
| 1151 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1152 | pp_reg = PP_CONTROL(0); |
| 1153 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1154 | |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1155 | switch (port_sel) { |
| 1156 | case PANEL_PORT_SELECT_LVDS: |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1157 | intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe); |
Ville Syrjälä | 4c23dea | 2018-05-18 18:29:30 +0300 | [diff] [blame] | 1158 | break; |
| 1159 | case PANEL_PORT_SELECT_DPA: |
| 1160 | intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe); |
| 1161 | break; |
| 1162 | case PANEL_PORT_SELECT_DPC: |
| 1163 | intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe); |
| 1164 | break; |
| 1165 | case PANEL_PORT_SELECT_DPD: |
| 1166 | intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe); |
| 1167 | break; |
| 1168 | default: |
| 1169 | MISSING_CASE(port_sel); |
| 1170 | break; |
| 1171 | } |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1172 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1173 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1174 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1175 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1176 | } else { |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1177 | u32 port_sel; |
| 1178 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1179 | pp_reg = PP_CONTROL(0); |
Ville Syrjälä | f0d2b75 | 2018-05-18 18:29:31 +0300 | [diff] [blame] | 1180 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
| 1181 | |
| 1182 | WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS); |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1183 | intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | val = I915_READ(pp_reg); |
| 1187 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1188 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1189 | locked = false; |
| 1190 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1191 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1192 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1193 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1196 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1197 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1198 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1199 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1200 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1201 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1202 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 1203 | intel_wakeref_t wakeref; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1204 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1205 | /* we keep both pipes enabled on 830 */ |
| 1206 | if (IS_I830(dev_priv)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1207 | state = true; |
| 1208 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1209 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 1210 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 1211 | if (wakeref) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1212 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1213 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1214 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 1215 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1216 | } else { |
| 1217 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1218 | } |
| 1219 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1220 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1221 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1222 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1225 | static void assert_plane(struct intel_plane *plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1226 | { |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 1227 | enum pipe pipe; |
| 1228 | bool cur_state; |
| 1229 | |
| 1230 | cur_state = plane->get_hw_state(plane, &pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1231 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1232 | I915_STATE_WARN(cur_state != state, |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1233 | "%s assertion failure (expected %s, current %s)\n", |
| 1234 | plane->base.name, 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 | #define assert_plane_enabled(p) assert_plane(p, true) |
| 1238 | #define assert_plane_disabled(p) assert_plane(p, false) |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1239 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1240 | static void assert_planes_disabled(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1241 | { |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1242 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1243 | struct intel_plane *plane; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1244 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1245 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
| 1246 | assert_plane_disabled(plane); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1249 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1250 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1251 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1252 | drm_crtc_vblank_put(crtc); |
| 1253 | } |
| 1254 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1255 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1256 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1257 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1258 | u32 val; |
| 1259 | bool enabled; |
| 1260 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1261 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1262 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1263 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1264 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1265 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1268 | 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] | 1269 | enum pipe pipe, enum port port, |
| 1270 | i915_reg_t dp_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1271 | { |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1272 | enum pipe port_pipe; |
| 1273 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1274 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1275 | state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe); |
| 1276 | |
| 1277 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1278 | "PCH DP %c enabled on transcoder %c, should be disabled\n", |
| 1279 | port_name(port), pipe_name(pipe)); |
| 1280 | |
| 1281 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1282 | "IBX PCH DP %c still using transcoder B\n", |
| 1283 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | 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] | 1287 | enum pipe pipe, enum port port, |
| 1288 | i915_reg_t hdmi_reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1289 | { |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1290 | enum pipe port_pipe; |
| 1291 | bool state; |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1292 | |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1293 | state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe); |
| 1294 | |
| 1295 | I915_STATE_WARN(state && port_pipe == pipe, |
| 1296 | "PCH HDMI %c enabled on transcoder %c, should be disabled\n", |
| 1297 | port_name(port), pipe_name(pipe)); |
| 1298 | |
| 1299 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B, |
| 1300 | "IBX PCH HDMI %c still using transcoder B\n", |
| 1301 | port_name(port)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1305 | enum pipe pipe) |
| 1306 | { |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1307 | enum pipe port_pipe; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1308 | |
Ville Syrjälä | 59b74c4 | 2018-05-18 18:29:28 +0300 | [diff] [blame] | 1309 | assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B); |
| 1310 | assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C); |
| 1311 | assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1312 | |
Ville Syrjälä | 6102a8e | 2018-05-14 20:24:19 +0300 | [diff] [blame] | 1313 | I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) && |
| 1314 | port_pipe == pipe, |
| 1315 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
| 1316 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1317 | |
Ville Syrjälä | a44628b | 2018-05-14 21:28:27 +0300 | [diff] [blame] | 1318 | I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) && |
| 1319 | port_pipe == pipe, |
| 1320 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
| 1321 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1322 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 1323 | /* PCH SDVOB multiplex with HDMIB */ |
Ville Syrjälä | 7620346 | 2018-05-14 20:24:21 +0300 | [diff] [blame] | 1324 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB); |
| 1325 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC); |
| 1326 | assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1329 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1330 | const struct intel_crtc_state *pipe_config) |
| 1331 | { |
| 1332 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1333 | enum pipe pipe = crtc->pipe; |
| 1334 | |
| 1335 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1336 | POSTING_READ(DPLL(pipe)); |
| 1337 | udelay(150); |
| 1338 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1339 | if (intel_wait_for_register(dev_priv, |
| 1340 | DPLL(pipe), |
| 1341 | DPLL_LOCK_VLV, |
| 1342 | DPLL_LOCK_VLV, |
| 1343 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1344 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1345 | } |
| 1346 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1347 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1348 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1349 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1350 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1351 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1352 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1353 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1354 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1355 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1356 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1357 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1358 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1359 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1360 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1361 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1362 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1363 | } |
| 1364 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1365 | |
| 1366 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1367 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1368 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1369 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1370 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1371 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1372 | u32 tmp; |
| 1373 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1374 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1375 | |
| 1376 | /* Enable back the 10bit clock to display controller */ |
| 1377 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1378 | tmp |= DPIO_DCLKP_EN; |
| 1379 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1380 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1381 | mutex_unlock(&dev_priv->sb_lock); |
| 1382 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1383 | /* |
| 1384 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1385 | */ |
| 1386 | udelay(1); |
| 1387 | |
| 1388 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1389 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1390 | |
| 1391 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1392 | if (intel_wait_for_register(dev_priv, |
| 1393 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1394 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1395 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1399 | const struct intel_crtc_state *pipe_config) |
| 1400 | { |
| 1401 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1402 | enum pipe pipe = crtc->pipe; |
| 1403 | |
| 1404 | assert_pipe_disabled(dev_priv, pipe); |
| 1405 | |
| 1406 | /* PLL is protected by panel, make sure we can write it */ |
| 1407 | assert_panel_unlocked(dev_priv, pipe); |
| 1408 | |
| 1409 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1410 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1411 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1412 | if (pipe != PIPE_A) { |
| 1413 | /* |
| 1414 | * WaPixelRepeatModeFixForC0:chv |
| 1415 | * |
| 1416 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1417 | * the value from DPLLBMD to either pipe B or C. |
| 1418 | */ |
Ville Syrjälä | dfa311f | 2017-09-13 17:08:54 +0300 | [diff] [blame] | 1419 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1420 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1421 | I915_WRITE(CBR4_VLV, 0); |
| 1422 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1423 | |
| 1424 | /* |
| 1425 | * DPLLB VGA mode also seems to cause problems. |
| 1426 | * We should always have it disabled. |
| 1427 | */ |
| 1428 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1429 | } else { |
| 1430 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1431 | POSTING_READ(DPLL_MD(pipe)); |
| 1432 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1433 | } |
| 1434 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1435 | 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] | 1436 | { |
| 1437 | struct intel_crtc *crtc; |
| 1438 | int count = 0; |
| 1439 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1440 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1441 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1442 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1443 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1444 | |
| 1445 | return count; |
| 1446 | } |
| 1447 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1448 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
| 1449 | const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1450 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1451 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1452 | i915_reg_t reg = DPLL(crtc->pipe); |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1453 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1454 | int i; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1455 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1456 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1457 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1458 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1459 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1460 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1461 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1462 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1463 | 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] | 1464 | /* |
| 1465 | * It appears to be important that we don't enable this |
| 1466 | * for the current pipe before otherwise configuring the |
| 1467 | * PLL. No idea how this should be handled if multiple |
| 1468 | * DVO outputs are enabled simultaneosly. |
| 1469 | */ |
| 1470 | dpll |= DPLL_DVO_2X_MODE; |
| 1471 | I915_WRITE(DPLL(!crtc->pipe), |
| 1472 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1473 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1474 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1475 | /* |
| 1476 | * Apparently we need to have VGA mode enabled prior to changing |
| 1477 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1478 | * dividers, even though the register value does change. |
| 1479 | */ |
| 1480 | I915_WRITE(reg, 0); |
| 1481 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1482 | I915_WRITE(reg, dpll); |
| 1483 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1484 | /* Wait for the clocks to stabilize. */ |
| 1485 | POSTING_READ(reg); |
| 1486 | udelay(150); |
| 1487 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1488 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1489 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 1490 | crtc_state->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1491 | } else { |
| 1492 | /* The pixel multiplier can only be updated once the |
| 1493 | * DPLL is enabled and the clocks are stable. |
| 1494 | * |
| 1495 | * So write it again. |
| 1496 | */ |
| 1497 | I915_WRITE(reg, dpll); |
| 1498 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1499 | |
| 1500 | /* We do this three times for luck */ |
Ville Syrjälä | bb408dd | 2017-06-01 17:36:15 +0300 | [diff] [blame] | 1501 | for (i = 0; i < 3; i++) { |
| 1502 | I915_WRITE(reg, dpll); |
| 1503 | POSTING_READ(reg); |
| 1504 | udelay(150); /* wait for warmup */ |
| 1505 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1508 | static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1509 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1510 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1511 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1512 | enum pipe pipe = crtc->pipe; |
| 1513 | |
| 1514 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1515 | if (IS_I830(dev_priv) && |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 1516 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1517 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1518 | I915_WRITE(DPLL(PIPE_B), |
| 1519 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1520 | I915_WRITE(DPLL(PIPE_A), |
| 1521 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1522 | } |
| 1523 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1524 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1525 | if (IS_I830(dev_priv)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1526 | return; |
| 1527 | |
| 1528 | /* Make sure the pipe isn't still relying on us */ |
| 1529 | assert_pipe_disabled(dev_priv, pipe); |
| 1530 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1531 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1532 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1535 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1536 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1537 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1538 | |
| 1539 | /* Make sure the pipe isn't still relying on us */ |
| 1540 | assert_pipe_disabled(dev_priv, pipe); |
| 1541 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1542 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1543 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1544 | if (pipe != PIPE_A) |
| 1545 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1546 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1547 | I915_WRITE(DPLL(pipe), val); |
| 1548 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1552 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1553 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1554 | u32 val; |
| 1555 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1556 | /* Make sure the pipe isn't still relying on us */ |
| 1557 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1558 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1559 | val = DPLL_SSC_REF_CLK_CHV | |
| 1560 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1561 | if (pipe != PIPE_A) |
| 1562 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1563 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1564 | I915_WRITE(DPLL(pipe), val); |
| 1565 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1566 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1567 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1568 | |
| 1569 | /* Disable 10bit clock to display controller */ |
| 1570 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1571 | val &= ~DPIO_DCLKP_EN; |
| 1572 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1573 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1574 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1577 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1578 | struct intel_digital_port *dport, |
| 1579 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1580 | { |
| 1581 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1582 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1583 | |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 1584 | switch (dport->base.port) { |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1585 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1586 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1587 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1588 | break; |
| 1589 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1590 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1591 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1592 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1593 | break; |
| 1594 | case PORT_D: |
| 1595 | port_mask = DPLL_PORTD_READY_MASK; |
| 1596 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1597 | break; |
| 1598 | default: |
| 1599 | BUG(); |
| 1600 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1601 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1602 | if (intel_wait_for_register(dev_priv, |
| 1603 | dpll_reg, port_mask, expected_mask, |
| 1604 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1605 | 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] | 1606 | port_name(dport->base.port), |
| 1607 | I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1610 | 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] | 1611 | { |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1612 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1613 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1614 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1615 | i915_reg_t reg; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 1616 | u32 val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1617 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1618 | /* Make sure PCH DPLL is enabled */ |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1619 | assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1620 | |
| 1621 | /* FDI must be feeding us bits for PCH ports */ |
| 1622 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1623 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1624 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1625 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1626 | /* Workaround: Set the timing override bit before enabling the |
| 1627 | * pch transcoder. */ |
| 1628 | reg = TRANS_CHICKEN2(pipe); |
| 1629 | val = I915_READ(reg); |
| 1630 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1631 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1632 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1633 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1634 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1635 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1636 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1637 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1638 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1639 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1640 | * Make the BPC in transcoder be consistent with |
| 1641 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1642 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1643 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1644 | val &= ~PIPECONF_BPC_MASK; |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1645 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1646 | val |= PIPECONF_8BPC; |
| 1647 | else |
| 1648 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1649 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1650 | |
| 1651 | val &= ~TRANS_INTERLACE_MASK; |
| 1652 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1653 | if (HAS_PCH_IBX(dev_priv) && |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 1654 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1655 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1656 | else |
| 1657 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1658 | else |
| 1659 | val |= TRANS_PROGRESSIVE; |
| 1660 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1661 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1662 | if (intel_wait_for_register(dev_priv, |
| 1663 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1664 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1665 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1666 | } |
| 1667 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1668 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1669 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1670 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1671 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1672 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1673 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1674 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1675 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1676 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1677 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1678 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1679 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1680 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1681 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1682 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1683 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1684 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1685 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1686 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1687 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1688 | else |
| 1689 | val |= TRANS_PROGRESSIVE; |
| 1690 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1691 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1692 | if (intel_wait_for_register(dev_priv, |
| 1693 | LPT_TRANSCONF, |
| 1694 | TRANS_STATE_ENABLE, |
| 1695 | TRANS_STATE_ENABLE, |
| 1696 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1697 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1698 | } |
| 1699 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1700 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1701 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1702 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1703 | i915_reg_t reg; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 1704 | u32 val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1705 | |
| 1706 | /* FDI relies on the transcoder */ |
| 1707 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1708 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1709 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1710 | /* Ports must be off as well */ |
| 1711 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1712 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1713 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1714 | val = I915_READ(reg); |
| 1715 | val &= ~TRANS_ENABLE; |
| 1716 | I915_WRITE(reg, val); |
| 1717 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1718 | if (intel_wait_for_register(dev_priv, |
| 1719 | reg, TRANS_STATE_ENABLE, 0, |
| 1720 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1721 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1722 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1723 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1724 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1725 | reg = TRANS_CHICKEN2(pipe); |
| 1726 | val = I915_READ(reg); |
| 1727 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1728 | I915_WRITE(reg, val); |
| 1729 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1732 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1733 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1734 | u32 val; |
| 1735 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1736 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1737 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1738 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1739 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1740 | if (intel_wait_for_register(dev_priv, |
| 1741 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1742 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1743 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1744 | |
| 1745 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1746 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1747 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1748 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1751 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1752 | { |
| 1753 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1754 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1755 | if (HAS_PCH_LPT(dev_priv)) |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1756 | return PIPE_A; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1757 | else |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1758 | return crtc->pipe; |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1759 | } |
| 1760 | |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 1761 | static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state) |
| 1762 | { |
| 1763 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 1764 | |
| 1765 | /* |
| 1766 | * On i965gm the hardware frame counter reads |
| 1767 | * zero when the TV encoder is enabled :( |
| 1768 | */ |
| 1769 | if (IS_I965GM(dev_priv) && |
| 1770 | (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT))) |
| 1771 | return 0; |
| 1772 | |
| 1773 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 1774 | return 0xffffffff; /* full 32 bit counter */ |
| 1775 | else if (INTEL_GEN(dev_priv) >= 3) |
| 1776 | return 0xffffff; /* only 24 bits of frame count */ |
| 1777 | else |
| 1778 | return 0; /* Gen2 doesn't have a hardware frame counter */ |
| 1779 | } |
| 1780 | |
| 1781 | static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state) |
| 1782 | { |
| 1783 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 1784 | |
| 1785 | drm_crtc_set_max_vblank_count(&crtc->base, |
| 1786 | intel_crtc_max_vblank_count(crtc_state)); |
| 1787 | drm_crtc_vblank_on(&crtc->base); |
| 1788 | } |
| 1789 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1790 | 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] | 1791 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1792 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1793 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1794 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1795 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1796 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1797 | u32 val; |
| 1798 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1799 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1800 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1801 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1802 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1803 | /* |
| 1804 | * A pipe without a PLL won't actually be able to drive bits from |
| 1805 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1806 | * need the check. |
| 1807 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 1808 | if (HAS_GMCH(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1809 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1810 | assert_dsi_pll_enabled(dev_priv); |
| 1811 | else |
| 1812 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1813 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1814 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1815 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1816 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1817 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1818 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1819 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1820 | } |
| 1821 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1822 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1823 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1824 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1825 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1826 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1827 | /* we keep both pipes enabled on 830 */ |
| 1828 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1829 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1830 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1831 | |
| 1832 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1833 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1834 | |
| 1835 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1836 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1837 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1838 | * resets to its proper value. That also messes up the frame count |
| 1839 | * when it's derived from the timestamps. So let's wait for the |
| 1840 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1841 | */ |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 1842 | if (intel_crtc_max_vblank_count(new_crtc_state) == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1843 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1844 | } |
| 1845 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1846 | 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] | 1847 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1848 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1849 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1850 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1851 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1852 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1853 | u32 val; |
| 1854 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1855 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1856 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1857 | /* |
| 1858 | * Make sure planes won't keep trying to pump pixels to us, |
| 1859 | * or we might hang the display. |
| 1860 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1861 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1862 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1863 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1864 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1865 | if ((val & PIPECONF_ENABLE) == 0) |
| 1866 | return; |
| 1867 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1868 | /* |
| 1869 | * Double wide has implications for planes |
| 1870 | * so best keep it disabled when not needed. |
| 1871 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1872 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1873 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1874 | |
| 1875 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1876 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1877 | val &= ~PIPECONF_ENABLE; |
| 1878 | |
| 1879 | I915_WRITE(reg, val); |
| 1880 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1881 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1882 | } |
| 1883 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1884 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1885 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1886 | return IS_GEN(dev_priv, 2) ? 2048 : 4096; |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1889 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1890 | 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] | 1891 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1892 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1893 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1894 | |
| 1895 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1896 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1897 | return cpp; |
| 1898 | case I915_FORMAT_MOD_X_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1899 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1900 | return 128; |
| 1901 | else |
| 1902 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1903 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1904 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1905 | return 128; |
| 1906 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1907 | case I915_FORMAT_MOD_Y_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1908 | if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv)) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1909 | return 128; |
| 1910 | else |
| 1911 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1912 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1913 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1914 | return 128; |
| 1915 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1916 | case I915_FORMAT_MOD_Yf_TILED: |
| 1917 | switch (cpp) { |
| 1918 | case 1: |
| 1919 | return 64; |
| 1920 | case 2: |
| 1921 | case 4: |
| 1922 | return 128; |
| 1923 | case 8: |
| 1924 | case 16: |
| 1925 | return 256; |
| 1926 | default: |
| 1927 | MISSING_CASE(cpp); |
| 1928 | return cpp; |
| 1929 | } |
| 1930 | break; |
| 1931 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1932 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1933 | return cpp; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1937 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1938 | intel_tile_height(const struct drm_framebuffer *fb, int color_plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1939 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1940 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1941 | return 1; |
| 1942 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1943 | return intel_tile_size(to_i915(fb->dev)) / |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1944 | intel_tile_width_bytes(fb, color_plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1947 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1948 | 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] | 1949 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1950 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1951 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1952 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane); |
| 1953 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1954 | |
| 1955 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1956 | *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] | 1957 | } |
| 1958 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1959 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1960 | intel_fb_align_height(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1961 | int color_plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1962 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1963 | unsigned int tile_height = intel_tile_height(fb, color_plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1964 | |
| 1965 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1968 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1969 | { |
| 1970 | unsigned int size = 0; |
| 1971 | int i; |
| 1972 | |
| 1973 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1974 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1975 | |
| 1976 | return size; |
| 1977 | } |
| 1978 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 1979 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 1980 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 1981 | const struct drm_framebuffer *fb, |
| 1982 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 1983 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1984 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 1985 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1986 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 1987 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1991 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 1992 | { |
| 1993 | if (IS_I830(dev_priv)) |
| 1994 | return 16 * 1024; |
| 1995 | else if (IS_I85X(dev_priv)) |
| 1996 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 1997 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 1998 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1999 | else |
| 2000 | return 4 * 1024; |
| 2001 | } |
| 2002 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2003 | 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] | 2004 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 2005 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2006 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 2007 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2008 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2009 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 2010 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2011 | return 4 * 1024; |
| 2012 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2013 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2014 | } |
| 2015 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2016 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2017 | int color_plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2018 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2019 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2020 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2021 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2022 | if (color_plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 2023 | return 4096; |
| 2024 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2025 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2026 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2027 | return intel_linear_alignment(dev_priv); |
| 2028 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2029 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2030 | return 256 * 1024; |
| 2031 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2032 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2033 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2034 | case I915_FORMAT_MOD_Y_TILED: |
| 2035 | case I915_FORMAT_MOD_Yf_TILED: |
| 2036 | return 1 * 1024 * 1024; |
| 2037 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2038 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2039 | return 0; |
| 2040 | } |
| 2041 | } |
| 2042 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2043 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2044 | { |
| 2045 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2046 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2047 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2048 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2049 | } |
| 2050 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2051 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2052 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2053 | const struct i915_ggtt_view *view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2054 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2055 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2056 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2057 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2058 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2059 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2060 | intel_wakeref_t wakeref; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2061 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2062 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2063 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2064 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2065 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2066 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2067 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2068 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2069 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2070 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2071 | * we should always have valid PTE following the scanout preventing |
| 2072 | * the VT-d warning. |
| 2073 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2074 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2075 | alignment = 256 * 1024; |
| 2076 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2077 | /* |
| 2078 | * Global gtt pte registers are special registers which actually forward |
| 2079 | * writes to a chunk of system memory. Which means that there is no risk |
| 2080 | * that the register values disappear as soon as we call |
| 2081 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2082 | * pin/unpin/fence and not more. |
| 2083 | */ |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2084 | wakeref = intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2085 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2086 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2087 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2088 | pinctl = 0; |
| 2089 | |
| 2090 | /* Valleyview is definitely limited to scanning out the first |
| 2091 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2092 | * g4x display engine and that all earlier gen are similarly |
| 2093 | * limited. Testing suggests that it is a little more |
| 2094 | * complicated than this. For example, Cherryview appears quite |
| 2095 | * happy to scanout from anywhere within its global aperture. |
| 2096 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 2097 | if (HAS_GMCH(dev_priv)) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2098 | pinctl |= PIN_MAPPABLE; |
| 2099 | |
| 2100 | vma = i915_gem_object_pin_to_display_plane(obj, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2101 | alignment, view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2102 | if (IS_ERR(vma)) |
| 2103 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2104 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2105 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2106 | int ret; |
| 2107 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2108 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2109 | * fence, whereas 965+ only requires a fence if using |
| 2110 | * framebuffer compression. For simplicity, we always, when |
| 2111 | * possible, install a fence as the cost is not that onerous. |
| 2112 | * |
| 2113 | * If we fail to fence the tiled scanout, then either the |
| 2114 | * modeset will reject the change (which is highly unlikely as |
| 2115 | * the affected systems, all but one, do not have unmappable |
| 2116 | * space) or we will not be able to enable full powersaving |
| 2117 | * techniques (also likely not to apply due to various limits |
| 2118 | * FBC and the like impose on the size of the buffer, which |
| 2119 | * presumably we violated anyway with this unmappable buffer). |
| 2120 | * Anyway, it is presumably better to stumble onwards with |
| 2121 | * something and try to run the system in a "less than optimal" |
| 2122 | * mode that matches the user configuration. |
| 2123 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2124 | ret = i915_vma_pin_fence(vma); |
| 2125 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2126 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2127 | vma = ERR_PTR(ret); |
| 2128 | goto err; |
| 2129 | } |
| 2130 | |
| 2131 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2132 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2133 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2134 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2135 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2136 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2137 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2138 | |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2139 | intel_runtime_pm_put(dev_priv, wakeref); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2140 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2141 | } |
| 2142 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2143 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2144 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2145 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2146 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2147 | if (flags & PLANE_HAS_FENCE) |
| 2148 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2149 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2150 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2151 | } |
| 2152 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2153 | 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] | 2154 | unsigned int rotation) |
| 2155 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2156 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2157 | return to_intel_framebuffer(fb)->rotated[color_plane].pitch; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2158 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2159 | return fb->pitches[color_plane]; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2160 | } |
| 2161 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2162 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2163 | * Convert the x/y offsets into a linear offset. |
| 2164 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2165 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2166 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2167 | */ |
| 2168 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2169 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2170 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2171 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2172 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2173 | unsigned int cpp = fb->format->cpp[color_plane]; |
| 2174 | unsigned int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2175 | |
| 2176 | return y * pitch + x * cpp; |
| 2177 | } |
| 2178 | |
| 2179 | /* |
| 2180 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2181 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2182 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2183 | */ |
| 2184 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2185 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2186 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2187 | |
| 2188 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2189 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2190 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2191 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2192 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2193 | *x += intel_fb->rotated[color_plane].x; |
| 2194 | *y += intel_fb->rotated[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2195 | } else { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2196 | *x += intel_fb->normal[color_plane].x; |
| 2197 | *y += intel_fb->normal[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2201 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2202 | unsigned int tile_width, |
| 2203 | unsigned int tile_height, |
| 2204 | unsigned int tile_size, |
| 2205 | unsigned int pitch_tiles, |
| 2206 | u32 old_offset, |
| 2207 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2208 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2209 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2210 | unsigned int tiles; |
| 2211 | |
| 2212 | WARN_ON(old_offset & (tile_size - 1)); |
| 2213 | WARN_ON(new_offset & (tile_size - 1)); |
| 2214 | WARN_ON(new_offset > old_offset); |
| 2215 | |
| 2216 | tiles = (old_offset - new_offset) / tile_size; |
| 2217 | |
| 2218 | *y += tiles / pitch_tiles * tile_height; |
| 2219 | *x += tiles % pitch_tiles * tile_width; |
| 2220 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2221 | /* minimize x in case it got needlessly big */ |
| 2222 | *y += *x / pitch_pixels * tile_height; |
| 2223 | *x %= pitch_pixels; |
| 2224 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2225 | return new_offset; |
| 2226 | } |
| 2227 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2228 | static bool is_surface_linear(u64 modifier, int color_plane) |
| 2229 | { |
| 2230 | return modifier == DRM_FORMAT_MOD_LINEAR; |
| 2231 | } |
| 2232 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2233 | static u32 intel_adjust_aligned_offset(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2234 | const struct drm_framebuffer *fb, |
| 2235 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2236 | unsigned int rotation, |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2237 | unsigned int pitch, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2238 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2239 | { |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2240 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2241 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2242 | |
| 2243 | WARN_ON(new_offset > old_offset); |
| 2244 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2245 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2246 | unsigned int tile_size, tile_width, tile_height; |
| 2247 | unsigned int pitch_tiles; |
| 2248 | |
| 2249 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2250 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2251 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2252 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2253 | pitch_tiles = pitch / tile_height; |
| 2254 | swap(tile_width, tile_height); |
| 2255 | } else { |
| 2256 | pitch_tiles = pitch / (tile_width * cpp); |
| 2257 | } |
| 2258 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2259 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2260 | tile_size, pitch_tiles, |
| 2261 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2262 | } else { |
| 2263 | old_offset += *y * pitch + *x * cpp; |
| 2264 | |
| 2265 | *y = (old_offset - new_offset) / pitch; |
| 2266 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2267 | } |
| 2268 | |
| 2269 | return new_offset; |
| 2270 | } |
| 2271 | |
| 2272 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2273 | * Adjust the tile offset by moving the difference into |
| 2274 | * the x/y offsets. |
| 2275 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2276 | static u32 intel_plane_adjust_aligned_offset(int *x, int *y, |
| 2277 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2278 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2279 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2280 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2281 | 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] | 2282 | state->base.rotation, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2283 | state->color_plane[color_plane].stride, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2284 | old_offset, new_offset); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /* |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2288 | * Computes the aligned offset to the base tile and adjusts |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2289 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2290 | * |
| 2291 | * In the 90/270 rotated case, x and y are assumed |
| 2292 | * to be already rotated to match the rotated GTT view, and |
| 2293 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2294 | * |
| 2295 | * This function is used when computing the derived information |
| 2296 | * under intel_framebuffer, so using any of that information |
| 2297 | * here is not allowed. Anything under drm_framebuffer can be |
| 2298 | * used. This is why the user has to pass in the pitch since it |
| 2299 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2300 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2301 | static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv, |
| 2302 | int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2303 | const struct drm_framebuffer *fb, |
| 2304 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2305 | unsigned int pitch, |
| 2306 | unsigned int rotation, |
| 2307 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2308 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2309 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2310 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2311 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2312 | if (alignment) |
| 2313 | alignment--; |
| 2314 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2315 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2316 | unsigned int tile_size, tile_width, tile_height; |
| 2317 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2318 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2319 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2320 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2321 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2322 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2323 | pitch_tiles = pitch / tile_height; |
| 2324 | swap(tile_width, tile_height); |
| 2325 | } else { |
| 2326 | pitch_tiles = pitch / (tile_width * cpp); |
| 2327 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2328 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2329 | tile_rows = *y / tile_height; |
| 2330 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2331 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2332 | tiles = *x / tile_width; |
| 2333 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2334 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2335 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2336 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2337 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2338 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2339 | tile_size, pitch_tiles, |
| 2340 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2341 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2342 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2343 | offset_aligned = offset & ~alignment; |
| 2344 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2345 | *y = (offset & alignment) / pitch; |
| 2346 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2347 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2348 | |
| 2349 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2350 | } |
| 2351 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2352 | static u32 intel_plane_compute_aligned_offset(int *x, int *y, |
| 2353 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2354 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2355 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2356 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2357 | 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] | 2358 | const struct drm_framebuffer *fb = state->base.fb; |
| 2359 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2360 | int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2361 | u32 alignment; |
| 2362 | |
| 2363 | if (intel_plane->id == PLANE_CURSOR) |
| 2364 | alignment = intel_cursor_alignment(dev_priv); |
| 2365 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2366 | alignment = intel_surf_alignment(fb, color_plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2367 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2368 | 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] | 2369 | pitch, rotation, alignment); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2370 | } |
| 2371 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2372 | /* Convert the fb->offset[] into x/y offsets */ |
| 2373 | static int intel_fb_offset_to_xy(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2374 | const struct drm_framebuffer *fb, |
| 2375 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2376 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2377 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2378 | unsigned int height; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2379 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2380 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2381 | fb->offsets[color_plane] % intel_tile_size(dev_priv)) { |
| 2382 | DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n", |
| 2383 | fb->offsets[color_plane], color_plane); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2384 | return -EINVAL; |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | height = drm_framebuffer_plane_height(fb->height, fb, color_plane); |
| 2388 | height = ALIGN(height, intel_tile_height(fb, color_plane)); |
| 2389 | |
| 2390 | /* Catch potential overflows early */ |
| 2391 | if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]), |
| 2392 | fb->offsets[color_plane])) { |
| 2393 | DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n", |
| 2394 | fb->offsets[color_plane], fb->pitches[color_plane], |
| 2395 | color_plane); |
| 2396 | return -ERANGE; |
| 2397 | } |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2398 | |
| 2399 | *x = 0; |
| 2400 | *y = 0; |
| 2401 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2402 | intel_adjust_aligned_offset(x, y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2403 | fb, color_plane, DRM_MODE_ROTATE_0, |
| 2404 | fb->pitches[color_plane], |
| 2405 | fb->offsets[color_plane], 0); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2406 | |
| 2407 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2408 | } |
| 2409 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 2410 | static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier) |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2411 | { |
| 2412 | switch (fb_modifier) { |
| 2413 | case I915_FORMAT_MOD_X_TILED: |
| 2414 | return I915_TILING_X; |
| 2415 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2416 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2417 | return I915_TILING_Y; |
| 2418 | default: |
| 2419 | return I915_TILING_NONE; |
| 2420 | } |
| 2421 | } |
| 2422 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2423 | /* |
| 2424 | * From the Sky Lake PRM: |
| 2425 | * "The Color Control Surface (CCS) contains the compression status of |
| 2426 | * the cache-line pairs. The compression state of the cache-line pair |
| 2427 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2428 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2429 | * cache-line-pairs. CCS is always Y tiled." |
| 2430 | * |
| 2431 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2432 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2433 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2434 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2435 | * main surface. |
| 2436 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2437 | static const struct drm_format_info ccs_formats[] = { |
| 2438 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2439 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2440 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2441 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2442 | }; |
| 2443 | |
| 2444 | static const struct drm_format_info * |
| 2445 | lookup_format_info(const struct drm_format_info formats[], |
| 2446 | int num_formats, u32 format) |
| 2447 | { |
| 2448 | int i; |
| 2449 | |
| 2450 | for (i = 0; i < num_formats; i++) { |
| 2451 | if (formats[i].format == format) |
| 2452 | return &formats[i]; |
| 2453 | } |
| 2454 | |
| 2455 | return NULL; |
| 2456 | } |
| 2457 | |
| 2458 | static const struct drm_format_info * |
| 2459 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2460 | { |
| 2461 | switch (cmd->modifier[0]) { |
| 2462 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2463 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2464 | return lookup_format_info(ccs_formats, |
| 2465 | ARRAY_SIZE(ccs_formats), |
| 2466 | cmd->pixel_format); |
| 2467 | default: |
| 2468 | return NULL; |
| 2469 | } |
| 2470 | } |
| 2471 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2472 | bool is_ccs_modifier(u64 modifier) |
| 2473 | { |
| 2474 | return modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2475 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 2476 | } |
| 2477 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2478 | static int |
| 2479 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2480 | struct drm_framebuffer *fb) |
| 2481 | { |
| 2482 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2483 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2484 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2485 | u32 gtt_offset_rotated = 0; |
| 2486 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2487 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2488 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2489 | |
| 2490 | for (i = 0; i < num_planes; i++) { |
| 2491 | unsigned int width, height; |
| 2492 | unsigned int cpp, size; |
| 2493 | u32 offset; |
| 2494 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2495 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2496 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2497 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2498 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2499 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2500 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2501 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2502 | if (ret) { |
| 2503 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2504 | i, fb->offsets[i]); |
| 2505 | return ret; |
| 2506 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2507 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2508 | if (is_ccs_modifier(fb->modifier) && i == 1) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2509 | int hsub = fb->format->hsub; |
| 2510 | int vsub = fb->format->vsub; |
| 2511 | int tile_width, tile_height; |
| 2512 | int main_x, main_y; |
| 2513 | int ccs_x, ccs_y; |
| 2514 | |
| 2515 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2516 | tile_width *= hsub; |
| 2517 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2518 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2519 | ccs_x = (x * hsub) % tile_width; |
| 2520 | ccs_y = (y * vsub) % tile_height; |
| 2521 | main_x = intel_fb->normal[0].x % tile_width; |
| 2522 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2523 | |
| 2524 | /* |
| 2525 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2526 | * x/y offsets must match between CCS and the main surface. |
| 2527 | */ |
| 2528 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2529 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2530 | main_x, main_y, |
| 2531 | ccs_x, ccs_y, |
| 2532 | intel_fb->normal[0].x, |
| 2533 | intel_fb->normal[0].y, |
| 2534 | x, y); |
| 2535 | return -EINVAL; |
| 2536 | } |
| 2537 | } |
| 2538 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2539 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2540 | * The fence (if used) is aligned to the start of the object |
| 2541 | * so having the framebuffer wrap around across the edge of the |
| 2542 | * fenced region doesn't really work. We have no API to configure |
| 2543 | * the fence start offset within the object (nor could we probably |
| 2544 | * on gen2/3). So it's just easier if we just require that the |
| 2545 | * fb layout agrees with the fence layout. We already check that the |
| 2546 | * fb stride matches the fence stride elsewhere. |
| 2547 | */ |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2548 | if (i == 0 && i915_gem_object_is_tiled(obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2549 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2550 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2551 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2552 | return -EINVAL; |
| 2553 | } |
| 2554 | |
| 2555 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2556 | * First pixel of the framebuffer from |
| 2557 | * the start of the normal gtt mapping. |
| 2558 | */ |
| 2559 | intel_fb->normal[i].x = x; |
| 2560 | intel_fb->normal[i].y = y; |
| 2561 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2562 | offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i, |
| 2563 | fb->pitches[i], |
| 2564 | DRM_MODE_ROTATE_0, |
| 2565 | tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2566 | offset /= tile_size; |
| 2567 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2568 | if (!is_surface_linear(fb->modifier, i)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2569 | unsigned int tile_width, tile_height; |
| 2570 | unsigned int pitch_tiles; |
| 2571 | struct drm_rect r; |
| 2572 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2573 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2574 | |
| 2575 | rot_info->plane[i].offset = offset; |
| 2576 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2577 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2578 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2579 | |
| 2580 | intel_fb->rotated[i].pitch = |
| 2581 | rot_info->plane[i].height * tile_height; |
| 2582 | |
| 2583 | /* how many tiles does this plane need */ |
| 2584 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2585 | /* |
| 2586 | * If the plane isn't horizontally tile aligned, |
| 2587 | * we need one more tile. |
| 2588 | */ |
| 2589 | if (x != 0) |
| 2590 | size++; |
| 2591 | |
| 2592 | /* rotate the x/y offsets to match the GTT view */ |
| 2593 | r.x1 = x; |
| 2594 | r.y1 = y; |
| 2595 | r.x2 = x + width; |
| 2596 | r.y2 = y + height; |
| 2597 | drm_rect_rotate(&r, |
| 2598 | rot_info->plane[i].width * tile_width, |
| 2599 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2600 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2601 | x = r.x1; |
| 2602 | y = r.y1; |
| 2603 | |
| 2604 | /* rotate the tile dimensions to match the GTT view */ |
| 2605 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2606 | swap(tile_width, tile_height); |
| 2607 | |
| 2608 | /* |
| 2609 | * We only keep the x/y offsets, so push all of the |
| 2610 | * gtt offset into the x/y offsets. |
| 2611 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2612 | intel_adjust_tile_offset(&x, &y, |
| 2613 | tile_width, tile_height, |
| 2614 | tile_size, pitch_tiles, |
| 2615 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2616 | |
| 2617 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2618 | |
| 2619 | /* |
| 2620 | * First pixel of the framebuffer from |
| 2621 | * the start of the rotated gtt mapping. |
| 2622 | */ |
| 2623 | intel_fb->rotated[i].x = x; |
| 2624 | intel_fb->rotated[i].y = y; |
| 2625 | } else { |
| 2626 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2627 | x * cpp, tile_size); |
| 2628 | } |
| 2629 | |
| 2630 | /* how many tiles in total needed in the bo */ |
| 2631 | max_size = max(max_size, offset + size); |
| 2632 | } |
| 2633 | |
Ville Syrjälä | 4e05047 | 2018-09-12 21:04:43 +0300 | [diff] [blame] | 2634 | if (mul_u32_u32(max_size, tile_size) > obj->base.size) { |
| 2635 | DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n", |
| 2636 | mul_u32_u32(max_size, tile_size), obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2637 | return -EINVAL; |
| 2638 | } |
| 2639 | |
| 2640 | return 0; |
| 2641 | } |
| 2642 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2643 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2644 | { |
| 2645 | switch (format) { |
| 2646 | case DISPPLANE_8BPP: |
| 2647 | return DRM_FORMAT_C8; |
| 2648 | case DISPPLANE_BGRX555: |
| 2649 | return DRM_FORMAT_XRGB1555; |
| 2650 | case DISPPLANE_BGRX565: |
| 2651 | return DRM_FORMAT_RGB565; |
| 2652 | default: |
| 2653 | case DISPPLANE_BGRX888: |
| 2654 | return DRM_FORMAT_XRGB8888; |
| 2655 | case DISPPLANE_RGBX888: |
| 2656 | return DRM_FORMAT_XBGR8888; |
| 2657 | case DISPPLANE_BGRX101010: |
| 2658 | return DRM_FORMAT_XRGB2101010; |
| 2659 | case DISPPLANE_RGBX101010: |
| 2660 | return DRM_FORMAT_XBGR2101010; |
| 2661 | } |
| 2662 | } |
| 2663 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2664 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2665 | { |
| 2666 | switch (format) { |
| 2667 | case PLANE_CTL_FORMAT_RGB_565: |
| 2668 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2669 | case PLANE_CTL_FORMAT_NV12: |
| 2670 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2671 | default: |
| 2672 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2673 | if (rgb_order) { |
| 2674 | if (alpha) |
| 2675 | return DRM_FORMAT_ABGR8888; |
| 2676 | else |
| 2677 | return DRM_FORMAT_XBGR8888; |
| 2678 | } else { |
| 2679 | if (alpha) |
| 2680 | return DRM_FORMAT_ARGB8888; |
| 2681 | else |
| 2682 | return DRM_FORMAT_XRGB8888; |
| 2683 | } |
| 2684 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2685 | if (rgb_order) |
| 2686 | return DRM_FORMAT_XBGR2101010; |
| 2687 | else |
| 2688 | return DRM_FORMAT_XRGB2101010; |
| 2689 | } |
| 2690 | } |
| 2691 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2692 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2693 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2694 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2695 | { |
| 2696 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2697 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2698 | struct drm_i915_gem_object *obj = NULL; |
| 2699 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2700 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2701 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2702 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2703 | PAGE_SIZE); |
| 2704 | |
| 2705 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2706 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2707 | if (plane_config->size == 0) |
| 2708 | return false; |
| 2709 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2710 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2711 | * important and we should probably use that space with FBC or other |
| 2712 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2713 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2714 | return false; |
| 2715 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2716 | switch (fb->modifier) { |
| 2717 | case DRM_FORMAT_MOD_LINEAR: |
| 2718 | case I915_FORMAT_MOD_X_TILED: |
| 2719 | case I915_FORMAT_MOD_Y_TILED: |
| 2720 | break; |
| 2721 | default: |
| 2722 | DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n", |
| 2723 | fb->modifier); |
| 2724 | return false; |
| 2725 | } |
| 2726 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2727 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2728 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2729 | base_aligned, |
| 2730 | base_aligned, |
| 2731 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2732 | mutex_unlock(&dev->struct_mutex); |
| 2733 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2734 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2735 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2736 | switch (plane_config->tiling) { |
| 2737 | case I915_TILING_NONE: |
| 2738 | break; |
| 2739 | case I915_TILING_X: |
| 2740 | case I915_TILING_Y: |
| 2741 | obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling; |
| 2742 | break; |
| 2743 | default: |
| 2744 | MISSING_CASE(plane_config->tiling); |
| 2745 | return false; |
| 2746 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2747 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2748 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2749 | mode_cmd.width = fb->width; |
| 2750 | mode_cmd.height = fb->height; |
| 2751 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2752 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2753 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2754 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2755 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2756 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2757 | goto out_unref_obj; |
| 2758 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2759 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2760 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2761 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2762 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2763 | |
| 2764 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2765 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2766 | return false; |
| 2767 | } |
| 2768 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2769 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2770 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2771 | struct intel_plane_state *plane_state, |
| 2772 | bool visible) |
| 2773 | { |
| 2774 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2775 | |
| 2776 | plane_state->base.visible = visible; |
| 2777 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2778 | if (visible) |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2779 | crtc_state->base.plane_mask |= drm_plane_mask(&plane->base); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2780 | else |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2781 | crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2782 | } |
| 2783 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2784 | static void fixup_active_planes(struct intel_crtc_state *crtc_state) |
| 2785 | { |
| 2786 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2787 | struct drm_plane *plane; |
| 2788 | |
| 2789 | /* |
| 2790 | * Active_planes aliases if multiple "primary" or cursor planes |
| 2791 | * have been used on the same (or wrong) pipe. plane_mask uses |
| 2792 | * unique ids, hence we can use that to reconstruct active_planes. |
| 2793 | */ |
| 2794 | crtc_state->active_planes = 0; |
| 2795 | |
| 2796 | drm_for_each_plane_mask(plane, &dev_priv->drm, |
| 2797 | crtc_state->base.plane_mask) |
| 2798 | crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); |
| 2799 | } |
| 2800 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2801 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2802 | struct intel_plane *plane) |
| 2803 | { |
| 2804 | struct intel_crtc_state *crtc_state = |
| 2805 | to_intel_crtc_state(crtc->base.state); |
| 2806 | struct intel_plane_state *plane_state = |
| 2807 | to_intel_plane_state(plane->base.state); |
| 2808 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 2809 | DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", |
| 2810 | plane->base.base.id, plane->base.name, |
| 2811 | crtc->base.base.id, crtc->base.name); |
| 2812 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2813 | intel_set_plane_visible(crtc_state, plane_state, false); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2814 | fixup_active_planes(crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2815 | |
| 2816 | if (plane->id == PLANE_PRIMARY) |
| 2817 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2818 | |
| 2819 | trace_intel_disable_plane(&plane->base, crtc); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 2820 | plane->disable_plane(plane, crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2821 | } |
| 2822 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2823 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2824 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2825 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2826 | { |
| 2827 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2828 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2829 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2830 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2831 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2832 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2833 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2834 | struct intel_plane_state *intel_state = |
| 2835 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2836 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2837 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2838 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2839 | return; |
| 2840 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2841 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2842 | fb = &plane_config->fb->base; |
| 2843 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2844 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2845 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2846 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2847 | |
| 2848 | /* |
| 2849 | * Failed to alloc the obj, check to see if we should share |
| 2850 | * an fb with another CRTC instead |
| 2851 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2852 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2853 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2854 | |
| 2855 | if (c == &intel_crtc->base) |
| 2856 | continue; |
| 2857 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2858 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2859 | continue; |
| 2860 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2861 | state = to_intel_plane_state(c->primary->state); |
| 2862 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2863 | continue; |
| 2864 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2865 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2866 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2867 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2868 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2869 | } |
| 2870 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2871 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2872 | /* |
| 2873 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2874 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2875 | * which will lead to problems later if we don't fix it up. The |
| 2876 | * simplest solution is to just disable the primary plane now and |
| 2877 | * pretend the BIOS never had it enabled. |
| 2878 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2879 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2880 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2881 | return; |
| 2882 | |
| 2883 | valid_fb: |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 2884 | intel_state->base.rotation = plane_config->rotation; |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2885 | intel_fill_fb_ggtt_view(&intel_state->view, fb, |
| 2886 | intel_state->base.rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2887 | intel_state->color_plane[0].stride = |
| 2888 | intel_fb_pitch(fb, 0, intel_state->base.rotation); |
| 2889 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2890 | mutex_lock(&dev->struct_mutex); |
| 2891 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2892 | intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2893 | &intel_state->view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2894 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2895 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2896 | mutex_unlock(&dev->struct_mutex); |
| 2897 | if (IS_ERR(intel_state->vma)) { |
| 2898 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2899 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2900 | |
| 2901 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2902 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2903 | return; |
| 2904 | } |
| 2905 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2906 | obj = intel_fb_obj(fb); |
| 2907 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2908 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2909 | plane_state->src_x = 0; |
| 2910 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2911 | plane_state->src_w = fb->width << 16; |
| 2912 | plane_state->src_h = fb->height << 16; |
| 2913 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2914 | plane_state->crtc_x = 0; |
| 2915 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2916 | plane_state->crtc_w = fb->width; |
| 2917 | plane_state->crtc_h = fb->height; |
| 2918 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2919 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2920 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2921 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2922 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2923 | dev_priv->preserve_bios_swizzle = true; |
| 2924 | |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 2925 | plane_state->fb = fb; |
| 2926 | plane_state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2927 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2928 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2929 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2930 | } |
| 2931 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2932 | static int skl_max_plane_width(const struct drm_framebuffer *fb, |
| 2933 | int color_plane, |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2934 | unsigned int rotation) |
| 2935 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2936 | int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2937 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2938 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2939 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2940 | case I915_FORMAT_MOD_X_TILED: |
| 2941 | switch (cpp) { |
| 2942 | case 8: |
| 2943 | return 4096; |
| 2944 | case 4: |
| 2945 | case 2: |
| 2946 | case 1: |
| 2947 | return 8192; |
| 2948 | default: |
| 2949 | MISSING_CASE(cpp); |
| 2950 | break; |
| 2951 | } |
| 2952 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2953 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2954 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2955 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2956 | case I915_FORMAT_MOD_Y_TILED: |
| 2957 | case I915_FORMAT_MOD_Yf_TILED: |
| 2958 | switch (cpp) { |
| 2959 | case 8: |
| 2960 | return 2048; |
| 2961 | case 4: |
| 2962 | return 4096; |
| 2963 | case 2: |
| 2964 | case 1: |
| 2965 | return 8192; |
| 2966 | default: |
| 2967 | MISSING_CASE(cpp); |
| 2968 | break; |
| 2969 | } |
| 2970 | break; |
| 2971 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2972 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | return 2048; |
| 2976 | } |
| 2977 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2978 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2979 | int main_x, int main_y, u32 main_offset) |
| 2980 | { |
| 2981 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2982 | int hsub = fb->format->hsub; |
| 2983 | int vsub = fb->format->vsub; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2984 | int aux_x = plane_state->color_plane[1].x; |
| 2985 | int aux_y = plane_state->color_plane[1].y; |
| 2986 | u32 aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2987 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2988 | |
| 2989 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2990 | int x, y; |
| 2991 | |
| 2992 | if (aux_x == main_x && aux_y == main_y) |
| 2993 | break; |
| 2994 | |
| 2995 | if (aux_offset == 0) |
| 2996 | break; |
| 2997 | |
| 2998 | x = aux_x / hsub; |
| 2999 | y = aux_y / vsub; |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3000 | aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1, |
| 3001 | aux_offset, aux_offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3002 | aux_x = x * hsub + aux_x % hsub; |
| 3003 | aux_y = y * vsub + aux_y % vsub; |
| 3004 | } |
| 3005 | |
| 3006 | if (aux_x != main_x || aux_y != main_y) |
| 3007 | return false; |
| 3008 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3009 | plane_state->color_plane[1].offset = aux_offset; |
| 3010 | plane_state->color_plane[1].x = aux_x; |
| 3011 | plane_state->color_plane[1].y = aux_y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3012 | |
| 3013 | return true; |
| 3014 | } |
| 3015 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3016 | 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] | 3017 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3018 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3019 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3020 | int x = plane_state->base.src.x1 >> 16; |
| 3021 | int y = plane_state->base.src.y1 >> 16; |
| 3022 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3023 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3024 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 3025 | int max_height = 4096; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3026 | u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3027 | |
| 3028 | if (w > max_width || h > max_height) { |
| 3029 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 3030 | w, h, max_width, max_height); |
| 3031 | return -EINVAL; |
| 3032 | } |
| 3033 | |
| 3034 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3035 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3036 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3037 | |
| 3038 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3039 | * AUX surface offset is specified as the distance from the |
| 3040 | * main surface offset, and it must be non-negative. Make |
| 3041 | * sure that is what we will get. |
| 3042 | */ |
| 3043 | if (offset > aux_offset) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3044 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3045 | offset, aux_offset & ~(alignment - 1)); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3046 | |
| 3047 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3048 | * When using an X-tiled surface, the plane blows up |
| 3049 | * if the x offset + width exceed the stride. |
| 3050 | * |
| 3051 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 3052 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3053 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3054 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3055 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3056 | while ((x + w) * cpp > plane_state->color_plane[0].stride) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3057 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3058 | 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] | 3059 | return -EINVAL; |
| 3060 | } |
| 3061 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3062 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3063 | offset, offset - alignment); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3064 | } |
| 3065 | } |
| 3066 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3067 | /* |
| 3068 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3069 | * they match with the main surface x/y offsets. |
| 3070 | */ |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3071 | if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3072 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3073 | if (offset == 0) |
| 3074 | break; |
| 3075 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3076 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3077 | offset, offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3080 | 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] | 3081 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3082 | return -EINVAL; |
| 3083 | } |
| 3084 | } |
| 3085 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3086 | plane_state->color_plane[0].offset = offset; |
| 3087 | plane_state->color_plane[0].x = x; |
| 3088 | plane_state->color_plane[0].y = y; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3089 | |
| 3090 | return 0; |
| 3091 | } |
| 3092 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3093 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3094 | { |
| 3095 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3096 | unsigned int rotation = plane_state->base.rotation; |
| 3097 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3098 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3099 | int x = plane_state->base.src.x1 >> 17; |
| 3100 | int y = plane_state->base.src.y1 >> 17; |
| 3101 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3102 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3103 | u32 offset; |
| 3104 | |
| 3105 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3106 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3107 | |
| 3108 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3109 | if (w > max_width || h > max_height) { |
| 3110 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3111 | w, h, max_width, max_height); |
| 3112 | return -EINVAL; |
| 3113 | } |
| 3114 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3115 | plane_state->color_plane[1].offset = offset; |
| 3116 | plane_state->color_plane[1].x = x; |
| 3117 | plane_state->color_plane[1].y = y; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3118 | |
| 3119 | return 0; |
| 3120 | } |
| 3121 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3122 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3123 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3124 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3125 | int src_x = plane_state->base.src.x1 >> 16; |
| 3126 | int src_y = plane_state->base.src.y1 >> 16; |
| 3127 | int hsub = fb->format->hsub; |
| 3128 | int vsub = fb->format->vsub; |
| 3129 | int x = src_x / hsub; |
| 3130 | int y = src_y / vsub; |
| 3131 | u32 offset; |
| 3132 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3133 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3134 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3135 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3136 | plane_state->color_plane[1].offset = offset; |
| 3137 | plane_state->color_plane[1].x = x * hsub + src_x % hsub; |
| 3138 | plane_state->color_plane[1].y = y * vsub + src_y % vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3139 | |
| 3140 | return 0; |
| 3141 | } |
| 3142 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3143 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3144 | { |
| 3145 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3146 | unsigned int rotation = plane_state->base.rotation; |
| 3147 | int ret; |
| 3148 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3149 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3150 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3151 | plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation); |
| 3152 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3153 | ret = intel_plane_check_stride(plane_state); |
| 3154 | if (ret) |
| 3155 | return ret; |
| 3156 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3157 | if (!plane_state->base.visible) |
| 3158 | return 0; |
| 3159 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3160 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3161 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3162 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3163 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3164 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3165 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3166 | /* |
| 3167 | * Handle the AUX surface first since |
| 3168 | * the main surface setup depends on it. |
| 3169 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3170 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3171 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3172 | if (ret) |
| 3173 | return ret; |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3174 | } else if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3175 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3176 | if (ret) |
| 3177 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3178 | } else { |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3179 | plane_state->color_plane[1].offset = ~0xfff; |
| 3180 | plane_state->color_plane[1].x = 0; |
| 3181 | plane_state->color_plane[1].y = 0; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3182 | } |
| 3183 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3184 | ret = skl_check_main_surface(plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3185 | if (ret) |
| 3186 | return ret; |
| 3187 | |
| 3188 | return 0; |
| 3189 | } |
| 3190 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3191 | unsigned int |
| 3192 | i9xx_plane_max_stride(struct intel_plane *plane, |
| 3193 | u32 pixel_format, u64 modifier, |
| 3194 | unsigned int rotation) |
| 3195 | { |
| 3196 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3197 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 3198 | if (!HAS_GMCH(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3199 | return 32*1024; |
| 3200 | } else if (INTEL_GEN(dev_priv) >= 4) { |
| 3201 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3202 | return 16*1024; |
| 3203 | else |
| 3204 | return 32*1024; |
| 3205 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 3206 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3207 | return 8*1024; |
| 3208 | else |
| 3209 | return 16*1024; |
| 3210 | } else { |
| 3211 | if (plane->i9xx_plane == PLANE_C) |
| 3212 | return 4*1024; |
| 3213 | else |
| 3214 | return 8*1024; |
| 3215 | } |
| 3216 | } |
| 3217 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3218 | static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3219 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3220 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3221 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3222 | u32 dspcntr = 0; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3223 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 3224 | if (crtc_state->gamma_enable) |
| 3225 | dspcntr |= DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3226 | |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 3227 | if (crtc_state->csc_enable) |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3228 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3229 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3230 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3231 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3232 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3233 | return dspcntr; |
| 3234 | } |
| 3235 | |
| 3236 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3237 | const struct intel_plane_state *plane_state) |
| 3238 | { |
| 3239 | struct drm_i915_private *dev_priv = |
| 3240 | to_i915(plane_state->base.plane->dev); |
| 3241 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3242 | unsigned int rotation = plane_state->base.rotation; |
| 3243 | u32 dspcntr; |
| 3244 | |
| 3245 | dspcntr = DISPLAY_PLANE_ENABLE; |
| 3246 | |
| 3247 | if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) || |
| 3248 | IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
| 3249 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 3250 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3251 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3252 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3253 | dspcntr |= DISPPLANE_8BPP; |
| 3254 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3255 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3256 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3257 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3258 | case DRM_FORMAT_RGB565: |
| 3259 | dspcntr |= DISPPLANE_BGRX565; |
| 3260 | break; |
| 3261 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3262 | dspcntr |= DISPPLANE_BGRX888; |
| 3263 | break; |
| 3264 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3265 | dspcntr |= DISPPLANE_RGBX888; |
| 3266 | break; |
| 3267 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3268 | dspcntr |= DISPPLANE_BGRX101010; |
| 3269 | break; |
| 3270 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3271 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3272 | break; |
| 3273 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3274 | MISSING_CASE(fb->format->format); |
| 3275 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3276 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3277 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3278 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3279 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3280 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3281 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3282 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3283 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3284 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3285 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3286 | dspcntr |= DISPPLANE_MIRROR; |
| 3287 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3288 | return dspcntr; |
| 3289 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3290 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3291 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3292 | { |
| 3293 | struct drm_i915_private *dev_priv = |
| 3294 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3295 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3296 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3297 | int src_x = plane_state->base.src.x1 >> 16; |
| 3298 | int src_y = plane_state->base.src.y1 >> 16; |
| 3299 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3300 | int ret; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3301 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3302 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3303 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3304 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3305 | ret = intel_plane_check_stride(plane_state); |
| 3306 | if (ret) |
| 3307 | return ret; |
| 3308 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3309 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3310 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3311 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3312 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 3313 | plane_state, 0); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3314 | else |
| 3315 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3316 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3317 | /* HSW/BDW do this automagically in hardware */ |
| 3318 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3319 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3320 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3321 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3322 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3323 | src_x += src_w - 1; |
| 3324 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3325 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3326 | src_x += src_w - 1; |
| 3327 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3328 | } |
| 3329 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3330 | plane_state->color_plane[0].offset = offset; |
| 3331 | plane_state->color_plane[0].x = src_x; |
| 3332 | plane_state->color_plane[0].y = src_y; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3333 | |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3337 | static int |
| 3338 | i9xx_plane_check(struct intel_crtc_state *crtc_state, |
| 3339 | struct intel_plane_state *plane_state) |
| 3340 | { |
| 3341 | int ret; |
| 3342 | |
Ville Syrjälä | 25721f8 | 2018-09-07 18:24:12 +0300 | [diff] [blame] | 3343 | ret = chv_plane_check_rotation(plane_state); |
| 3344 | if (ret) |
| 3345 | return ret; |
| 3346 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3347 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 3348 | &crtc_state->base, |
| 3349 | DRM_PLANE_HELPER_NO_SCALING, |
| 3350 | DRM_PLANE_HELPER_NO_SCALING, |
| 3351 | false, true); |
| 3352 | if (ret) |
| 3353 | return ret; |
| 3354 | |
| 3355 | if (!plane_state->base.visible) |
| 3356 | return 0; |
| 3357 | |
| 3358 | ret = intel_plane_check_src_coordinates(plane_state); |
| 3359 | if (ret) |
| 3360 | return ret; |
| 3361 | |
| 3362 | ret = i9xx_check_plane_surface(plane_state); |
| 3363 | if (ret) |
| 3364 | return ret; |
| 3365 | |
| 3366 | plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state); |
| 3367 | |
| 3368 | return 0; |
| 3369 | } |
| 3370 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3371 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3372 | const struct intel_crtc_state *crtc_state, |
| 3373 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3374 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3375 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3376 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3377 | u32 linear_offset; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3378 | int x = plane_state->color_plane[0].x; |
| 3379 | int y = plane_state->color_plane[0].y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3380 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3381 | u32 dspaddr_offset; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3382 | u32 dspcntr; |
| 3383 | |
| 3384 | dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state); |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3385 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3386 | 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] | 3387 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3388 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3389 | dspaddr_offset = plane_state->color_plane[0].offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3390 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3391 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3392 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3393 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3394 | |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3395 | I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride); |
| 3396 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3397 | if (INTEL_GEN(dev_priv) < 4) { |
| 3398 | /* pipesrc and dspsize control the size that is scaled from, |
| 3399 | * which should always be the user's requested size. |
| 3400 | */ |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3401 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3402 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3403 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3404 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3405 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3406 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3407 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3408 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3409 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3410 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3411 | } |
| 3412 | |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3413 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3414 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3415 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3416 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
| 3417 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3418 | } |
| 3419 | |
| 3420 | /* |
| 3421 | * The control register self-arms if the plane was previously |
| 3422 | * disabled. Try to make the plane enable atomic by writing |
| 3423 | * the control register just before the surface register. |
| 3424 | */ |
| 3425 | I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr); |
| 3426 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3427 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3428 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3429 | dspaddr_offset); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3430 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3431 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3432 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3433 | dspaddr_offset); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3434 | |
| 3435 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3438 | static void i9xx_disable_plane(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 3439 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3440 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3441 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3442 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3443 | unsigned long irqflags; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3444 | u32 dspcntr; |
| 3445 | |
| 3446 | /* |
| 3447 | * DSPCNTR pipe gamma enable on g4x+ and pipe csc |
| 3448 | * enable on ilk+ affect the pipe bottom color as |
| 3449 | * well, so we must configure them even if the plane |
| 3450 | * is disabled. |
| 3451 | * |
| 3452 | * On pre-g4x there is no way to gamma correct the |
| 3453 | * pipe bottom color but we'll keep on doing this |
Ville Syrjälä | 9d5441d | 2019-02-07 22:21:40 +0200 | [diff] [blame] | 3454 | * anyway so that the crtc state readout works correctly. |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3455 | */ |
| 3456 | dspcntr = i9xx_plane_ctl_crtc(crtc_state); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3457 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3458 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3459 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3460 | I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3461 | if (INTEL_GEN(dev_priv) >= 4) |
| 3462 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3463 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3464 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3465 | |
| 3466 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3467 | } |
| 3468 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3469 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane, |
| 3470 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3471 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3472 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3473 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3474 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3475 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3476 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3477 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3478 | |
| 3479 | /* |
| 3480 | * Not 100% correct for planes that can move between pipes, |
| 3481 | * but that's only the case for gen2-4 which don't have any |
| 3482 | * display power wells. |
| 3483 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3484 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3485 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 3486 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3487 | return false; |
| 3488 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3489 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 3490 | |
| 3491 | ret = val & DISPLAY_PLANE_ENABLE; |
| 3492 | |
| 3493 | if (INTEL_GEN(dev_priv) >= 5) |
| 3494 | *pipe = plane->pipe; |
| 3495 | else |
| 3496 | *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 3497 | DISPPLANE_SEL_PIPE_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3498 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3499 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3500 | |
| 3501 | return ret; |
| 3502 | } |
| 3503 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3504 | static u32 |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3505 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3506 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3507 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3508 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3509 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3510 | return intel_tile_width_bytes(fb, color_plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3513 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3514 | { |
| 3515 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3516 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3517 | |
| 3518 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3519 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3520 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3521 | } |
| 3522 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3523 | /* |
| 3524 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3525 | */ |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3526 | static void skl_detach_scalers(const struct intel_crtc_state *crtc_state) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3527 | { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3528 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3529 | const struct intel_crtc_scaler_state *scaler_state = |
| 3530 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3531 | int i; |
| 3532 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3533 | /* loop through and disable scalers that aren't in use */ |
| 3534 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3535 | if (!scaler_state->scalers[i].in_use) |
| 3536 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3537 | } |
| 3538 | } |
| 3539 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3540 | static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb, |
| 3541 | int color_plane, unsigned int rotation) |
| 3542 | { |
| 3543 | /* |
| 3544 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3545 | * linear buffers or in number of tiles for tiled buffers. |
| 3546 | */ |
| 3547 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
| 3548 | return 64; |
| 3549 | else if (drm_rotation_90_or_270(rotation)) |
| 3550 | return intel_tile_height(fb, color_plane); |
| 3551 | else |
| 3552 | return intel_tile_width_bytes(fb, color_plane); |
| 3553 | } |
| 3554 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3555 | u32 skl_plane_stride(const struct intel_plane_state *plane_state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3556 | int color_plane) |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3557 | { |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3558 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3559 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3560 | u32 stride = plane_state->color_plane[color_plane].stride; |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3561 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3562 | if (color_plane >= fb->format->num_planes) |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3563 | return 0; |
| 3564 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3565 | return stride / skl_plane_stride_mult(fb, color_plane, rotation); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3566 | } |
| 3567 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 3568 | static u32 skl_plane_ctl_format(u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3569 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3570 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3571 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3572 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3573 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3574 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3575 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3576 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3577 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3578 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3579 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3580 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3581 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3582 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3583 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3584 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3585 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3586 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3587 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3588 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3589 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3590 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3591 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3592 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3593 | case DRM_FORMAT_NV12: |
| 3594 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3595 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3596 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3597 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3598 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3599 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3602 | 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] | 3603 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3604 | if (!plane_state->base.fb->format->has_alpha) |
| 3605 | return PLANE_CTL_ALPHA_DISABLE; |
| 3606 | |
| 3607 | switch (plane_state->base.pixel_blend_mode) { |
| 3608 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3609 | return PLANE_CTL_ALPHA_DISABLE; |
| 3610 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3611 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3612 | case DRM_MODE_BLEND_COVERAGE: |
| 3613 | return PLANE_CTL_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3614 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3615 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3616 | return PLANE_CTL_ALPHA_DISABLE; |
| 3617 | } |
| 3618 | } |
| 3619 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3620 | 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] | 3621 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3622 | if (!plane_state->base.fb->format->has_alpha) |
| 3623 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3624 | |
| 3625 | switch (plane_state->base.pixel_blend_mode) { |
| 3626 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3627 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3628 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3629 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3630 | case DRM_MODE_BLEND_COVERAGE: |
| 3631 | return PLANE_COLOR_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3632 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3633 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3634 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3635 | } |
| 3636 | } |
| 3637 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 3638 | static u32 skl_plane_ctl_tiling(u64 fb_modifier) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3639 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3640 | switch (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3641 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3642 | break; |
| 3643 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3644 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3645 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3646 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3647 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3648 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3649 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3650 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3651 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3652 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3653 | default: |
| 3654 | MISSING_CASE(fb_modifier); |
| 3655 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3656 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3657 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3660 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3661 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3662 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3663 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3664 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3665 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3666 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3667 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3668 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3669 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3670 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3671 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3672 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3673 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3674 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3675 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3676 | MISSING_CASE(rotate); |
| 3677 | } |
| 3678 | |
| 3679 | return 0; |
| 3680 | } |
| 3681 | |
| 3682 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3683 | { |
| 3684 | switch (reflect) { |
| 3685 | case 0: |
| 3686 | break; |
| 3687 | case DRM_MODE_REFLECT_X: |
| 3688 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3689 | case DRM_MODE_REFLECT_Y: |
| 3690 | default: |
| 3691 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3694 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3697 | u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 3698 | { |
| 3699 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3700 | u32 plane_ctl = 0; |
| 3701 | |
| 3702 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) |
| 3703 | return plane_ctl; |
| 3704 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 3705 | if (crtc_state->gamma_enable) |
| 3706 | plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE; |
| 3707 | |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 3708 | if (crtc_state->csc_enable) |
| 3709 | plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3710 | |
| 3711 | return plane_ctl; |
| 3712 | } |
| 3713 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3714 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3715 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3716 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3717 | struct drm_i915_private *dev_priv = |
| 3718 | to_i915(plane_state->base.plane->dev); |
| 3719 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3720 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3721 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3722 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3723 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3724 | plane_ctl = PLANE_CTL_ENABLE; |
| 3725 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3726 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3727 | plane_ctl |= skl_plane_ctl_alpha(plane_state); |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3728 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3729 | |
| 3730 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3731 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3732 | |
| 3733 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3734 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3735 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3736 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3737 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3738 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3739 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3740 | |
| 3741 | if (INTEL_GEN(dev_priv) >= 10) |
| 3742 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3743 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3744 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3745 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3746 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3747 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3748 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3749 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3750 | return plane_ctl; |
| 3751 | } |
| 3752 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3753 | u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 3754 | { |
| 3755 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 3756 | u32 plane_color_ctl = 0; |
| 3757 | |
| 3758 | if (INTEL_GEN(dev_priv) >= 11) |
| 3759 | return plane_color_ctl; |
| 3760 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 3761 | if (crtc_state->gamma_enable) |
| 3762 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3763 | |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 3764 | if (crtc_state->csc_enable) |
| 3765 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 3766 | |
| 3767 | return plane_color_ctl; |
| 3768 | } |
| 3769 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3770 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3771 | const struct intel_plane_state *plane_state) |
| 3772 | { |
| 3773 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3774 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3775 | u32 plane_color_ctl = 0; |
| 3776 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3777 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3778 | plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3779 | |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3780 | if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) { |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3781 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3782 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3783 | else |
| 3784 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3785 | |
| 3786 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3787 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3788 | } else if (fb->format->is_yuv) { |
| 3789 | plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3790 | } |
Ville Syrjälä | 012d79e | 2018-05-21 21:56:12 +0300 | [diff] [blame] | 3791 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3792 | return plane_color_ctl; |
| 3793 | } |
| 3794 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3795 | static int |
| 3796 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3797 | struct drm_atomic_state *state, |
| 3798 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3799 | { |
| 3800 | struct drm_crtc_state *crtc_state; |
| 3801 | struct drm_crtc *crtc; |
| 3802 | int i, ret; |
| 3803 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3804 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3805 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3806 | |
| 3807 | if (!state) |
| 3808 | return 0; |
| 3809 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3810 | /* |
| 3811 | * We've duplicated the state, pointers to the old state are invalid. |
| 3812 | * |
| 3813 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3814 | */ |
| 3815 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3816 | /* |
| 3817 | * Force recalculation even if we restore |
| 3818 | * current state. With fast modeset this may not result |
| 3819 | * in a modeset when the state is compatible. |
| 3820 | */ |
| 3821 | crtc_state->mode_changed = true; |
| 3822 | } |
| 3823 | |
| 3824 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 3825 | if (!HAS_GMCH(to_i915(dev))) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3826 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3827 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3828 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3829 | |
| 3830 | WARN_ON(ret == -EDEADLK); |
| 3831 | return ret; |
| 3832 | } |
| 3833 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3834 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3835 | { |
Chris Wilson | 55277e1 | 2019-01-03 11:21:04 +0000 | [diff] [blame] | 3836 | return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display && |
| 3837 | intel_has_gpu_reset(dev_priv)); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3838 | } |
| 3839 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3840 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3841 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3842 | struct drm_device *dev = &dev_priv->drm; |
| 3843 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3844 | struct drm_atomic_state *state; |
| 3845 | int ret; |
| 3846 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3847 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3848 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3849 | !gpu_reset_clobbers_display(dev_priv)) |
| 3850 | return; |
| 3851 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3852 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3853 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3854 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3855 | |
| 3856 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3857 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3858 | i915_gem_set_wedged(dev_priv); |
| 3859 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3860 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3861 | /* |
| 3862 | * Need mode_config.mutex so that we don't |
| 3863 | * trample ongoing ->detect() and whatnot. |
| 3864 | */ |
| 3865 | mutex_lock(&dev->mode_config.mutex); |
| 3866 | drm_modeset_acquire_init(ctx, 0); |
| 3867 | while (1) { |
| 3868 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3869 | if (ret != -EDEADLK) |
| 3870 | break; |
| 3871 | |
| 3872 | drm_modeset_backoff(ctx); |
| 3873 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3874 | /* |
| 3875 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3876 | * g33 docs say we should at least disable all the planes. |
| 3877 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3878 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3879 | if (IS_ERR(state)) { |
| 3880 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3881 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3882 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3886 | if (ret) { |
| 3887 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3888 | drm_atomic_state_put(state); |
| 3889 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | dev_priv->modeset_restore_state = state; |
| 3893 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3894 | } |
| 3895 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3896 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3897 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3898 | struct drm_device *dev = &dev_priv->drm; |
| 3899 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3900 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3901 | int ret; |
| 3902 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3903 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3904 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3905 | return; |
| 3906 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3907 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3908 | if (!state) |
| 3909 | goto unlock; |
| 3910 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3911 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3912 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3913 | /* for testing only restore the display */ |
| 3914 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3915 | if (ret) |
| 3916 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3917 | } else { |
| 3918 | /* |
| 3919 | * The display has been reset as well, |
| 3920 | * so need a full re-initialization. |
| 3921 | */ |
| 3922 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3923 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3924 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3925 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3926 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3927 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3928 | |
| 3929 | spin_lock_irq(&dev_priv->irq_lock); |
| 3930 | if (dev_priv->display.hpd_irq_setup) |
| 3931 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3932 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3933 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3934 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3935 | if (ret) |
| 3936 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3937 | |
| 3938 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3939 | } |
| 3940 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3941 | drm_atomic_state_put(state); |
| 3942 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3943 | drm_modeset_drop_locks(ctx); |
| 3944 | drm_modeset_acquire_fini(ctx); |
| 3945 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3946 | |
| 3947 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3948 | } |
| 3949 | |
Ville Syrjälä | d162211 | 2019-02-04 22:21:39 +0200 | [diff] [blame] | 3950 | static void icl_set_pipe_chicken(struct intel_crtc *crtc) |
| 3951 | { |
| 3952 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3953 | enum pipe pipe = crtc->pipe; |
| 3954 | u32 tmp; |
| 3955 | |
| 3956 | tmp = I915_READ(PIPE_CHICKEN(pipe)); |
| 3957 | |
| 3958 | /* |
| 3959 | * Display WA #1153: icl |
| 3960 | * enable hardware to bypass the alpha math |
| 3961 | * and rounding for per-pixel values 00 and 0xff |
| 3962 | */ |
| 3963 | tmp |= PER_PIXEL_ALPHA_BYPASS_EN; |
| 3964 | |
| 3965 | I915_WRITE(PIPE_CHICKEN(pipe), tmp); |
| 3966 | } |
| 3967 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3968 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3969 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3970 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3971 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3972 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3973 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3974 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3975 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3976 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3977 | /* |
| 3978 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3979 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3980 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3981 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3982 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3983 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3984 | */ |
| 3985 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3986 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3987 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3988 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3989 | |
| 3990 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3991 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3992 | skl_detach_scalers(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3993 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3994 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3995 | skylake_pfit_enable(new_crtc_state); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3996 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3997 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3998 | ironlake_pfit_enable(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3999 | else if (old_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 4000 | ironlake_pfit_disable(old_crtc_state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 4001 | } |
Matt Roper | c055030 | 2019-01-30 10:51:20 -0800 | [diff] [blame] | 4002 | |
Ville Syrjälä | 108d14b | 2019-02-04 22:22:14 +0200 | [diff] [blame] | 4003 | if (INTEL_GEN(dev_priv) >= 11) |
| 4004 | icl_set_pipe_chicken(crtc); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 4005 | } |
| 4006 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4007 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4008 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4009 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4010 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4011 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4012 | i915_reg_t reg; |
| 4013 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4014 | |
| 4015 | /* enable normal train */ |
| 4016 | reg = FDI_TX_CTL(pipe); |
| 4017 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4018 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4019 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4020 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 4021 | } else { |
| 4022 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4023 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4024 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4025 | I915_WRITE(reg, temp); |
| 4026 | |
| 4027 | reg = FDI_RX_CTL(pipe); |
| 4028 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4029 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4030 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4031 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 4032 | } else { |
| 4033 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4034 | temp |= FDI_LINK_TRAIN_NONE; |
| 4035 | } |
| 4036 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 4037 | |
| 4038 | /* wait one idle pattern time */ |
| 4039 | POSTING_READ(reg); |
| 4040 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4041 | |
| 4042 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4043 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4044 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 4045 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4046 | } |
| 4047 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4048 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4049 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 4050 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4051 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4052 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4053 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4054 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4055 | i915_reg_t reg; |
| 4056 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4057 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 4058 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4059 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4060 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4061 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4062 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4063 | reg = FDI_RX_IMR(pipe); |
| 4064 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4065 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4066 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4067 | I915_WRITE(reg, temp); |
| 4068 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4069 | udelay(150); |
| 4070 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4071 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4072 | reg = FDI_TX_CTL(pipe); |
| 4073 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4074 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4075 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4076 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4077 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4078 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4079 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4080 | reg = FDI_RX_CTL(pipe); |
| 4081 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4082 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4083 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4084 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4085 | |
| 4086 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4087 | udelay(150); |
| 4088 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 4089 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 4090 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 4091 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 4092 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 4093 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4094 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4095 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4096 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4097 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4098 | |
| 4099 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 4100 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4101 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4102 | break; |
| 4103 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4104 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4105 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4106 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4107 | |
| 4108 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4109 | reg = FDI_TX_CTL(pipe); |
| 4110 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4111 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4112 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4113 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4114 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4115 | reg = FDI_RX_CTL(pipe); |
| 4116 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4117 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4118 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4119 | I915_WRITE(reg, temp); |
| 4120 | |
| 4121 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4122 | udelay(150); |
| 4123 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4124 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4125 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4126 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4127 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4128 | |
| 4129 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4130 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4131 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4132 | break; |
| 4133 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4134 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4135 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4136 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4137 | |
| 4138 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4139 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4140 | } |
| 4141 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4142 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4143 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 4144 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 4145 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 4146 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 4147 | }; |
| 4148 | |
| 4149 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4150 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
| 4151 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4152 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4153 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4154 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4155 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4156 | i915_reg_t reg; |
| 4157 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4158 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4159 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4160 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4161 | reg = FDI_RX_IMR(pipe); |
| 4162 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4163 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4164 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4165 | I915_WRITE(reg, temp); |
| 4166 | |
| 4167 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4168 | udelay(150); |
| 4169 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4170 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4171 | reg = FDI_TX_CTL(pipe); |
| 4172 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4173 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4174 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4175 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4176 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4177 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4178 | /* SNB-B */ |
| 4179 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4180 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4181 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4182 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4183 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4184 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4185 | reg = FDI_RX_CTL(pipe); |
| 4186 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4187 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4188 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4189 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4190 | } else { |
| 4191 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4192 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4193 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4194 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4195 | |
| 4196 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4197 | udelay(150); |
| 4198 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4199 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4200 | reg = FDI_TX_CTL(pipe); |
| 4201 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4202 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4203 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4204 | I915_WRITE(reg, temp); |
| 4205 | |
| 4206 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4207 | udelay(500); |
| 4208 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4209 | for (retry = 0; retry < 5; retry++) { |
| 4210 | reg = FDI_RX_IIR(pipe); |
| 4211 | temp = I915_READ(reg); |
| 4212 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4213 | if (temp & FDI_RX_BIT_LOCK) { |
| 4214 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4215 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4216 | break; |
| 4217 | } |
| 4218 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4219 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4220 | if (retry < 5) |
| 4221 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4222 | } |
| 4223 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4224 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4225 | |
| 4226 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4227 | reg = FDI_TX_CTL(pipe); |
| 4228 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4229 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4230 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4231 | if (IS_GEN(dev_priv, 6)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4232 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4233 | /* SNB-B */ |
| 4234 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4235 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4236 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4237 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4238 | reg = FDI_RX_CTL(pipe); |
| 4239 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4240 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4241 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4242 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4243 | } else { |
| 4244 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4245 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4246 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4247 | I915_WRITE(reg, temp); |
| 4248 | |
| 4249 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4250 | udelay(150); |
| 4251 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4252 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4253 | reg = FDI_TX_CTL(pipe); |
| 4254 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4255 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4256 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4257 | I915_WRITE(reg, temp); |
| 4258 | |
| 4259 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4260 | udelay(500); |
| 4261 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4262 | for (retry = 0; retry < 5; retry++) { |
| 4263 | reg = FDI_RX_IIR(pipe); |
| 4264 | temp = I915_READ(reg); |
| 4265 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4266 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4267 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4268 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4269 | break; |
| 4270 | } |
| 4271 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4272 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4273 | if (retry < 5) |
| 4274 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4275 | } |
| 4276 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4277 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4278 | |
| 4279 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4280 | } |
| 4281 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4282 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4283 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4284 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4285 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4286 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4287 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4288 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4289 | i915_reg_t reg; |
| 4290 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4291 | |
| 4292 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4293 | for train result */ |
| 4294 | reg = FDI_RX_IMR(pipe); |
| 4295 | temp = I915_READ(reg); |
| 4296 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4297 | temp &= ~FDI_RX_BIT_LOCK; |
| 4298 | I915_WRITE(reg, temp); |
| 4299 | |
| 4300 | POSTING_READ(reg); |
| 4301 | udelay(150); |
| 4302 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4303 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4304 | I915_READ(FDI_RX_IIR(pipe))); |
| 4305 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4306 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4307 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4308 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4309 | reg = FDI_TX_CTL(pipe); |
| 4310 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4311 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4312 | temp &= ~FDI_TX_ENABLE; |
| 4313 | I915_WRITE(reg, temp); |
| 4314 | |
| 4315 | reg = FDI_RX_CTL(pipe); |
| 4316 | temp = I915_READ(reg); |
| 4317 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4318 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4319 | temp &= ~FDI_RX_ENABLE; |
| 4320 | I915_WRITE(reg, temp); |
| 4321 | |
| 4322 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4323 | reg = FDI_TX_CTL(pipe); |
| 4324 | temp = I915_READ(reg); |
| 4325 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4326 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4327 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4328 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4329 | temp |= snb_b_fdi_train_param[j/2]; |
| 4330 | temp |= FDI_COMPOSITE_SYNC; |
| 4331 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4332 | |
| 4333 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4334 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4335 | |
| 4336 | reg = FDI_RX_CTL(pipe); |
| 4337 | temp = I915_READ(reg); |
| 4338 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4339 | temp |= FDI_COMPOSITE_SYNC; |
| 4340 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4341 | |
| 4342 | POSTING_READ(reg); |
| 4343 | udelay(1); /* should be 0.5us */ |
| 4344 | |
| 4345 | for (i = 0; i < 4; i++) { |
| 4346 | reg = FDI_RX_IIR(pipe); |
| 4347 | temp = I915_READ(reg); |
| 4348 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4349 | |
| 4350 | if (temp & FDI_RX_BIT_LOCK || |
| 4351 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4352 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4353 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4354 | i); |
| 4355 | break; |
| 4356 | } |
| 4357 | udelay(1); /* should be 0.5us */ |
| 4358 | } |
| 4359 | if (i == 4) { |
| 4360 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4361 | continue; |
| 4362 | } |
| 4363 | |
| 4364 | /* Train 2 */ |
| 4365 | reg = FDI_TX_CTL(pipe); |
| 4366 | temp = I915_READ(reg); |
| 4367 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4368 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4369 | I915_WRITE(reg, temp); |
| 4370 | |
| 4371 | reg = FDI_RX_CTL(pipe); |
| 4372 | temp = I915_READ(reg); |
| 4373 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4374 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4375 | I915_WRITE(reg, temp); |
| 4376 | |
| 4377 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4378 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4379 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4380 | for (i = 0; i < 4; i++) { |
| 4381 | reg = FDI_RX_IIR(pipe); |
| 4382 | temp = I915_READ(reg); |
| 4383 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4384 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4385 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4386 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4387 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4388 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4389 | i); |
| 4390 | goto train_done; |
| 4391 | } |
| 4392 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4393 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4394 | if (i == 4) |
| 4395 | 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] | 4396 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4397 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4398 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4399 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4400 | } |
| 4401 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4402 | 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] | 4403 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4404 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4405 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4406 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4407 | i915_reg_t reg; |
| 4408 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4409 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4410 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4411 | reg = FDI_RX_CTL(pipe); |
| 4412 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4413 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4414 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4415 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4416 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4417 | |
| 4418 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4419 | udelay(200); |
| 4420 | |
| 4421 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4422 | temp = I915_READ(reg); |
| 4423 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4424 | |
| 4425 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4426 | udelay(200); |
| 4427 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4428 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4429 | reg = FDI_TX_CTL(pipe); |
| 4430 | temp = I915_READ(reg); |
| 4431 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4432 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4433 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4434 | POSTING_READ(reg); |
| 4435 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4436 | } |
| 4437 | } |
| 4438 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4439 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4440 | { |
| 4441 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4442 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4443 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4444 | i915_reg_t reg; |
| 4445 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4446 | |
| 4447 | /* Switch from PCDclk to Rawclk */ |
| 4448 | reg = FDI_RX_CTL(pipe); |
| 4449 | temp = I915_READ(reg); |
| 4450 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4451 | |
| 4452 | /* Disable CPU FDI TX PLL */ |
| 4453 | reg = FDI_TX_CTL(pipe); |
| 4454 | temp = I915_READ(reg); |
| 4455 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4456 | |
| 4457 | POSTING_READ(reg); |
| 4458 | udelay(100); |
| 4459 | |
| 4460 | reg = FDI_RX_CTL(pipe); |
| 4461 | temp = I915_READ(reg); |
| 4462 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4463 | |
| 4464 | /* Wait for the clocks to turn off. */ |
| 4465 | POSTING_READ(reg); |
| 4466 | udelay(100); |
| 4467 | } |
| 4468 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4469 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4470 | { |
| 4471 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4472 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4473 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4474 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4475 | i915_reg_t reg; |
| 4476 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4477 | |
| 4478 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4479 | reg = FDI_TX_CTL(pipe); |
| 4480 | temp = I915_READ(reg); |
| 4481 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4482 | POSTING_READ(reg); |
| 4483 | |
| 4484 | reg = FDI_RX_CTL(pipe); |
| 4485 | temp = I915_READ(reg); |
| 4486 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4487 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4488 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4489 | |
| 4490 | POSTING_READ(reg); |
| 4491 | udelay(100); |
| 4492 | |
| 4493 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4494 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4495 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4496 | |
| 4497 | /* still set train pattern 1 */ |
| 4498 | reg = FDI_TX_CTL(pipe); |
| 4499 | temp = I915_READ(reg); |
| 4500 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4501 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4502 | I915_WRITE(reg, temp); |
| 4503 | |
| 4504 | reg = FDI_RX_CTL(pipe); |
| 4505 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4506 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4507 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4508 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4509 | } else { |
| 4510 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4511 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4512 | } |
| 4513 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4514 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4515 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4516 | I915_WRITE(reg, temp); |
| 4517 | |
| 4518 | POSTING_READ(reg); |
| 4519 | udelay(100); |
| 4520 | } |
| 4521 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4522 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4523 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4524 | struct drm_crtc *crtc; |
| 4525 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4526 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4527 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4528 | struct drm_crtc_commit *commit; |
| 4529 | spin_lock(&crtc->commit_lock); |
| 4530 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4531 | struct drm_crtc_commit, commit_entry); |
| 4532 | cleanup_done = commit ? |
| 4533 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4534 | spin_unlock(&crtc->commit_lock); |
| 4535 | |
| 4536 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4537 | continue; |
| 4538 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4539 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4540 | |
| 4541 | return true; |
| 4542 | } |
| 4543 | |
| 4544 | return false; |
| 4545 | } |
| 4546 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4547 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4548 | { |
| 4549 | u32 temp; |
| 4550 | |
| 4551 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4552 | |
| 4553 | mutex_lock(&dev_priv->sb_lock); |
| 4554 | |
| 4555 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4556 | temp |= SBI_SSCCTL_DISABLE; |
| 4557 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4558 | |
| 4559 | mutex_unlock(&dev_priv->sb_lock); |
| 4560 | } |
| 4561 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4562 | /* Program iCLKIP clock to the desired frequency */ |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4563 | static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4564 | { |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4565 | 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] | 4566 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4567 | int clock = crtc_state->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4568 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4569 | u32 temp; |
| 4570 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4571 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4572 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4573 | /* The iCLK virtual clock root frequency is in MHz, |
| 4574 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4575 | * divisors, it is necessary to divide one by another, so we |
| 4576 | * convert the virtual clock precision to KHz here for higher |
| 4577 | * precision. |
| 4578 | */ |
| 4579 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4580 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4581 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4582 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4583 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4584 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4585 | clock << auxdiv); |
| 4586 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4587 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4588 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4589 | /* |
| 4590 | * Near 20MHz is a corner case which is |
| 4591 | * out of range for the 7-bit divisor |
| 4592 | */ |
| 4593 | if (divsel <= 0x7f) |
| 4594 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | /* This should not happen with any sane values */ |
| 4598 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4599 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4600 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4601 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4602 | |
| 4603 | 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] | 4604 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4605 | auxdiv, |
| 4606 | divsel, |
| 4607 | phasedir, |
| 4608 | phaseinc); |
| 4609 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4610 | mutex_lock(&dev_priv->sb_lock); |
| 4611 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4612 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4613 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4614 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4615 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4616 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4617 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4618 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4619 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4620 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4621 | |
| 4622 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4623 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4624 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4625 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4626 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4627 | |
| 4628 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4629 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4630 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4631 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4632 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4633 | mutex_unlock(&dev_priv->sb_lock); |
| 4634 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4635 | /* Wait for initialization time */ |
| 4636 | udelay(24); |
| 4637 | |
| 4638 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4639 | } |
| 4640 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4641 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4642 | { |
| 4643 | u32 divsel, phaseinc, auxdiv; |
| 4644 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4645 | u32 iclk_pi_range = 64; |
| 4646 | u32 desired_divisor; |
| 4647 | u32 temp; |
| 4648 | |
| 4649 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4650 | return 0; |
| 4651 | |
| 4652 | mutex_lock(&dev_priv->sb_lock); |
| 4653 | |
| 4654 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4655 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4656 | mutex_unlock(&dev_priv->sb_lock); |
| 4657 | return 0; |
| 4658 | } |
| 4659 | |
| 4660 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4661 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4662 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4663 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4664 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4665 | |
| 4666 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4667 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4668 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4669 | |
| 4670 | mutex_unlock(&dev_priv->sb_lock); |
| 4671 | |
| 4672 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4673 | |
| 4674 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4675 | desired_divisor << auxdiv); |
| 4676 | } |
| 4677 | |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4678 | 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] | 4679 | enum pipe pch_transcoder) |
| 4680 | { |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4681 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4682 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4683 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4684 | |
| 4685 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4686 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4687 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4688 | I915_READ(HBLANK(cpu_transcoder))); |
| 4689 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4690 | I915_READ(HSYNC(cpu_transcoder))); |
| 4691 | |
| 4692 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4693 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4694 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4695 | I915_READ(VBLANK(cpu_transcoder))); |
| 4696 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4697 | I915_READ(VSYNC(cpu_transcoder))); |
| 4698 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4699 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4700 | } |
| 4701 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4702 | static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4703 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 4704 | u32 temp; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4705 | |
| 4706 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4707 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4708 | return; |
| 4709 | |
| 4710 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4711 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4712 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4713 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4714 | if (enable) |
| 4715 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4716 | |
| 4717 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4718 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4719 | POSTING_READ(SOUTH_CHICKEN1); |
| 4720 | } |
| 4721 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4722 | static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4723 | { |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4724 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4725 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4726 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4727 | switch (crtc->pipe) { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4728 | case PIPE_A: |
| 4729 | break; |
| 4730 | case PIPE_B: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4731 | if (crtc_state->fdi_lanes > 2) |
| 4732 | cpt_set_fdi_bc_bifurcation(dev_priv, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4733 | else |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4734 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4735 | |
| 4736 | break; |
| 4737 | case PIPE_C: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4738 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4739 | |
| 4740 | break; |
| 4741 | default: |
| 4742 | BUG(); |
| 4743 | } |
| 4744 | } |
| 4745 | |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4746 | /* |
| 4747 | * Finds the encoder associated with the given CRTC. This can only be |
| 4748 | * used when we know that the CRTC isn't feeding multiple encoders! |
| 4749 | */ |
| 4750 | static struct intel_encoder * |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4751 | intel_get_crtc_new_encoder(const struct intel_atomic_state *state, |
| 4752 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4753 | { |
| 4754 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4755 | const struct drm_connector_state *connector_state; |
| 4756 | const struct drm_connector *connector; |
| 4757 | struct intel_encoder *encoder = NULL; |
| 4758 | int num_encoders = 0; |
| 4759 | int i; |
| 4760 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4761 | 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] | 4762 | if (connector_state->crtc != &crtc->base) |
| 4763 | continue; |
| 4764 | |
| 4765 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 4766 | num_encoders++; |
| 4767 | } |
| 4768 | |
| 4769 | WARN(num_encoders != 1, "%d encoders for pipe %c\n", |
| 4770 | num_encoders, pipe_name(crtc->pipe)); |
| 4771 | |
| 4772 | return encoder; |
| 4773 | } |
| 4774 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4775 | /* |
| 4776 | * Enable PCH resources required for PCH ports: |
| 4777 | * - PCH PLLs |
| 4778 | * - FDI training & RX/TX |
| 4779 | * - update transcoder timings |
| 4780 | * - DP transcoding bits |
| 4781 | * - transcoder |
| 4782 | */ |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4783 | static void ironlake_pch_enable(const struct intel_atomic_state *state, |
| 4784 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4785 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4786 | 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] | 4787 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4788 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4789 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4790 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4791 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4792 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4793 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4794 | if (IS_IVYBRIDGE(dev_priv)) |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4795 | ivybridge_update_fdi_bc_bifurcation(crtc_state); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4796 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4797 | /* Write the TU size bits before fdi link training, so that error |
| 4798 | * detection works. */ |
| 4799 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4800 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4801 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4802 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4803 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4804 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4805 | /* We need to program the right clock selection before writing the pixel |
| 4806 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4807 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4808 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4809 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4810 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4811 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4812 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4813 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4814 | 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] | 4815 | temp |= sel; |
| 4816 | else |
| 4817 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4818 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4819 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4820 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4821 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4822 | * transcoder, and we actually should do this to not upset any PCH |
| 4823 | * transcoder that already use the clock when we share it. |
| 4824 | * |
| 4825 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4826 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4827 | * the right LVDS enable sequence. */ |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 4828 | intel_enable_shared_dpll(crtc_state); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4829 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4830 | /* set transcoder timing, panel must allow it */ |
| 4831 | assert_panel_unlocked(dev_priv, pipe); |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4832 | ironlake_pch_transcoder_set_timings(crtc_state, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4833 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4834 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4835 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4836 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4837 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4838 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4839 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4840 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4841 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4842 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4843 | enum port port; |
| 4844 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4845 | temp = I915_READ(reg); |
| 4846 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4847 | TRANS_DP_SYNC_MASK | |
| 4848 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4849 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4850 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4851 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4852 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4853 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4854 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4855 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4856 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4857 | port = intel_get_crtc_new_encoder(state, crtc_state)->port; |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4858 | WARN_ON(port < PORT_B || port > PORT_D); |
| 4859 | temp |= TRANS_DP_PORT_SEL(port); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4860 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4861 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 4864 | ironlake_enable_pch_transcoder(crtc_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4865 | } |
| 4866 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4867 | static void lpt_pch_enable(const struct intel_atomic_state *state, |
| 4868 | const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4869 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4870 | 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] | 4871 | 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] | 4872 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4873 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4874 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4875 | |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4876 | lpt_program_iclkip(crtc_state); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4877 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4878 | /* Set transcoder timing. */ |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4879 | ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4880 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4881 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4882 | } |
| 4883 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4884 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4885 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4886 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4887 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4888 | u32 temp; |
| 4889 | |
| 4890 | temp = I915_READ(dslreg); |
| 4891 | udelay(500); |
| 4892 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4893 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4894 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4898 | /* |
| 4899 | * The hardware phase 0.0 refers to the center of the pixel. |
| 4900 | * We want to start from the top/left edge which is phase |
| 4901 | * -0.5. That matches how the hardware calculates the scaling |
| 4902 | * factors (from top-left of the first pixel to bottom-right |
| 4903 | * of the last pixel, as opposed to the pixel centers). |
| 4904 | * |
| 4905 | * For 4:2:0 subsampled chroma planes we obviously have to |
| 4906 | * adjust that so that the chroma sample position lands in |
| 4907 | * the right spot. |
| 4908 | * |
| 4909 | * Note that for packed YCbCr 4:2:2 formats there is no way to |
| 4910 | * control chroma siting. The hardware simply replicates the |
| 4911 | * chroma samples for both of the luma samples, and thus we don't |
| 4912 | * actually get the expected MPEG2 chroma siting convention :( |
| 4913 | * The same behaviour is observed on pre-SKL platforms as well. |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4914 | * |
| 4915 | * Theory behind the formula (note that we ignore sub-pixel |
| 4916 | * source coordinates): |
| 4917 | * s = source sample position |
| 4918 | * d = destination sample position |
| 4919 | * |
| 4920 | * Downscaling 4:1: |
| 4921 | * -0.5 |
| 4922 | * | 0.0 |
| 4923 | * | | 1.5 (initial phase) |
| 4924 | * | | | |
| 4925 | * v v v |
| 4926 | * | s | s | s | s | |
| 4927 | * | d | |
| 4928 | * |
| 4929 | * Upscaling 1:4: |
| 4930 | * -0.5 |
| 4931 | * | -0.375 (initial phase) |
| 4932 | * | | 0.0 |
| 4933 | * | | | |
| 4934 | * v v v |
| 4935 | * | s | |
| 4936 | * | d | d | d | d | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4937 | */ |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4938 | u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited) |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4939 | { |
| 4940 | int phase = -0x8000; |
| 4941 | u16 trip = 0; |
| 4942 | |
| 4943 | if (chroma_cosited) |
| 4944 | phase += (sub - 1) * 0x8000 / sub; |
| 4945 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4946 | phase += scale / (2 * sub); |
| 4947 | |
| 4948 | /* |
| 4949 | * Hardware initial phase limited to [-0.5:1.5]. |
| 4950 | * Since the max hardware scale factor is 3.0, we |
| 4951 | * should never actually excdeed 1.0 here. |
| 4952 | */ |
| 4953 | WARN_ON(phase < -0x8000 || phase > 0x18000); |
| 4954 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4955 | if (phase < 0) |
| 4956 | phase = 0x10000 + phase; |
| 4957 | else |
| 4958 | trip = PS_PHASE_TRIP; |
| 4959 | |
| 4960 | return ((phase >> 2) & PS_PHASE_MASK) | trip; |
| 4961 | } |
| 4962 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4963 | static int |
| 4964 | 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] | 4965 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4966 | int src_w, int src_h, int dst_w, int dst_h, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4967 | const struct drm_format_info *format, bool need_scaler) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4968 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4969 | struct intel_crtc_scaler_state *scaler_state = |
| 4970 | &crtc_state->scaler_state; |
| 4971 | struct intel_crtc *intel_crtc = |
| 4972 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4973 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4974 | const struct drm_display_mode *adjusted_mode = |
| 4975 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4976 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4977 | /* |
| 4978 | * Src coordinates are already rotated by 270 degrees for |
| 4979 | * the 90/270 degree plane rotation cases (to match the |
| 4980 | * GTT mapping), hence no need to account for rotation here. |
| 4981 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4982 | if (src_w != dst_w || src_h != dst_h) |
| 4983 | need_scaler = true; |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 4984 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4985 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4986 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 4987 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 4988 | * Once NV12 is enabled, handle it here while allocating scaler |
| 4989 | * for NV12. |
| 4990 | */ |
| 4991 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4992 | need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4993 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 4994 | return -EINVAL; |
| 4995 | } |
| 4996 | |
| 4997 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4998 | * if plane is being disabled or scaler is no more required or force detach |
| 4999 | * - free scaler binded to this plane/crtc |
| 5000 | * - in order to do this, update crtc->scaler_usage |
| 5001 | * |
| 5002 | * Here scaler state in crtc_state is set free so that |
| 5003 | * scaler can be assigned to other user. Actual register |
| 5004 | * update to free the scaler is done in plane/panel-fit programming. |
| 5005 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 5006 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5007 | if (force_detach || !need_scaler) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5008 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5009 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5010 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 5011 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5012 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 5013 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 5014 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5015 | scaler_state->scaler_users); |
| 5016 | *scaler_id = -1; |
| 5017 | } |
| 5018 | return 0; |
| 5019 | } |
| 5020 | |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5021 | if (format && format->format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 5022 | (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] | 5023 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 5024 | return -EINVAL; |
| 5025 | } |
| 5026 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5027 | /* range checks */ |
| 5028 | 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] | 5029 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5030 | (IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 5031 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 5032 | dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) || |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5033 | (!IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 5034 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 5035 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5036 | 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] | 5037 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5038 | 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] | 5039 | return -EINVAL; |
| 5040 | } |
| 5041 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5042 | /* mark this plane as a scaler user in crtc_state */ |
| 5043 | scaler_state->scaler_users |= (1 << scaler_user); |
| 5044 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 5045 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 5046 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 5047 | scaler_state->scaler_users); |
| 5048 | |
| 5049 | return 0; |
| 5050 | } |
| 5051 | |
| 5052 | /** |
| 5053 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 5054 | * |
| 5055 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5056 | * |
| 5057 | * Return |
| 5058 | * 0 - scaler_usage updated successfully |
| 5059 | * error - requested scaling cannot be supported or other error condition |
| 5060 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5061 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5062 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 5063 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5064 | bool need_scaler = false; |
| 5065 | |
| 5066 | if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
| 5067 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5068 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5069 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5070 | &state->scaler_state.scaler_id, |
| 5071 | state->pipe_src_w, state->pipe_src_h, |
| 5072 | adjusted_mode->crtc_hdisplay, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5073 | adjusted_mode->crtc_vdisplay, NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | /** |
| 5077 | * 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] | 5078 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5079 | * @plane_state: atomic plane state to update |
| 5080 | * |
| 5081 | * Return |
| 5082 | * 0 - scaler_usage updated successfully |
| 5083 | * error - requested scaling cannot be supported or other error condition |
| 5084 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 5085 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 5086 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5087 | { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 5088 | struct intel_plane *intel_plane = |
| 5089 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5090 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 5091 | int ret; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5092 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5093 | bool need_scaler = false; |
| 5094 | |
| 5095 | /* Pre-gen11 and SDR planes always need a scaler for planar formats. */ |
| 5096 | if (!icl_is_hdr_plane(intel_plane) && |
| 5097 | fb && fb->format->format == DRM_FORMAT_NV12) |
| 5098 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5099 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5100 | ret = skl_update_scaler(crtc_state, force_detach, |
| 5101 | drm_plane_index(&intel_plane->base), |
| 5102 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5103 | drm_rect_width(&plane_state->base.src) >> 16, |
| 5104 | drm_rect_height(&plane_state->base.src) >> 16, |
| 5105 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5106 | drm_rect_height(&plane_state->base.dst), |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5107 | fb ? fb->format : NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5108 | |
| 5109 | if (ret || plane_state->scaler_id < 0) |
| 5110 | return ret; |
| 5111 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5112 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 5113 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5114 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 5115 | intel_plane->base.base.id, |
| 5116 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5117 | return -EINVAL; |
| 5118 | } |
| 5119 | |
| 5120 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5121 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5122 | case DRM_FORMAT_RGB565: |
| 5123 | case DRM_FORMAT_XBGR8888: |
| 5124 | case DRM_FORMAT_XRGB8888: |
| 5125 | case DRM_FORMAT_ABGR8888: |
| 5126 | case DRM_FORMAT_ARGB8888: |
| 5127 | case DRM_FORMAT_XRGB2101010: |
| 5128 | case DRM_FORMAT_XBGR2101010: |
| 5129 | case DRM_FORMAT_YUYV: |
| 5130 | case DRM_FORMAT_YVYU: |
| 5131 | case DRM_FORMAT_UYVY: |
| 5132 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5133 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5134 | break; |
| 5135 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5136 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 5137 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5138 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5139 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5142 | return 0; |
| 5143 | } |
| 5144 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5145 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 5146 | { |
| 5147 | int i; |
| 5148 | |
| 5149 | for (i = 0; i < crtc->num_scalers; i++) |
| 5150 | skl_detach_scaler(crtc, i); |
| 5151 | } |
| 5152 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5153 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5154 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5155 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5156 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5157 | enum pipe pipe = crtc->pipe; |
| 5158 | const struct intel_crtc_scaler_state *scaler_state = |
| 5159 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5160 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5161 | if (crtc_state->pch_pfit.enabled) { |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5162 | u16 uv_rgb_hphase, uv_rgb_vphase; |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5163 | int pfit_w, pfit_h, hscale, vscale; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5164 | int id; |
| 5165 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5166 | if (WARN_ON(crtc_state->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5167 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5168 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5169 | pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF; |
| 5170 | pfit_h = crtc_state->pch_pfit.size & 0xFFFF; |
| 5171 | |
| 5172 | hscale = (crtc_state->pipe_src_w << 16) / pfit_w; |
| 5173 | vscale = (crtc_state->pipe_src_h << 16) / pfit_h; |
| 5174 | |
| 5175 | uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false); |
| 5176 | uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5177 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5178 | id = scaler_state->scaler_id; |
| 5179 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 5180 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5181 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, id), |
| 5182 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase)); |
| 5183 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, id), |
| 5184 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase)); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5185 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos); |
| 5186 | 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] | 5187 | } |
| 5188 | } |
| 5189 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5190 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5191 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5192 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5193 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5194 | int pipe = crtc->pipe; |
| 5195 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5196 | if (crtc_state->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5197 | /* Force use of hard-coded filter coefficients |
| 5198 | * as some pre-programmed values are broken, |
| 5199 | * e.g. x201. |
| 5200 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5201 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5202 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 5203 | PF_PIPE_SEL_IVB(pipe)); |
| 5204 | else |
| 5205 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5206 | I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos); |
| 5207 | I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 5208 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5209 | } |
| 5210 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5211 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5212 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5213 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 5214 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5215 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5216 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5217 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5218 | return; |
| 5219 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 5220 | /* |
| 5221 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 5222 | * This function is called from post_plane_update, which is run after |
| 5223 | * a vblank wait. |
| 5224 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5225 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 5226 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5227 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5228 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 5229 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 5230 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5231 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5232 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 5233 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5234 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 5235 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5236 | */ |
| 5237 | } else { |
| 5238 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 5239 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 5240 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5241 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5242 | * the HW state readout code will complain that the expected |
| 5243 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5244 | if (intel_wait_for_register(dev_priv, |
| 5245 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5246 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5247 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5248 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5249 | } |
| 5250 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5251 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5252 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5253 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5254 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5255 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5256 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5257 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5258 | return; |
| 5259 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5260 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5261 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5262 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5263 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5264 | /* |
| 5265 | * Wait for PCODE to finish disabling IPS. The BSpec specified |
| 5266 | * 42ms timeout value leads to occasional timeouts so use 100ms |
| 5267 | * instead. |
| 5268 | */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5269 | if (intel_wait_for_register(dev_priv, |
| 5270 | IPS_CTL, IPS_ENABLE, 0, |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5271 | 100)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5272 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5273 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5274 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5275 | POSTING_READ(IPS_CTL); |
| 5276 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5277 | |
| 5278 | /* 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] | 5279 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5280 | } |
| 5281 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5282 | 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] | 5283 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5284 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5285 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5286 | |
| 5287 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5288 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5289 | mutex_unlock(&dev->struct_mutex); |
| 5290 | } |
| 5291 | |
| 5292 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5293 | * has to recompute where to put it anyway. |
| 5294 | */ |
| 5295 | } |
| 5296 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5297 | /** |
| 5298 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5299 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5300 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5301 | * |
| 5302 | * Performs potentially sleeping operations that must be done after the primary |
| 5303 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5304 | * called due to an explicit primary plane update, or due to an implicit |
| 5305 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5306 | * completely hide the primary plane. |
| 5307 | */ |
| 5308 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5309 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5310 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5311 | { |
| 5312 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5313 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5314 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5315 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5316 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5317 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5318 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5319 | * So don't enable underrun reporting before at least some planes |
| 5320 | * are enabled. |
| 5321 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5322 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5323 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5324 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5325 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5326 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5327 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5328 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5329 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5330 | } |
| 5331 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5332 | /* FIXME get rid of this and use pre_plane_update */ |
| 5333 | static void |
| 5334 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5335 | { |
| 5336 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5337 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5338 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5339 | int pipe = intel_crtc->pipe; |
| 5340 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5341 | /* |
| 5342 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5343 | * So disable underrun reporting before all the planes get disabled. |
| 5344 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5345 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5346 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5347 | |
| 5348 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5349 | |
| 5350 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5351 | * Vblank time updates from the shadow to live plane control register |
| 5352 | * are blocked if the memory self-refresh mode is active at that |
| 5353 | * moment. So to make sure the plane gets truly disabled, disable |
| 5354 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5355 | * will be checked/applied by the HW only at the next frame start |
| 5356 | * event which is after the vblank start event, so we need to have a |
| 5357 | * wait-for-vblank between disabling the plane and the pipe. |
| 5358 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 5359 | if (HAS_GMCH(dev_priv) && |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5360 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5361 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5362 | } |
| 5363 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5364 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5365 | const struct intel_crtc_state *new_crtc_state) |
| 5366 | { |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5367 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5368 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5369 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5370 | if (!old_crtc_state->ips_enabled) |
| 5371 | return false; |
| 5372 | |
| 5373 | if (needs_modeset(&new_crtc_state->base)) |
| 5374 | return true; |
| 5375 | |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5376 | /* |
| 5377 | * Workaround : Do not read or write the pipe palette/gamma data while |
| 5378 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 5379 | * |
| 5380 | * Disable IPS before we program the LUT. |
| 5381 | */ |
| 5382 | if (IS_HASWELL(dev_priv) && |
| 5383 | (new_crtc_state->base.color_mgmt_changed || |
| 5384 | new_crtc_state->update_pipe) && |
| 5385 | new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT) |
| 5386 | return true; |
| 5387 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5388 | return !new_crtc_state->ips_enabled; |
| 5389 | } |
| 5390 | |
| 5391 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5392 | const struct intel_crtc_state *new_crtc_state) |
| 5393 | { |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5394 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 5395 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5396 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5397 | if (!new_crtc_state->ips_enabled) |
| 5398 | return false; |
| 5399 | |
| 5400 | if (needs_modeset(&new_crtc_state->base)) |
| 5401 | return true; |
| 5402 | |
| 5403 | /* |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 5404 | * Workaround : Do not read or write the pipe palette/gamma data while |
| 5405 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 5406 | * |
| 5407 | * Re-enable IPS after the LUT has been programmed. |
| 5408 | */ |
| 5409 | if (IS_HASWELL(dev_priv) && |
| 5410 | (new_crtc_state->base.color_mgmt_changed || |
| 5411 | new_crtc_state->update_pipe) && |
| 5412 | new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT) |
| 5413 | return true; |
| 5414 | |
| 5415 | /* |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5416 | * We can't read out IPS on broadwell, assume the worst and |
| 5417 | * forcibly enable IPS on the first fastset. |
| 5418 | */ |
| 5419 | if (new_crtc_state->update_pipe && |
| 5420 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5421 | return true; |
| 5422 | |
| 5423 | return !old_crtc_state->ips_enabled; |
| 5424 | } |
| 5425 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5426 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5427 | const struct intel_crtc_state *crtc_state) |
| 5428 | { |
| 5429 | if (!crtc_state->nv12_planes) |
| 5430 | return false; |
| 5431 | |
Rodrigo Vivi | 1347d3c | 2018-10-31 09:28:45 -0700 | [diff] [blame] | 5432 | /* WA Display #0827: Gen9:all */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5433 | if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv)) |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5434 | return true; |
| 5435 | |
| 5436 | return false; |
| 5437 | } |
| 5438 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5439 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5440 | { |
| 5441 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5442 | struct drm_device *dev = crtc->base.dev; |
| 5443 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5444 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5445 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5446 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5447 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5448 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5449 | struct drm_plane_state *old_primary_state = |
| 5450 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5451 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5452 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5453 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5454 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5455 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5456 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5457 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5458 | hsw_enable_ips(pipe_config); |
| 5459 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5460 | if (old_primary_state) { |
| 5461 | struct drm_plane_state *new_primary_state = |
| 5462 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5463 | |
| 5464 | intel_fbc_post_update(crtc); |
| 5465 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5466 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5467 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5468 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5469 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5470 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5471 | |
| 5472 | /* Display WA 827 */ |
| 5473 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5474 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5475 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5476 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5477 | } |
| 5478 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5479 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5480 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5481 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5482 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5483 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5484 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5485 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5486 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5487 | struct drm_plane_state *old_primary_state = |
| 5488 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5489 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5490 | struct intel_atomic_state *old_intel_state = |
| 5491 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5492 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5493 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5494 | hsw_disable_ips(old_crtc_state); |
| 5495 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5496 | if (old_primary_state) { |
| 5497 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5498 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5499 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5500 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5501 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5502 | /* |
| 5503 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5504 | * So disable underrun reporting before all the planes get disabled. |
| 5505 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5506 | if (IS_GEN(dev_priv, 2) && old_primary_state->visible && |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5507 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5508 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5509 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5510 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5511 | /* Display WA 827 */ |
| 5512 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5513 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5514 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b60 | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5515 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5516 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5517 | /* |
| 5518 | * Vblank time updates from the shadow to live plane control register |
| 5519 | * are blocked if the memory self-refresh mode is active at that |
| 5520 | * moment. So to make sure the plane gets truly disabled, disable |
| 5521 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5522 | * will be checked/applied by the HW only at the next frame start |
| 5523 | * event which is after the vblank start event, so we need to have a |
| 5524 | * wait-for-vblank between disabling the plane and the pipe. |
| 5525 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 5526 | if (HAS_GMCH(dev_priv) && old_crtc_state->base.active && |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5527 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5528 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5529 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5530 | /* |
| 5531 | * IVB workaround: must disable low power watermarks for at least |
| 5532 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5533 | * when scaling is disabled. |
| 5534 | * |
| 5535 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5536 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 5537 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) && |
| 5538 | old_crtc_state->base.active) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5539 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5540 | |
| 5541 | /* |
| 5542 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5543 | * watermark programming here. |
| 5544 | */ |
| 5545 | if (needs_modeset(&pipe_config->base)) |
| 5546 | return; |
| 5547 | |
| 5548 | /* |
| 5549 | * For platforms that support atomic watermarks, program the |
| 5550 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5551 | * will be the intermediate values that are safe for both pre- and |
| 5552 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5553 | * to the final 'target' values and we'll do this again to get the |
| 5554 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5555 | * will be the final target values which will get automatically latched |
| 5556 | * at vblank time; no further programming will be necessary. |
| 5557 | * |
| 5558 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5559 | * we'll continue to update watermarks the old way, if flags tell |
| 5560 | * us to. |
| 5561 | */ |
| 5562 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5563 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5564 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5565 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5566 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5567 | } |
| 5568 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5569 | static void intel_crtc_disable_planes(struct intel_atomic_state *state, |
| 5570 | struct intel_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5571 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5572 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5573 | const struct intel_crtc_state *new_crtc_state = |
| 5574 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5575 | unsigned int update_mask = new_crtc_state->update_planes; |
| 5576 | const struct intel_plane_state *old_plane_state; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5577 | struct intel_plane *plane; |
| 5578 | unsigned fb_bits = 0; |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5579 | int i; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5580 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5581 | intel_crtc_dpms_overlay_disable(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5582 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5583 | for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { |
| 5584 | if (crtc->pipe != plane->pipe || |
| 5585 | !(update_mask & BIT(plane->id))) |
| 5586 | continue; |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5587 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5588 | plane->disable_plane(plane, new_crtc_state); |
| 5589 | |
| 5590 | if (old_plane_state->base.visible) |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5591 | fb_bits |= plane->frontbuffer_bit; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5592 | } |
| 5593 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5594 | intel_frontbuffer_flip(dev_priv, fb_bits); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5595 | } |
| 5596 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5597 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5598 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5599 | struct drm_atomic_state *old_state) |
| 5600 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5601 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5602 | struct drm_connector *conn; |
| 5603 | int i; |
| 5604 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5605 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5606 | struct intel_encoder *encoder = |
| 5607 | to_intel_encoder(conn_state->best_encoder); |
| 5608 | |
| 5609 | if (conn_state->crtc != crtc) |
| 5610 | continue; |
| 5611 | |
| 5612 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5613 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5614 | } |
| 5615 | } |
| 5616 | |
| 5617 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5618 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5619 | struct drm_atomic_state *old_state) |
| 5620 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5621 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5622 | struct drm_connector *conn; |
| 5623 | int i; |
| 5624 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5625 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5626 | struct intel_encoder *encoder = |
| 5627 | to_intel_encoder(conn_state->best_encoder); |
| 5628 | |
| 5629 | if (conn_state->crtc != crtc) |
| 5630 | continue; |
| 5631 | |
| 5632 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5633 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5634 | } |
| 5635 | } |
| 5636 | |
| 5637 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5638 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5639 | struct drm_atomic_state *old_state) |
| 5640 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5641 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5642 | struct drm_connector *conn; |
| 5643 | int i; |
| 5644 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5645 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5646 | struct intel_encoder *encoder = |
| 5647 | to_intel_encoder(conn_state->best_encoder); |
| 5648 | |
| 5649 | if (conn_state->crtc != crtc) |
| 5650 | continue; |
| 5651 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5652 | if (encoder->enable) |
| 5653 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5654 | intel_opregion_notify_encoder(encoder, true); |
| 5655 | } |
| 5656 | } |
| 5657 | |
| 5658 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5659 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5660 | struct drm_atomic_state *old_state) |
| 5661 | { |
| 5662 | struct drm_connector_state *old_conn_state; |
| 5663 | struct drm_connector *conn; |
| 5664 | int i; |
| 5665 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5666 | 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] | 5667 | struct intel_encoder *encoder = |
| 5668 | to_intel_encoder(old_conn_state->best_encoder); |
| 5669 | |
| 5670 | if (old_conn_state->crtc != crtc) |
| 5671 | continue; |
| 5672 | |
| 5673 | intel_opregion_notify_encoder(encoder, false); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5674 | if (encoder->disable) |
| 5675 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5680 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5681 | struct drm_atomic_state *old_state) |
| 5682 | { |
| 5683 | struct drm_connector_state *old_conn_state; |
| 5684 | struct drm_connector *conn; |
| 5685 | int i; |
| 5686 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5687 | 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] | 5688 | struct intel_encoder *encoder = |
| 5689 | to_intel_encoder(old_conn_state->best_encoder); |
| 5690 | |
| 5691 | if (old_conn_state->crtc != crtc) |
| 5692 | continue; |
| 5693 | |
| 5694 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5695 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5700 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5701 | struct drm_atomic_state *old_state) |
| 5702 | { |
| 5703 | struct drm_connector_state *old_conn_state; |
| 5704 | struct drm_connector *conn; |
| 5705 | int i; |
| 5706 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5707 | 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] | 5708 | struct intel_encoder *encoder = |
| 5709 | to_intel_encoder(old_conn_state->best_encoder); |
| 5710 | |
| 5711 | if (old_conn_state->crtc != crtc) |
| 5712 | continue; |
| 5713 | |
| 5714 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5715 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5716 | } |
| 5717 | } |
| 5718 | |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 5719 | static void intel_encoders_update_pipe(struct drm_crtc *crtc, |
| 5720 | struct intel_crtc_state *crtc_state, |
| 5721 | struct drm_atomic_state *old_state) |
| 5722 | { |
| 5723 | struct drm_connector_state *conn_state; |
| 5724 | struct drm_connector *conn; |
| 5725 | int i; |
| 5726 | |
| 5727 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
| 5728 | struct intel_encoder *encoder = |
| 5729 | to_intel_encoder(conn_state->best_encoder); |
| 5730 | |
| 5731 | if (conn_state->crtc != crtc) |
| 5732 | continue; |
| 5733 | |
| 5734 | if (encoder->update_pipe) |
| 5735 | encoder->update_pipe(encoder, crtc_state, conn_state); |
| 5736 | } |
| 5737 | } |
| 5738 | |
Ville Syrjälä | 73a116b | 2019-02-07 22:21:46 +0200 | [diff] [blame] | 5739 | static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state) |
| 5740 | { |
| 5741 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5742 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 5743 | |
| 5744 | plane->disable_plane(plane, crtc_state); |
| 5745 | } |
| 5746 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5747 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5748 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5749 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5750 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5751 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5752 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5753 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5754 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5755 | struct intel_atomic_state *old_intel_state = |
| 5756 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5757 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5758 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5759 | return; |
| 5760 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5761 | /* |
| 5762 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5763 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5764 | * |
| 5765 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5766 | * between eDP port A enable and vdd enable. Also PCH port |
| 5767 | * enable seems to result in the occasional CPU pipe underrun. |
| 5768 | * |
| 5769 | * Spurious PCH underruns also occur during PCH enabling. |
| 5770 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5771 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5772 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5773 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5774 | if (pipe_config->has_pch_encoder) |
| 5775 | intel_prepare_shared_dpll(pipe_config); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5776 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5777 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5778 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5779 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5780 | intel_set_pipe_timings(pipe_config); |
| 5781 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5782 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5783 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5784 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5785 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5786 | } |
| 5787 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5788 | ironlake_set_pipeconf(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5789 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5790 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5791 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5792 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5793 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5794 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5795 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5796 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5797 | * enabling. */ |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 5798 | ironlake_fdi_pll_enable(pipe_config); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5799 | } else { |
| 5800 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5801 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5802 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5803 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5804 | ironlake_pfit_enable(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5805 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5806 | /* |
| 5807 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5808 | * clocks enabled |
| 5809 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5810 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 5811 | intel_color_commit(pipe_config); |
Ville Syrjälä | 73a116b | 2019-02-07 22:21:46 +0200 | [diff] [blame] | 5812 | /* update DSPCNTR to configure gamma for pipe bottom color */ |
| 5813 | intel_disable_primary_plane(pipe_config); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5814 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5815 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5816 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5817 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5818 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5819 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5820 | ironlake_pch_enable(old_intel_state, pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5821 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5822 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 5823 | intel_crtc_vblank_on(pipe_config); |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5824 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5825 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5826 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5827 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5828 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5829 | |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5830 | /* |
| 5831 | * Must wait for vblank to avoid spurious PCH FIFO underruns. |
| 5832 | * And a second vblank wait is needed at least on ILK with |
| 5833 | * some interlaced HDMI modes. Let's do the double wait always |
| 5834 | * in case there are more corner cases we don't know about. |
| 5835 | */ |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5836 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5837 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5838 | intel_wait_for_vblank(dev_priv, pipe); |
| 5839 | } |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5840 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5841 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5844 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5845 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5846 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5847 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5848 | } |
| 5849 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5850 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5851 | enum pipe pipe, bool apply) |
| 5852 | { |
| 5853 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5854 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5855 | |
| 5856 | if (apply) |
| 5857 | val |= mask; |
| 5858 | else |
| 5859 | val &= ~mask; |
| 5860 | |
| 5861 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5862 | } |
| 5863 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5864 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5865 | { |
| 5866 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5867 | enum pipe pipe = crtc->pipe; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 5868 | u32 val; |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5869 | |
Rodrigo Vivi | 443d5e3 | 2018-10-04 08:18:14 -0700 | [diff] [blame] | 5870 | val = MBUS_DBOX_A_CREDIT(2); |
| 5871 | val |= MBUS_DBOX_BW_CREDIT(1); |
| 5872 | val |= MBUS_DBOX_B_CREDIT(8); |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5873 | |
| 5874 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5875 | } |
| 5876 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5877 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5878 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5879 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5880 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5881 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5882 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5883 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5884 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5885 | struct intel_atomic_state *old_intel_state = |
| 5886 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5887 | bool psl_clkgate_wa; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5888 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5889 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5890 | return; |
| 5891 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5892 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5893 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5894 | if (pipe_config->shared_dpll) |
| 5895 | intel_enable_shared_dpll(pipe_config); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5896 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame] | 5897 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5898 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5899 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5900 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5901 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5902 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5903 | intel_set_pipe_timings(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5904 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5905 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5906 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5907 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5908 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5909 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5910 | pipe_config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5911 | } |
| 5912 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5913 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5914 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5915 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5916 | } |
| 5917 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5918 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5919 | haswell_set_pipeconf(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5920 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5921 | haswell_set_pipemisc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5922 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5923 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5924 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5925 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5926 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5927 | pipe_config->pch_pfit.enabled; |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5928 | if (psl_clkgate_wa) |
| 5929 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5930 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5931 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5932 | skylake_pfit_enable(pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5933 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5934 | ironlake_pfit_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5935 | |
| 5936 | /* |
| 5937 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5938 | * clocks enabled |
| 5939 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5940 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 5941 | intel_color_commit(pipe_config); |
Ville Syrjälä | 73a116b | 2019-02-07 22:21:46 +0200 | [diff] [blame] | 5942 | /* update DSPCNTR to configure gamma/csc for pipe bottom color */ |
| 5943 | if (INTEL_GEN(dev_priv) < 9) |
| 5944 | intel_disable_primary_plane(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5945 | |
Ville Syrjälä | d162211 | 2019-02-04 22:21:39 +0200 | [diff] [blame] | 5946 | if (INTEL_GEN(dev_priv) >= 11) |
| 5947 | icl_set_pipe_chicken(intel_crtc); |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5948 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5949 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5950 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5951 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5952 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5953 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5954 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5955 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5956 | if (INTEL_GEN(dev_priv) >= 11) |
| 5957 | icl_pipe_mbus_enable(intel_crtc); |
| 5958 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5959 | /* 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] | 5960 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5961 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5962 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5963 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5964 | lpt_pch_enable(old_intel_state, pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5965 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5966 | 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] | 5967 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5968 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5969 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 5970 | intel_crtc_vblank_on(pipe_config); |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5971 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5972 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5973 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5974 | if (psl_clkgate_wa) { |
| 5975 | intel_wait_for_vblank(dev_priv, pipe); |
| 5976 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5977 | } |
| 5978 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5979 | /* If we change the relative order between pipe/planes enabling, we need |
| 5980 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5981 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5982 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5983 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5984 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5985 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5986 | } |
| 5987 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5988 | 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] | 5989 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5990 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5991 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5992 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5993 | |
| 5994 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5995 | * 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] | 5996 | if (old_crtc_state->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5997 | I915_WRITE(PF_CTL(pipe), 0); |
| 5998 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5999 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 6000 | } |
| 6001 | } |
| 6002 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6003 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6004 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6005 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6006 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6007 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6008 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6009 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6010 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6011 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 6012 | /* |
| 6013 | * Sometimes spurious CPU pipe underruns happen when the |
| 6014 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 6015 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 6016 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 6017 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 6018 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 6019 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6020 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 6021 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6022 | drm_crtc_vblank_off(crtc); |
| 6023 | assert_vblank_disabled(crtc); |
| 6024 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6025 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6026 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6027 | ironlake_pfit_disable(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6028 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6029 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 6030 | ironlake_fdi_disable(crtc); |
| 6031 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6032 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6033 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6034 | if (old_crtc_state->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6035 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6036 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 6037 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 6038 | i915_reg_t reg; |
| 6039 | u32 temp; |
| 6040 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6041 | /* disable TRANS_DP_CTL */ |
| 6042 | reg = TRANS_DP_CTL(pipe); |
| 6043 | temp = I915_READ(reg); |
| 6044 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 6045 | TRANS_DP_PORT_SEL_MASK); |
| 6046 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 6047 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6048 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6049 | /* disable DPLL_SEL */ |
| 6050 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 6051 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6052 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6053 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6054 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 6055 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6056 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 6057 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 6058 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 6059 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 6060 | } |
| 6061 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6062 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6063 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6064 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6065 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6066 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6067 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 6068 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6069 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6070 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6071 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6072 | drm_crtc_vblank_off(crtc); |
| 6073 | assert_vblank_disabled(crtc); |
| 6074 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 6075 | /* 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] | 6076 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6077 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6078 | |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 6079 | if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) |
| 6080 | intel_ddi_set_vc_payload_alloc(old_crtc_state, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 6081 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 6082 | if (!transcoder_is_dsi(cpu_transcoder)) |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 6083 | intel_ddi_disable_transcoder_func(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6084 | |
Manasi Navare | a600622 | 2018-11-28 12:26:23 -0800 | [diff] [blame] | 6085 | intel_dsc_disable(old_crtc_state); |
| 6086 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6087 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 6088 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 6089 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6090 | ironlake_pfit_disable(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6091 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6092 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 6093 | |
Imre Deak | bdaa29b | 2018-11-01 16:04:24 +0200 | [diff] [blame] | 6094 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 6095 | } |
| 6096 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6097 | static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6098 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6099 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6100 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6101 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6102 | if (!crtc_state->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6103 | return; |
| 6104 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 6105 | /* |
| 6106 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 6107 | * according to register description and PRM. |
| 6108 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6109 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 6110 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6111 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6112 | I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios); |
| 6113 | I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 6114 | |
| 6115 | /* Border color in case we don't scale up to the full screen. Black by |
| 6116 | * default, change to something else for debugging. */ |
| 6117 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6118 | } |
| 6119 | |
Mahesh Kumar | 176597a | 2018-10-04 14:20:43 +0530 | [diff] [blame] | 6120 | bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port) |
| 6121 | { |
| 6122 | if (port == PORT_NONE) |
| 6123 | return false; |
| 6124 | |
| 6125 | if (IS_ICELAKE(dev_priv)) |
| 6126 | return port <= PORT_B; |
| 6127 | |
| 6128 | return false; |
| 6129 | } |
| 6130 | |
Paulo Zanoni | ac213c1 | 2018-05-21 17:25:37 -0700 | [diff] [blame] | 6131 | bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port) |
| 6132 | { |
| 6133 | if (IS_ICELAKE(dev_priv)) |
| 6134 | return port >= PORT_C && port <= PORT_F; |
| 6135 | |
| 6136 | return false; |
| 6137 | } |
| 6138 | |
| 6139 | enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) |
| 6140 | { |
| 6141 | if (!intel_port_is_tc(dev_priv, port)) |
| 6142 | return PORT_TC_NONE; |
| 6143 | |
| 6144 | return port - PORT_C; |
| 6145 | } |
| 6146 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6147 | 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] | 6148 | { |
| 6149 | switch (port) { |
| 6150 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6151 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6152 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6153 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6154 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6155 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6156 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6157 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 6158 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6159 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 6160 | case PORT_F: |
| 6161 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6162 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 6163 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6164 | return POWER_DOMAIN_PORT_OTHER; |
| 6165 | } |
| 6166 | } |
| 6167 | |
Imre Deak | 337837a | 2018-11-01 16:04:23 +0200 | [diff] [blame] | 6168 | enum intel_display_power_domain |
| 6169 | intel_aux_power_domain(struct intel_digital_port *dig_port) |
| 6170 | { |
| 6171 | switch (dig_port->aux_ch) { |
| 6172 | case AUX_CH_A: |
| 6173 | return POWER_DOMAIN_AUX_A; |
| 6174 | case AUX_CH_B: |
| 6175 | return POWER_DOMAIN_AUX_B; |
| 6176 | case AUX_CH_C: |
| 6177 | return POWER_DOMAIN_AUX_C; |
| 6178 | case AUX_CH_D: |
| 6179 | return POWER_DOMAIN_AUX_D; |
| 6180 | case AUX_CH_E: |
| 6181 | return POWER_DOMAIN_AUX_E; |
| 6182 | case AUX_CH_F: |
| 6183 | return POWER_DOMAIN_AUX_F; |
| 6184 | default: |
| 6185 | MISSING_CASE(dig_port->aux_ch); |
| 6186 | return POWER_DOMAIN_AUX_A; |
| 6187 | } |
| 6188 | } |
| 6189 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6190 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 6191 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6192 | { |
| 6193 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6194 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6195 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6196 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6197 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6198 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6199 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6200 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6201 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6202 | return 0; |
| 6203 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6204 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 6205 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6206 | if (crtc_state->pch_pfit.enabled || |
| 6207 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6208 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6209 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6210 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 6211 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 6212 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6213 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6214 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6215 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6216 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6217 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6218 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6219 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6220 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6221 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6222 | return mask; |
| 6223 | } |
| 6224 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6225 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6226 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 6227 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6228 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6229 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6230 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6231 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6232 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6233 | |
| 6234 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6235 | intel_crtc->enabled_power_domains = new_domains = |
| 6236 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6237 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6238 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6239 | |
| 6240 | for_each_power_domain(domain, domains) |
| 6241 | intel_display_power_get(dev_priv, domain); |
| 6242 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6243 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | 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] | 6247 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6248 | { |
| 6249 | enum intel_display_power_domain domain; |
| 6250 | |
| 6251 | for_each_power_domain(domain, domains) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 6252 | intel_display_power_put_unchecked(dev_priv, domain); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6253 | } |
| 6254 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6255 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6256 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6257 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6258 | struct intel_atomic_state *old_intel_state = |
| 6259 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6260 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6261 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6262 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6263 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6264 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6265 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6266 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6267 | return; |
| 6268 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6269 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6270 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6271 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6272 | intel_set_pipe_timings(pipe_config); |
| 6273 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6274 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6275 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6276 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6277 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6278 | } |
| 6279 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6280 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6281 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6282 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6283 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6284 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6285 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6286 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6287 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6288 | if (IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6289 | chv_prepare_pll(intel_crtc, pipe_config); |
| 6290 | chv_enable_pll(intel_crtc, pipe_config); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6291 | } else { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6292 | vlv_prepare_pll(intel_crtc, pipe_config); |
| 6293 | vlv_enable_pll(intel_crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6294 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6295 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6296 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6297 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6298 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6299 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6300 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 6301 | intel_color_commit(pipe_config); |
Ville Syrjälä | 73a116b | 2019-02-07 22:21:46 +0200 | [diff] [blame] | 6302 | /* update DSPCNTR to configure gamma for pipe bottom color */ |
| 6303 | intel_disable_primary_plane(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6304 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6305 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6306 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6307 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6308 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6309 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 6310 | intel_crtc_vblank_on(pipe_config); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6311 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6312 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6313 | } |
| 6314 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6315 | 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] | 6316 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6317 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6318 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6319 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6320 | I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0); |
| 6321 | I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6322 | } |
| 6323 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6324 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6325 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6326 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6327 | struct intel_atomic_state *old_intel_state = |
| 6328 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6329 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6330 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6331 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6332 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6333 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6334 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6335 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6336 | return; |
| 6337 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6338 | i9xx_set_pll_dividers(pipe_config); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6339 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6340 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6341 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6342 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6343 | intel_set_pipe_timings(pipe_config); |
| 6344 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6345 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6346 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6347 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6348 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6349 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6350 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6351 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6352 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6353 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6354 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 6355 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6356 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6357 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6358 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6359 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 6360 | intel_color_commit(pipe_config); |
Ville Syrjälä | 73a116b | 2019-02-07 22:21:46 +0200 | [diff] [blame] | 6361 | /* update DSPCNTR to configure gamma for pipe bottom color */ |
| 6362 | intel_disable_primary_plane(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6363 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6364 | if (dev_priv->display.initial_watermarks != NULL) |
| 6365 | dev_priv->display.initial_watermarks(old_intel_state, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6366 | pipe_config); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6367 | else |
| 6368 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6369 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6370 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6371 | assert_vblank_disabled(crtc); |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 6372 | intel_crtc_vblank_on(pipe_config); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6373 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6374 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6375 | } |
| 6376 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6377 | 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] | 6378 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6379 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 6380 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6381 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6382 | if (!old_crtc_state->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6383 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6384 | |
| 6385 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6386 | |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 6387 | DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n", |
| 6388 | I915_READ(PFIT_CONTROL)); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6389 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6390 | } |
| 6391 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6392 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6393 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6394 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6395 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6396 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6397 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6398 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6399 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6400 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6401 | /* |
| 6402 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6403 | * wait for planes to fully turn off before disabling the pipe. |
| 6404 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6405 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6406 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6407 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6408 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6409 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6410 | drm_crtc_vblank_off(crtc); |
| 6411 | assert_vblank_disabled(crtc); |
| 6412 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6413 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6414 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6415 | i9xx_pfit_disable(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6416 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6417 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6418 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6419 | if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6420 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6421 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6422 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6423 | vlv_disable_pll(dev_priv, pipe); |
| 6424 | else |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6425 | i9xx_disable_pll(old_crtc_state); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6426 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6427 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6428 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6429 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6430 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6431 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6432 | |
| 6433 | if (!dev_priv->display.initial_watermarks) |
| 6434 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6435 | |
| 6436 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6437 | if (IS_I830(dev_priv)) |
| 6438 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6439 | } |
| 6440 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6441 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6442 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6443 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6444 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6445 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6446 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6447 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6448 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6449 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6450 | struct drm_atomic_state *state; |
| 6451 | struct intel_crtc_state *crtc_state; |
| 6452 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6453 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6454 | if (!intel_crtc->active) |
| 6455 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6456 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6457 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6458 | const struct intel_plane_state *plane_state = |
| 6459 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6460 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6461 | if (plane_state->base.visible) |
| 6462 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6463 | } |
| 6464 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6465 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6466 | if (!state) { |
| 6467 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6468 | crtc->base.id, crtc->name); |
| 6469 | return; |
| 6470 | } |
| 6471 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6472 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6473 | |
| 6474 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6475 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6476 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6477 | |
| 6478 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6479 | |
| 6480 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6481 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6482 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6483 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6484 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6485 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6486 | |
| 6487 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6488 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6489 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6490 | crtc->enabled = false; |
| 6491 | crtc->state->connector_mask = 0; |
| 6492 | crtc->state->encoder_mask = 0; |
| 6493 | |
| 6494 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6495 | encoder->base.crtc = NULL; |
| 6496 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6497 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6498 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 6499 | intel_disable_shared_dpll(to_intel_crtc_state(crtc->state)); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6500 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6501 | domains = intel_crtc->enabled_power_domains; |
| 6502 | for_each_power_domain(domain, domains) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 6503 | intel_display_power_put_unchecked(dev_priv, domain); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6504 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6505 | |
| 6506 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6507 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6508 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6509 | } |
| 6510 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6511 | /* |
| 6512 | * turn all crtc's off, but do not adjust state |
| 6513 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6514 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6515 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6516 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6517 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6518 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6519 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6520 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6521 | state = drm_atomic_helper_suspend(dev); |
| 6522 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6523 | if (ret) |
| 6524 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6525 | else |
| 6526 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6527 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6528 | } |
| 6529 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6530 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6531 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6532 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6533 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6534 | drm_encoder_cleanup(encoder); |
| 6535 | kfree(intel_encoder); |
| 6536 | } |
| 6537 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6538 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6539 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6540 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6541 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6542 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6543 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6544 | |
| 6545 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6546 | connector->base.base.id, |
| 6547 | connector->base.name); |
| 6548 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6549 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6550 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6551 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6552 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6553 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6554 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6555 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6556 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6557 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6558 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6559 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6560 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6561 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6562 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6563 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6564 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6565 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6566 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6567 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6568 | "attached encoder crtc differs from connector crtc\n"); |
| 6569 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6570 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6571 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6572 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6573 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6574 | } |
| 6575 | } |
| 6576 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6577 | 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] | 6578 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6579 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6580 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6581 | |
| 6582 | return 0; |
| 6583 | } |
| 6584 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6585 | 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] | 6586 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6587 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6588 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6589 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6590 | struct intel_crtc *other_crtc; |
| 6591 | struct intel_crtc_state *other_crtc_state; |
| 6592 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6593 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6594 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6595 | if (pipe_config->fdi_lanes > 4) { |
| 6596 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6597 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6598 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6599 | } |
| 6600 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6601 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6602 | if (pipe_config->fdi_lanes > 2) { |
| 6603 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6604 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6605 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6606 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6607 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6608 | } |
| 6609 | } |
| 6610 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6611 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6612 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6613 | |
| 6614 | /* Ivybridge 3 pipe is really complicated */ |
| 6615 | switch (pipe) { |
| 6616 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6617 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6618 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6619 | if (pipe_config->fdi_lanes <= 2) |
| 6620 | return 0; |
| 6621 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6622 | 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] | 6623 | other_crtc_state = |
| 6624 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6625 | if (IS_ERR(other_crtc_state)) |
| 6626 | return PTR_ERR(other_crtc_state); |
| 6627 | |
| 6628 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6629 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6630 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6631 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6632 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6633 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6634 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6635 | if (pipe_config->fdi_lanes > 2) { |
| 6636 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6637 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6638 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6639 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6640 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6641 | 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] | 6642 | other_crtc_state = |
| 6643 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6644 | if (IS_ERR(other_crtc_state)) |
| 6645 | return PTR_ERR(other_crtc_state); |
| 6646 | |
| 6647 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6648 | 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] | 6649 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6650 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6651 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6652 | default: |
| 6653 | BUG(); |
| 6654 | } |
| 6655 | } |
| 6656 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6657 | #define RETRY 1 |
| 6658 | 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] | 6659 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6660 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6661 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6662 | 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] | 6663 | int lane, link_bw, fdi_dotclock, ret; |
| 6664 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6665 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6666 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6667 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6668 | * each output octet as 10 bits. The actual frequency |
| 6669 | * is stored as a divider into a 100MHz clock, and the |
| 6670 | * mode pixel clock is stored in units of 1KHz. |
| 6671 | * Hence the bw of each lane in terms of the mode signal |
| 6672 | * is: |
| 6673 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6674 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6675 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6676 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6677 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6678 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6679 | pipe_config->pipe_bpp); |
| 6680 | |
| 6681 | pipe_config->fdi_lanes = lane; |
| 6682 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6683 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6684 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6685 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6686 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 6687 | if (ret == -EDEADLK) |
| 6688 | return ret; |
| 6689 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6690 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6691 | pipe_config->pipe_bpp -= 2*3; |
| 6692 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6693 | pipe_config->pipe_bpp); |
| 6694 | needs_recompute = true; |
| 6695 | pipe_config->bw_constrained = true; |
| 6696 | |
| 6697 | goto retry; |
| 6698 | } |
| 6699 | |
| 6700 | if (needs_recompute) |
| 6701 | return RETRY; |
| 6702 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6703 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6704 | } |
| 6705 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6706 | 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] | 6707 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6708 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6709 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6710 | |
| 6711 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6712 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6713 | return false; |
| 6714 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6715 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6716 | return false; |
| 6717 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6718 | if (crtc_state->pipe_bpp > 24) |
| 6719 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6720 | |
| 6721 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6722 | * We compare against max which means we must take |
| 6723 | * the increased cdclk requirement into account when |
| 6724 | * calculating the new cdclk. |
| 6725 | * |
| 6726 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6727 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6728 | if (IS_BROADWELL(dev_priv) && |
| 6729 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6730 | return false; |
| 6731 | |
| 6732 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6733 | } |
| 6734 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6735 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6736 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6737 | struct drm_i915_private *dev_priv = |
| 6738 | to_i915(crtc_state->base.crtc->dev); |
| 6739 | struct intel_atomic_state *intel_state = |
| 6740 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6741 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6742 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6743 | return false; |
| 6744 | |
| 6745 | if (crtc_state->ips_force_disable) |
| 6746 | return false; |
| 6747 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6748 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6749 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6750 | return false; |
| 6751 | |
| 6752 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6753 | if (IS_BROADWELL(dev_priv) && |
| 6754 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6755 | return false; |
| 6756 | |
| 6757 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6758 | } |
| 6759 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6760 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6761 | { |
| 6762 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6763 | |
| 6764 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6765 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6766 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6767 | } |
| 6768 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6769 | static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6770 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6771 | u32 pixel_rate; |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6772 | |
| 6773 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6774 | |
| 6775 | /* |
| 6776 | * We only use IF-ID interlacing. If we ever use |
| 6777 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6778 | */ |
| 6779 | |
| 6780 | if (pipe_config->pch_pfit.enabled) { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6781 | u64 pipe_w, pipe_h, pfit_w, pfit_h; |
| 6782 | u32 pfit_size = pipe_config->pch_pfit.size; |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6783 | |
| 6784 | pipe_w = pipe_config->pipe_src_w; |
| 6785 | pipe_h = pipe_config->pipe_src_h; |
| 6786 | |
| 6787 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6788 | pfit_h = pfit_size & 0xFFFF; |
| 6789 | if (pipe_w < pfit_w) |
| 6790 | pipe_w = pfit_w; |
| 6791 | if (pipe_h < pfit_h) |
| 6792 | pipe_h = pfit_h; |
| 6793 | |
| 6794 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6795 | return pixel_rate; |
| 6796 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6797 | pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h, |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6798 | pfit_w * pfit_h); |
| 6799 | } |
| 6800 | |
| 6801 | return pixel_rate; |
| 6802 | } |
| 6803 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6804 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6805 | { |
| 6806 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6807 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 6808 | if (HAS_GMCH(dev_priv)) |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6809 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6810 | crtc_state->pixel_rate = |
| 6811 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6812 | else |
| 6813 | crtc_state->pixel_rate = |
| 6814 | ilk_pipe_pixel_rate(crtc_state); |
| 6815 | } |
| 6816 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6817 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6818 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6819 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6820 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6821 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6822 | 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] | 6823 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6824 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6825 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6826 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6827 | |
| 6828 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6829 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6830 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6831 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6832 | if (intel_crtc_supports_double_wide(crtc) && |
| 6833 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6834 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6835 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6836 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6837 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6838 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6839 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6840 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6841 | adjusted_mode->crtc_clock, clock_limit, |
| 6842 | yesno(pipe_config->double_wide)); |
| 6843 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6844 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6845 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 6846 | if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 6847 | pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) && |
| 6848 | pipe_config->base.ctm) { |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6849 | /* |
| 6850 | * There is only one pipe CSC unit per pipe, and we need that |
| 6851 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6852 | * applied we can't support YCBCR420 output. |
| 6853 | */ |
| 6854 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6855 | return -EINVAL; |
| 6856 | } |
| 6857 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6858 | /* |
| 6859 | * Pipe horizontal size must be even in: |
| 6860 | * - DVO ganged mode |
| 6861 | * - LVDS dual channel mode |
| 6862 | * - Double wide pipe |
| 6863 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6864 | if (pipe_config->pipe_src_w & 1) { |
| 6865 | if (pipe_config->double_wide) { |
| 6866 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6867 | return -EINVAL; |
| 6868 | } |
| 6869 | |
| 6870 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6871 | intel_is_dual_link_lvds(dev)) { |
| 6872 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6873 | return -EINVAL; |
| 6874 | } |
| 6875 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6876 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6877 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6878 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6879 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6880 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6881 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6882 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6883 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6884 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6885 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6886 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6887 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6888 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6889 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6890 | } |
| 6891 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6892 | static void |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6893 | intel_reduce_m_n_ratio(u32 *num, u32 *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6894 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6895 | while (*num > DATA_LINK_M_N_MASK || |
| 6896 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6897 | *num >>= 1; |
| 6898 | *den >>= 1; |
| 6899 | } |
| 6900 | } |
| 6901 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6902 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6903 | u32 *ret_m, u32 *ret_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6904 | bool constant_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6905 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6906 | /* |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6907 | * Several DP dongles in particular seem to be fussy about |
| 6908 | * too large link M/N values. Give N value as 0x8000 that |
| 6909 | * should be acceptable by specific devices. 0x8000 is the |
| 6910 | * specified fixed N value for asynchronous clock mode, |
| 6911 | * which the devices expect also in synchronous clock mode. |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6912 | */ |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6913 | if (constant_n) |
| 6914 | *ret_n = 0x8000; |
| 6915 | else |
| 6916 | *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] | 6917 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6918 | *ret_m = div_u64((u64)m * *ret_n, n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6919 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6920 | } |
| 6921 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6922 | void |
Manasi Navare | a4a1577 | 2018-11-28 13:36:21 -0800 | [diff] [blame] | 6923 | intel_link_compute_m_n(u16 bits_per_pixel, int nlanes, |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6924 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6925 | struct intel_link_m_n *m_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6926 | bool constant_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6927 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6928 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6929 | |
| 6930 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6931 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6932 | &m_n->gmch_m, &m_n->gmch_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6933 | constant_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6934 | |
| 6935 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6936 | &m_n->link_m, &m_n->link_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6937 | constant_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6938 | } |
| 6939 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6940 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6941 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6942 | if (i915_modparams.panel_use_ssc >= 0) |
| 6943 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6944 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6945 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6946 | } |
| 6947 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6948 | static u32 pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6949 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6950 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6951 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6952 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6953 | static u32 i9xx_dpll_compute_fp(struct dpll *dpll) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6954 | { |
| 6955 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6956 | } |
| 6957 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6958 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6959 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6960 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6961 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6962 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6963 | u32 fp, fp2 = 0; |
| 6964 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6965 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6966 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6967 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6968 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6969 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6970 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6971 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6972 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6973 | } |
| 6974 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6975 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6976 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6977 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6978 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6979 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6980 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6981 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6982 | } |
| 6983 | } |
| 6984 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6985 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6986 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6987 | { |
| 6988 | u32 reg_val; |
| 6989 | |
| 6990 | /* |
| 6991 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6992 | * and set it to a reasonable value instead. |
| 6993 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6994 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6995 | reg_val &= 0xffffff00; |
| 6996 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6997 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6998 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6999 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 7000 | reg_val &= 0x00ffffff; |
| 7001 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7002 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7003 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7004 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7005 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7006 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7007 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7008 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7009 | reg_val &= 0x00ffffff; |
| 7010 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7011 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7012 | } |
| 7013 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7014 | static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 7015 | const struct intel_link_m_n *m_n) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7016 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7017 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7018 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7019 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7020 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7021 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7022 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7023 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7024 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7025 | } |
| 7026 | |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7027 | static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv, |
| 7028 | enum transcoder transcoder) |
| 7029 | { |
| 7030 | if (IS_HASWELL(dev_priv)) |
| 7031 | return transcoder == TRANSCODER_EDP; |
| 7032 | |
| 7033 | /* |
| 7034 | * Strictly speaking some registers are available before |
| 7035 | * gen7, but we only support DRRS on gen7+ |
| 7036 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 7037 | return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7038 | } |
| 7039 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7040 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 7041 | const struct intel_link_m_n *m_n, |
| 7042 | const struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7043 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7044 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7045 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7046 | enum pipe pipe = crtc->pipe; |
| 7047 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7048 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7049 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7050 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7051 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7052 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7053 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7054 | /* |
| 7055 | * M2_N2 registers are set only if DRRS is supported |
| 7056 | * (to make sure the registers are not unnecessarily accessed). |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7057 | */ |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 7058 | if (m2_n2 && crtc_state->has_drrs && |
| 7059 | transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7060 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7061 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7062 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7063 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7064 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7065 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7066 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7067 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7068 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7069 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7070 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7071 | } |
| 7072 | } |
| 7073 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7074 | void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7075 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7076 | const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7077 | |
| 7078 | if (m_n == M1_N1) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7079 | dp_m_n = &crtc_state->dp_m_n; |
| 7080 | dp_m2_n2 = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7081 | } else if (m_n == M2_N2) { |
| 7082 | |
| 7083 | /* |
| 7084 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7085 | * needs to be programmed into M1_N1. |
| 7086 | */ |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7087 | dp_m_n = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7088 | } else { |
| 7089 | DRM_ERROR("Unsupported divider value\n"); |
| 7090 | return; |
| 7091 | } |
| 7092 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7093 | if (crtc_state->has_pch_encoder) |
| 7094 | intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7095 | else |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 7096 | intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7097 | } |
| 7098 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7099 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7100 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7101 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7102 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7103 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7104 | if (crtc->pipe != PIPE_A) |
| 7105 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7106 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7107 | /* 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] | 7108 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7109 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 7110 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 7111 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7112 | pipe_config->dpll_hw_state.dpll_md = |
| 7113 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 7114 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7115 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7116 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7117 | struct intel_crtc_state *pipe_config) |
| 7118 | { |
| 7119 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7120 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7121 | if (crtc->pipe != PIPE_A) |
| 7122 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7123 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7124 | /* 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] | 7125 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7126 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 7127 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7128 | pipe_config->dpll_hw_state.dpll_md = |
| 7129 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7130 | } |
| 7131 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7132 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7133 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7134 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7135 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7136 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7137 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7138 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7139 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7140 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7141 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7142 | /* Enable Refclk */ |
| 7143 | I915_WRITE(DPLL(pipe), |
| 7144 | pipe_config->dpll_hw_state.dpll & |
| 7145 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 7146 | |
| 7147 | /* No need to actually set up the DPLL with DSI */ |
| 7148 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7149 | return; |
| 7150 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7151 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7152 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7153 | bestn = pipe_config->dpll.n; |
| 7154 | bestm1 = pipe_config->dpll.m1; |
| 7155 | bestm2 = pipe_config->dpll.m2; |
| 7156 | bestp1 = pipe_config->dpll.p1; |
| 7157 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7158 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7159 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7160 | |
| 7161 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7162 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7163 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7164 | |
| 7165 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7166 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7167 | |
| 7168 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7169 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7170 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7171 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7172 | |
| 7173 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7174 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7175 | |
| 7176 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7177 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7178 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7179 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7180 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7181 | |
| 7182 | /* |
| 7183 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7184 | * but we don't support that). |
| 7185 | * Note: don't use the DAC post divider as it seems unstable. |
| 7186 | */ |
| 7187 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7188 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7189 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7190 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7191 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7192 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7193 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7194 | if (pipe_config->port_clock == 162000 || |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7195 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) || |
| 7196 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7197 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7198 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7199 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7200 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7201 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7202 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7203 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7204 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7205 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7206 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7207 | 0x0df40000); |
| 7208 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7209 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7210 | 0x0df70000); |
| 7211 | } else { /* HDMI or VGA */ |
| 7212 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7213 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7214 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7215 | 0x0df70000); |
| 7216 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7217 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7218 | 0x0df40000); |
| 7219 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7220 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7221 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7222 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7223 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7224 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7225 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7226 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7227 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7228 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7229 | } |
| 7230 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7231 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7232 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7233 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7234 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7235 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7236 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7237 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7238 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7239 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7240 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7241 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7242 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7243 | /* Enable Refclk and SSC */ |
| 7244 | I915_WRITE(DPLL(pipe), |
| 7245 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7246 | |
| 7247 | /* No need to actually set up the DPLL with DSI */ |
| 7248 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7249 | return; |
| 7250 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7251 | bestn = pipe_config->dpll.n; |
| 7252 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7253 | bestm1 = pipe_config->dpll.m1; |
| 7254 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7255 | bestp1 = pipe_config->dpll.p1; |
| 7256 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7257 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7258 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7259 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7260 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7261 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7262 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7263 | /* p1 and p2 divider */ |
| 7264 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7265 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7266 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7267 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7268 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7269 | |
| 7270 | /* Feedback post-divider - m2 */ |
| 7271 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7272 | |
| 7273 | /* Feedback refclk divider - n and m1 */ |
| 7274 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7275 | DPIO_CHV_M1_DIV_BY_2 | |
| 7276 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7277 | |
| 7278 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7279 | 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] | 7280 | |
| 7281 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7282 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7283 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7284 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7285 | if (bestm2_frac) |
| 7286 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7287 | 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] | 7288 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7289 | /* Program digital lock detect threshold */ |
| 7290 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7291 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7292 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7293 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7294 | if (!bestm2_frac) |
| 7295 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7296 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7297 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7298 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7299 | if (vco == 5400000) { |
| 7300 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7301 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7302 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7303 | tribuf_calcntr = 0x9; |
| 7304 | } else if (vco <= 6200000) { |
| 7305 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7306 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7307 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7308 | tribuf_calcntr = 0x9; |
| 7309 | } else if (vco <= 6480000) { |
| 7310 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7311 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7312 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7313 | tribuf_calcntr = 0x8; |
| 7314 | } else { |
| 7315 | /* Not supported. Apply the same limits as in the max case */ |
| 7316 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7317 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7318 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7319 | tribuf_calcntr = 0; |
| 7320 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7321 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7322 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7323 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7324 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7325 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7326 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7327 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7328 | /* AFC Recal */ |
| 7329 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7330 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7331 | DPIO_AFC_RECAL); |
| 7332 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7333 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7334 | } |
| 7335 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7336 | /** |
| 7337 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7338 | * @dev_priv: i915 private structure |
| 7339 | * @pipe: pipe PLL to enable |
| 7340 | * @dpll: PLL configuration |
| 7341 | * |
| 7342 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7343 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7344 | * be enabled. |
| 7345 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7346 | 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] | 7347 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7348 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7349 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7350 | struct intel_crtc_state *pipe_config; |
| 7351 | |
| 7352 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7353 | if (!pipe_config) |
| 7354 | return -ENOMEM; |
| 7355 | |
| 7356 | pipe_config->base.crtc = &crtc->base; |
| 7357 | pipe_config->pixel_multiplier = 1; |
| 7358 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7359 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7360 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7361 | chv_compute_dpll(crtc, pipe_config); |
| 7362 | chv_prepare_pll(crtc, pipe_config); |
| 7363 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7364 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7365 | vlv_compute_dpll(crtc, pipe_config); |
| 7366 | vlv_prepare_pll(crtc, pipe_config); |
| 7367 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7368 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7369 | |
| 7370 | kfree(pipe_config); |
| 7371 | |
| 7372 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7373 | } |
| 7374 | |
| 7375 | /** |
| 7376 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7377 | * @dev_priv: i915 private structure |
| 7378 | * @pipe: pipe PLL to disable |
| 7379 | * |
| 7380 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7381 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7382 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7383 | 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] | 7384 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7385 | if (IS_CHERRYVIEW(dev_priv)) |
| 7386 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7387 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7388 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7389 | } |
| 7390 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7391 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7392 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7393 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7394 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7395 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7396 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7397 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7398 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7399 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7400 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7401 | dpll = DPLL_VGA_MODE_DIS; |
| 7402 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7403 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7404 | dpll |= DPLLB_MODE_LVDS; |
| 7405 | else |
| 7406 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7407 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7408 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7409 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7410 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7411 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7412 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7413 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7414 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7415 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7416 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7417 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7418 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7419 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7420 | |
| 7421 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7422 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7423 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7424 | else { |
| 7425 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7426 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7427 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7428 | } |
| 7429 | switch (clock->p2) { |
| 7430 | case 5: |
| 7431 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7432 | break; |
| 7433 | case 7: |
| 7434 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7435 | break; |
| 7436 | case 10: |
| 7437 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7438 | break; |
| 7439 | case 14: |
| 7440 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7441 | break; |
| 7442 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7443 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7444 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7445 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7446 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7447 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7448 | 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] | 7449 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7450 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7451 | else |
| 7452 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7453 | |
| 7454 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7455 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7456 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7457 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7458 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7459 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7460 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7461 | } |
| 7462 | } |
| 7463 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7464 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7465 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7466 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7467 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7468 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7469 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7470 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7471 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7472 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7473 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7474 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7475 | dpll = DPLL_VGA_MODE_DIS; |
| 7476 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7477 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7478 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7479 | } else { |
| 7480 | if (clock->p1 == 2) |
| 7481 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7482 | else |
| 7483 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7484 | if (clock->p2 == 4) |
| 7485 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7486 | } |
| 7487 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7488 | if (!IS_I830(dev_priv) && |
| 7489 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7490 | dpll |= DPLL_DVO_2X_MODE; |
| 7491 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7492 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7493 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7494 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7495 | else |
| 7496 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7497 | |
| 7498 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7499 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7500 | } |
| 7501 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7502 | 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] | 7503 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7504 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7505 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7506 | enum pipe pipe = crtc->pipe; |
| 7507 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 7508 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7509 | u32 crtc_vtotal, crtc_vblank_end; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7510 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7511 | |
| 7512 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7513 | * the hw state checker will get angry at the mismatch. */ |
| 7514 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7515 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7516 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7517 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7518 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7519 | crtc_vtotal -= 1; |
| 7520 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7521 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7522 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7523 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7524 | else |
| 7525 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7526 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7527 | if (vsyncshift < 0) |
| 7528 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7529 | } |
| 7530 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7531 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7532 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7533 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7534 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7535 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7536 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7537 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7538 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7539 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7540 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7541 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7542 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7543 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7544 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7545 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7546 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7547 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7548 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7549 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7550 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7551 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7552 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7553 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7554 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7555 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7556 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7557 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7558 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7559 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7560 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7561 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7562 | } |
| 7563 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7564 | 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] | 7565 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7566 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7567 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7568 | enum pipe pipe = crtc->pipe; |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7569 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7570 | /* pipesrc controls the size that is scaled from, which should |
| 7571 | * always be the user's requested size. |
| 7572 | */ |
| 7573 | I915_WRITE(PIPESRC(pipe), |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7574 | ((crtc_state->pipe_src_w - 1) << 16) | |
| 7575 | (crtc_state->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7576 | } |
| 7577 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7578 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7579 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7580 | { |
| 7581 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7582 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7583 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7584 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7585 | |
| 7586 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7587 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7588 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7589 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7590 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7591 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7592 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7593 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7594 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7595 | |
| 7596 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7597 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7598 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7599 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7600 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7601 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7602 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7603 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7604 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7605 | |
| 7606 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7607 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7608 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7609 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7610 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7611 | } |
| 7612 | |
| 7613 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7614 | struct intel_crtc_state *pipe_config) |
| 7615 | { |
| 7616 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7617 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7618 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7619 | |
| 7620 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7621 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7622 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7623 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7624 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7625 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7626 | } |
| 7627 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7628 | 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] | 7629 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7630 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7631 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7632 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7633 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7634 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7635 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7636 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7637 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7638 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7639 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7640 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7641 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7642 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7643 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7644 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7645 | |
| 7646 | mode->hsync = drm_mode_hsync(mode); |
| 7647 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7648 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7649 | } |
| 7650 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7651 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7652 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7653 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7654 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7655 | u32 pipeconf; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7656 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7657 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7658 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7659 | /* we keep both pipes enabled on 830 */ |
| 7660 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7661 | pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7662 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7663 | if (crtc_state->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7664 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7665 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7666 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7667 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7668 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7669 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7670 | if (crtc_state->dither && crtc_state->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7671 | pipeconf |= PIPECONF_DITHER_EN | |
| 7672 | PIPECONF_DITHER_TYPE_SP; |
| 7673 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7674 | switch (crtc_state->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7675 | case 18: |
| 7676 | pipeconf |= PIPECONF_6BPC; |
| 7677 | break; |
| 7678 | case 24: |
| 7679 | pipeconf |= PIPECONF_8BPC; |
| 7680 | break; |
| 7681 | case 30: |
| 7682 | pipeconf |= PIPECONF_10BPC; |
| 7683 | break; |
| 7684 | default: |
| 7685 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7686 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7687 | } |
| 7688 | } |
| 7689 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7690 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7691 | if (INTEL_GEN(dev_priv) < 4 || |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7692 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7693 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7694 | else |
| 7695 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7696 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7697 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7698 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7699 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7700 | crtc_state->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7701 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7702 | |
Ville Syrjälä | 9d5441d | 2019-02-07 22:21:40 +0200 | [diff] [blame] | 7703 | pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode); |
| 7704 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7705 | I915_WRITE(PIPECONF(crtc->pipe), pipeconf); |
| 7706 | POSTING_READ(PIPECONF(crtc->pipe)); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7707 | } |
| 7708 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7709 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7710 | struct intel_crtc_state *crtc_state) |
| 7711 | { |
| 7712 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7713 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7714 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7715 | int refclk = 48000; |
| 7716 | |
| 7717 | memset(&crtc_state->dpll_hw_state, 0, |
| 7718 | sizeof(crtc_state->dpll_hw_state)); |
| 7719 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7720 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7721 | if (intel_panel_use_ssc(dev_priv)) { |
| 7722 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7723 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7724 | } |
| 7725 | |
| 7726 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7727 | } 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] | 7728 | limit = &intel_limits_i8xx_dvo; |
| 7729 | } else { |
| 7730 | limit = &intel_limits_i8xx_dac; |
| 7731 | } |
| 7732 | |
| 7733 | if (!crtc_state->clock_set && |
| 7734 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7735 | refclk, NULL, &crtc_state->dpll)) { |
| 7736 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7737 | return -EINVAL; |
| 7738 | } |
| 7739 | |
| 7740 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7741 | |
| 7742 | return 0; |
| 7743 | } |
| 7744 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7745 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7746 | struct intel_crtc_state *crtc_state) |
| 7747 | { |
| 7748 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7749 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7750 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7751 | int refclk = 96000; |
| 7752 | |
| 7753 | memset(&crtc_state->dpll_hw_state, 0, |
| 7754 | sizeof(crtc_state->dpll_hw_state)); |
| 7755 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7756 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7757 | if (intel_panel_use_ssc(dev_priv)) { |
| 7758 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7759 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7760 | } |
| 7761 | |
| 7762 | if (intel_is_dual_link_lvds(dev)) |
| 7763 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7764 | else |
| 7765 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7766 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7767 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7768 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7769 | } 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] | 7770 | limit = &intel_limits_g4x_sdvo; |
| 7771 | } else { |
| 7772 | /* The option is for other outputs */ |
| 7773 | limit = &intel_limits_i9xx_sdvo; |
| 7774 | } |
| 7775 | |
| 7776 | if (!crtc_state->clock_set && |
| 7777 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7778 | refclk, NULL, &crtc_state->dpll)) { |
| 7779 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7780 | return -EINVAL; |
| 7781 | } |
| 7782 | |
| 7783 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7784 | |
| 7785 | return 0; |
| 7786 | } |
| 7787 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7788 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7789 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7790 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7791 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7792 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7793 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7794 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7795 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7796 | memset(&crtc_state->dpll_hw_state, 0, |
| 7797 | sizeof(crtc_state->dpll_hw_state)); |
| 7798 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7799 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7800 | if (intel_panel_use_ssc(dev_priv)) { |
| 7801 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7802 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7803 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7804 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7805 | limit = &intel_limits_pineview_lvds; |
| 7806 | } else { |
| 7807 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7808 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7809 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7810 | if (!crtc_state->clock_set && |
| 7811 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7812 | refclk, NULL, &crtc_state->dpll)) { |
| 7813 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7814 | return -EINVAL; |
| 7815 | } |
| 7816 | |
| 7817 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7818 | |
| 7819 | return 0; |
| 7820 | } |
| 7821 | |
| 7822 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7823 | struct intel_crtc_state *crtc_state) |
| 7824 | { |
| 7825 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7826 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7827 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7828 | int refclk = 96000; |
| 7829 | |
| 7830 | memset(&crtc_state->dpll_hw_state, 0, |
| 7831 | sizeof(crtc_state->dpll_hw_state)); |
| 7832 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7833 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7834 | if (intel_panel_use_ssc(dev_priv)) { |
| 7835 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7836 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7837 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7838 | |
| 7839 | limit = &intel_limits_i9xx_lvds; |
| 7840 | } else { |
| 7841 | limit = &intel_limits_i9xx_sdvo; |
| 7842 | } |
| 7843 | |
| 7844 | if (!crtc_state->clock_set && |
| 7845 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7846 | refclk, NULL, &crtc_state->dpll)) { |
| 7847 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7848 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7849 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7850 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7851 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7852 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7853 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7854 | } |
| 7855 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7856 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7857 | struct intel_crtc_state *crtc_state) |
| 7858 | { |
| 7859 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7860 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7861 | |
| 7862 | memset(&crtc_state->dpll_hw_state, 0, |
| 7863 | sizeof(crtc_state->dpll_hw_state)); |
| 7864 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7865 | if (!crtc_state->clock_set && |
| 7866 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7867 | refclk, NULL, &crtc_state->dpll)) { |
| 7868 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7869 | return -EINVAL; |
| 7870 | } |
| 7871 | |
| 7872 | chv_compute_dpll(crtc, crtc_state); |
| 7873 | |
| 7874 | return 0; |
| 7875 | } |
| 7876 | |
| 7877 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7878 | struct intel_crtc_state *crtc_state) |
| 7879 | { |
| 7880 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7881 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7882 | |
| 7883 | memset(&crtc_state->dpll_hw_state, 0, |
| 7884 | sizeof(crtc_state->dpll_hw_state)); |
| 7885 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7886 | if (!crtc_state->clock_set && |
| 7887 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7888 | refclk, NULL, &crtc_state->dpll)) { |
| 7889 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7890 | return -EINVAL; |
| 7891 | } |
| 7892 | |
| 7893 | vlv_compute_dpll(crtc, crtc_state); |
| 7894 | |
| 7895 | return 0; |
| 7896 | } |
| 7897 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7898 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7899 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7900 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7901 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7902 | u32 tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7903 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7904 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7905 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7906 | return; |
| 7907 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7908 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7909 | if (!(tmp & PFIT_ENABLE)) |
| 7910 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7911 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7912 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7913 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7914 | if (crtc->pipe != PIPE_B) |
| 7915 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7916 | } else { |
| 7917 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7918 | return; |
| 7919 | } |
| 7920 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7921 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7922 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7923 | } |
| 7924 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7925 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7926 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7927 | { |
| 7928 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7929 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7930 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7931 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7932 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7933 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7934 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7935 | /* In case of DSI, DPLL will not be used */ |
| 7936 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7937 | return; |
| 7938 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7939 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7940 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7941 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7942 | |
| 7943 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7944 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7945 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7946 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7947 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7948 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7949 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7950 | } |
| 7951 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7952 | static void |
| 7953 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7954 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7955 | { |
| 7956 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7957 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7958 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7959 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7960 | enum pipe pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7961 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7962 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7963 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7964 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7965 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7966 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7967 | if (!plane->get_hw_state(plane, &pipe)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7968 | return; |
| 7969 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7970 | WARN_ON(pipe != crtc->pipe); |
| 7971 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7972 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7973 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7974 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7975 | return; |
| 7976 | } |
| 7977 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7978 | fb = &intel_fb->base; |
| 7979 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7980 | fb->dev = dev; |
| 7981 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7982 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7983 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7984 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7985 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7986 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7987 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7988 | } |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7989 | |
| 7990 | if (val & DISPPLANE_ROTATE_180) |
| 7991 | plane_config->rotation = DRM_MODE_ROTATE_180; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7992 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7993 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7994 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B && |
| 7995 | val & DISPPLANE_MIRROR) |
| 7996 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 7997 | |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7998 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7999 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 8000 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8001 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 8002 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 8003 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 8004 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 8005 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8006 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8007 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8008 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8009 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 8010 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8011 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8012 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8013 | } |
| 8014 | plane_config->base = base; |
| 8015 | |
| 8016 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8017 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8018 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8019 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8020 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8021 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8022 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 8023 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8024 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8025 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8026 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8027 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8028 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 8029 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8030 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8031 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8032 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8033 | } |
| 8034 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8035 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8036 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8037 | { |
| 8038 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8039 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8040 | int pipe = pipe_config->cpu_transcoder; |
| 8041 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8042 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8043 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8044 | int refclk = 100000; |
| 8045 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 8046 | /* In case of DSI, DPLL will not be used */ |
| 8047 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 8048 | return; |
| 8049 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8050 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8051 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 8052 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 8053 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 8054 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8055 | 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] | 8056 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8057 | |
| 8058 | 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] | 8059 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 8060 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 8061 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8062 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 8063 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 8064 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 8065 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8066 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8067 | } |
| 8068 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8069 | static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc, |
| 8070 | struct intel_crtc_state *pipe_config) |
| 8071 | { |
| 8072 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8073 | enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB; |
| 8074 | |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 8075 | pipe_config->lspcon_downsampling = false; |
| 8076 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8077 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
| 8078 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 8079 | |
| 8080 | if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) { |
| 8081 | bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE; |
| 8082 | bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 8083 | |
| 8084 | if (ycbcr420_enabled) { |
| 8085 | /* We support 4:2:0 in full blend mode only */ |
| 8086 | if (!blend) |
| 8087 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 8088 | else if (!(IS_GEMINILAKE(dev_priv) || |
| 8089 | INTEL_GEN(dev_priv) >= 10)) |
| 8090 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 8091 | else |
| 8092 | output = INTEL_OUTPUT_FORMAT_YCBCR420; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8093 | } else { |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 8094 | /* |
| 8095 | * Currently there is no interface defined to |
| 8096 | * check user preference between RGB/YCBCR444 |
| 8097 | * or YCBCR420. So the only possible case for |
| 8098 | * YCBCR444 usage is driving YCBCR420 output |
| 8099 | * with LSPCON, when pipe is configured for |
| 8100 | * YCBCR444 output and LSPCON takes care of |
| 8101 | * downsampling it. |
| 8102 | */ |
| 8103 | pipe_config->lspcon_downsampling = true; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8104 | output = INTEL_OUTPUT_FORMAT_YCBCR444; |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8105 | } |
| 8106 | } |
| 8107 | } |
| 8108 | |
| 8109 | pipe_config->output_format = output; |
| 8110 | } |
| 8111 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 8112 | static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state) |
| 8113 | { |
| 8114 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8115 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 8116 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8117 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
| 8118 | u32 tmp; |
| 8119 | |
| 8120 | tmp = I915_READ(DSPCNTR(i9xx_plane)); |
| 8121 | |
| 8122 | if (tmp & DISPPLANE_GAMMA_ENABLE) |
| 8123 | crtc_state->gamma_enable = true; |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 8124 | |
| 8125 | if (!HAS_GMCH(dev_priv) && |
| 8126 | tmp & DISPPLANE_PIPE_CSC_ENABLE) |
| 8127 | crtc_state->csc_enable = true; |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 8128 | } |
| 8129 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8130 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8131 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8132 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8133 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8134 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8135 | intel_wakeref_t wakeref; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8136 | u32 tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8137 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8138 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8139 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8140 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 8141 | if (!wakeref) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8142 | return false; |
| 8143 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 8144 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8145 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8146 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8147 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8148 | ret = false; |
| 8149 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8150 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8151 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8152 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8153 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 8154 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 8155 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8156 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8157 | case PIPECONF_6BPC: |
| 8158 | pipe_config->pipe_bpp = 18; |
| 8159 | break; |
| 8160 | case PIPECONF_8BPC: |
| 8161 | pipe_config->pipe_bpp = 24; |
| 8162 | break; |
| 8163 | case PIPECONF_10BPC: |
| 8164 | pipe_config->pipe_bpp = 30; |
| 8165 | break; |
| 8166 | default: |
| 8167 | break; |
| 8168 | } |
| 8169 | } |
| 8170 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8171 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8172 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8173 | pipe_config->limited_color_range = true; |
| 8174 | |
Ville Syrjälä | 9d5441d | 2019-02-07 22:21:40 +0200 | [diff] [blame] | 8175 | pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >> |
| 8176 | PIPECONF_GAMMA_MODE_SHIFT; |
| 8177 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 8178 | i9xx_get_pipe_color_config(pipe_config); |
| 8179 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8180 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8181 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8182 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8183 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8184 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8185 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8186 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8187 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8188 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8189 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8190 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8191 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8192 | else |
| 8193 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8194 | pipe_config->pixel_multiplier = |
| 8195 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8196 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8197 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8198 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 8199 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8200 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8201 | pipe_config->pixel_multiplier = |
| 8202 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8203 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8204 | } else { |
| 8205 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8206 | * port and will be fixed up in the encoder->get_config |
| 8207 | * function. */ |
| 8208 | pipe_config->pixel_multiplier = 1; |
| 8209 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8210 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8211 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8212 | /* |
| 8213 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8214 | * on 830. Filter it out here so that we don't |
| 8215 | * report errors due to that. |
| 8216 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8217 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8218 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8219 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8220 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8221 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8222 | } else { |
| 8223 | /* Mask out read-only status bits. */ |
| 8224 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8225 | DPLL_PORTC_READY_MASK | |
| 8226 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8227 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8228 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8229 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8230 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 8231 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8232 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8233 | else |
| 8234 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8235 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8236 | /* |
| 8237 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8238 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8239 | * default. |
| 8240 | */ |
| 8241 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8242 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8243 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8244 | ret = true; |
| 8245 | |
| 8246 | out: |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8247 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8248 | |
| 8249 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8250 | } |
| 8251 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8252 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8253 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8254 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8255 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8256 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8257 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8258 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8259 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8260 | bool has_ck505 = false; |
| 8261 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8262 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8263 | |
| 8264 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8265 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8266 | switch (encoder->type) { |
| 8267 | case INTEL_OUTPUT_LVDS: |
| 8268 | has_panel = true; |
| 8269 | has_lvds = true; |
| 8270 | break; |
| 8271 | case INTEL_OUTPUT_EDP: |
| 8272 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 8273 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8274 | has_cpu_edp = true; |
| 8275 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8276 | default: |
| 8277 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8278 | } |
| 8279 | } |
| 8280 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8281 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8282 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8283 | can_ssc = has_ck505; |
| 8284 | } else { |
| 8285 | has_ck505 = false; |
| 8286 | can_ssc = true; |
| 8287 | } |
| 8288 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8289 | /* Check if any DPLLs are using the SSC source */ |
| 8290 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8291 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8292 | |
| 8293 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8294 | continue; |
| 8295 | |
| 8296 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8297 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8298 | using_ssc_source = true; |
| 8299 | break; |
| 8300 | } |
| 8301 | } |
| 8302 | |
| 8303 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8304 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8305 | |
| 8306 | /* Ironlake: try to setup display ref clock before DPLL |
| 8307 | * enabling. This is only under driver's control after |
| 8308 | * PCH B stepping, previous chipset stepping should be |
| 8309 | * ignoring this setting. |
| 8310 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8311 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8312 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8313 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8314 | * compute the final state we want first and check if we need to |
| 8315 | * make any changes at all. |
| 8316 | */ |
| 8317 | final = val; |
| 8318 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8319 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8320 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8321 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8322 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8323 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8324 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8325 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8326 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8327 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8328 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8329 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8330 | |
| 8331 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8332 | final |= DREF_SSC1_ENABLE; |
| 8333 | |
| 8334 | if (has_cpu_edp) { |
| 8335 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8336 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8337 | else |
| 8338 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8339 | } else |
| 8340 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8341 | } else if (using_ssc_source) { |
| 8342 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8343 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8344 | } |
| 8345 | |
| 8346 | if (final == val) |
| 8347 | return; |
| 8348 | |
| 8349 | /* Always enable nonspread source */ |
| 8350 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8351 | |
| 8352 | if (has_ck505) |
| 8353 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8354 | else |
| 8355 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8356 | |
| 8357 | if (has_panel) { |
| 8358 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8359 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8360 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8361 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8362 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8363 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8364 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8365 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8366 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8367 | |
| 8368 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8369 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8370 | POSTING_READ(PCH_DREF_CONTROL); |
| 8371 | udelay(200); |
| 8372 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8373 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8374 | |
| 8375 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8376 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8377 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8378 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8379 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8380 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8381 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8382 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8383 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8384 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8385 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8386 | POSTING_READ(PCH_DREF_CONTROL); |
| 8387 | udelay(200); |
| 8388 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8389 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8390 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8391 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8392 | |
| 8393 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8394 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8395 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8396 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8397 | POSTING_READ(PCH_DREF_CONTROL); |
| 8398 | udelay(200); |
| 8399 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8400 | if (!using_ssc_source) { |
| 8401 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8402 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8403 | /* Turn off the SSC source */ |
| 8404 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8405 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8406 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8407 | /* Turn off SSC1 */ |
| 8408 | val &= ~DREF_SSC1_ENABLE; |
| 8409 | |
| 8410 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8411 | POSTING_READ(PCH_DREF_CONTROL); |
| 8412 | udelay(200); |
| 8413 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8414 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8415 | |
| 8416 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8417 | } |
| 8418 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8419 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8420 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8421 | u32 tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8422 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8423 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8424 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8425 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8426 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8427 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8428 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8429 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8430 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8431 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8432 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8433 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8434 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8435 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8436 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8437 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8438 | } |
| 8439 | |
| 8440 | /* WaMPhyProgramming:hsw */ |
| 8441 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8442 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8443 | u32 tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8444 | |
| 8445 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8446 | tmp &= ~(0xFF << 24); |
| 8447 | tmp |= (0x12 << 24); |
| 8448 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8449 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8450 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8451 | tmp |= (1 << 11); |
| 8452 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8453 | |
| 8454 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8455 | tmp |= (1 << 11); |
| 8456 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8457 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8458 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8459 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8460 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8461 | |
| 8462 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8463 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8464 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8465 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8466 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8467 | tmp &= ~(7 << 13); |
| 8468 | tmp |= (5 << 13); |
| 8469 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8470 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8471 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8472 | tmp &= ~(7 << 13); |
| 8473 | tmp |= (5 << 13); |
| 8474 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8475 | |
| 8476 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8477 | tmp &= ~0xFF; |
| 8478 | tmp |= 0x1C; |
| 8479 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8480 | |
| 8481 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8482 | tmp &= ~0xFF; |
| 8483 | tmp |= 0x1C; |
| 8484 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8485 | |
| 8486 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8487 | tmp &= ~(0xFF << 16); |
| 8488 | tmp |= (0x1C << 16); |
| 8489 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8490 | |
| 8491 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8492 | tmp &= ~(0xFF << 16); |
| 8493 | tmp |= (0x1C << 16); |
| 8494 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8495 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8496 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8497 | tmp |= (1 << 27); |
| 8498 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8499 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8500 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8501 | tmp |= (1 << 27); |
| 8502 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8503 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8504 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8505 | tmp &= ~(0xF << 28); |
| 8506 | tmp |= (4 << 28); |
| 8507 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8508 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8509 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8510 | tmp &= ~(0xF << 28); |
| 8511 | tmp |= (4 << 28); |
| 8512 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8513 | } |
| 8514 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8515 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8516 | * Programming" based on the parameters passed: |
| 8517 | * - Sequence to enable CLKOUT_DP |
| 8518 | * - Sequence to enable CLKOUT_DP without spread |
| 8519 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8520 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8521 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8522 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8523 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8524 | u32 reg, tmp; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8525 | |
| 8526 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8527 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8528 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8529 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8530 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8531 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8532 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8533 | |
| 8534 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8535 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8536 | tmp |= SBI_SSCCTL_PATHALT; |
| 8537 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8538 | |
| 8539 | udelay(24); |
| 8540 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8541 | if (with_spread) { |
| 8542 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8543 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8544 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8545 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8546 | if (with_fdi) { |
| 8547 | lpt_reset_fdi_mphy(dev_priv); |
| 8548 | lpt_program_fdi_mphy(dev_priv); |
| 8549 | } |
| 8550 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8551 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8552 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8553 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8554 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8555 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8556 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8557 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8558 | } |
| 8559 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8560 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8561 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8562 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8563 | u32 reg, tmp; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8564 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8565 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8566 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8567 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8568 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8569 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8570 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8571 | |
| 8572 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8573 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8574 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8575 | tmp |= SBI_SSCCTL_PATHALT; |
| 8576 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8577 | udelay(32); |
| 8578 | } |
| 8579 | tmp |= SBI_SSCCTL_DISABLE; |
| 8580 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8581 | } |
| 8582 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8583 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8584 | } |
| 8585 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8586 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8587 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8588 | static const u16 sscdivintphase[] = { |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8589 | [BEND_IDX( 50)] = 0x3B23, |
| 8590 | [BEND_IDX( 45)] = 0x3B23, |
| 8591 | [BEND_IDX( 40)] = 0x3C23, |
| 8592 | [BEND_IDX( 35)] = 0x3C23, |
| 8593 | [BEND_IDX( 30)] = 0x3D23, |
| 8594 | [BEND_IDX( 25)] = 0x3D23, |
| 8595 | [BEND_IDX( 20)] = 0x3E23, |
| 8596 | [BEND_IDX( 15)] = 0x3E23, |
| 8597 | [BEND_IDX( 10)] = 0x3F23, |
| 8598 | [BEND_IDX( 5)] = 0x3F23, |
| 8599 | [BEND_IDX( 0)] = 0x0025, |
| 8600 | [BEND_IDX( -5)] = 0x0025, |
| 8601 | [BEND_IDX(-10)] = 0x0125, |
| 8602 | [BEND_IDX(-15)] = 0x0125, |
| 8603 | [BEND_IDX(-20)] = 0x0225, |
| 8604 | [BEND_IDX(-25)] = 0x0225, |
| 8605 | [BEND_IDX(-30)] = 0x0325, |
| 8606 | [BEND_IDX(-35)] = 0x0325, |
| 8607 | [BEND_IDX(-40)] = 0x0425, |
| 8608 | [BEND_IDX(-45)] = 0x0425, |
| 8609 | [BEND_IDX(-50)] = 0x0525, |
| 8610 | }; |
| 8611 | |
| 8612 | /* |
| 8613 | * Bend CLKOUT_DP |
| 8614 | * steps -50 to 50 inclusive, in steps of 5 |
| 8615 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8616 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8617 | */ |
| 8618 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8619 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8620 | u32 tmp; |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8621 | int idx = BEND_IDX(steps); |
| 8622 | |
| 8623 | if (WARN_ON(steps % 5 != 0)) |
| 8624 | return; |
| 8625 | |
| 8626 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8627 | return; |
| 8628 | |
| 8629 | mutex_lock(&dev_priv->sb_lock); |
| 8630 | |
| 8631 | if (steps % 10 != 0) |
| 8632 | tmp = 0xAAAAAAAB; |
| 8633 | else |
| 8634 | tmp = 0x00000000; |
| 8635 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8636 | |
| 8637 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8638 | tmp &= 0xffff0000; |
| 8639 | tmp |= sscdivintphase[idx]; |
| 8640 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8641 | |
| 8642 | mutex_unlock(&dev_priv->sb_lock); |
| 8643 | } |
| 8644 | |
| 8645 | #undef BEND_IDX |
| 8646 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8647 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8648 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8649 | struct intel_encoder *encoder; |
| 8650 | bool has_vga = false; |
| 8651 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8652 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8653 | switch (encoder->type) { |
| 8654 | case INTEL_OUTPUT_ANALOG: |
| 8655 | has_vga = true; |
| 8656 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8657 | default: |
| 8658 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8659 | } |
| 8660 | } |
| 8661 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8662 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8663 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8664 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8665 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8666 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8667 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8668 | } |
| 8669 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8670 | /* |
| 8671 | * Initialize reference clocks when the driver loads |
| 8672 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8673 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8674 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8675 | 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] | 8676 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8677 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8678 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8679 | } |
| 8680 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8681 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8682 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8683 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8684 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8685 | enum pipe pipe = crtc->pipe; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8686 | u32 val; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8687 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8688 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8689 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8690 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8691 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8692 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8693 | break; |
| 8694 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8695 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8696 | break; |
| 8697 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8698 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8699 | break; |
| 8700 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8701 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8702 | break; |
| 8703 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8704 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8705 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8706 | } |
| 8707 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8708 | if (crtc_state->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8709 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8710 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8711 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8712 | val |= PIPECONF_INTERLACED_ILK; |
| 8713 | else |
| 8714 | val |= PIPECONF_PROGRESSIVE; |
| 8715 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8716 | if (crtc_state->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8717 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8718 | |
Ville Syrjälä | 9d5441d | 2019-02-07 22:21:40 +0200 | [diff] [blame] | 8719 | val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode); |
| 8720 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8721 | I915_WRITE(PIPECONF(pipe), val); |
| 8722 | POSTING_READ(PIPECONF(pipe)); |
| 8723 | } |
| 8724 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8725 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8726 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8727 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8728 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8729 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8730 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8731 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8732 | if (IS_HASWELL(dev_priv) && crtc_state->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8733 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8734 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8735 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8736 | val |= PIPECONF_INTERLACED_ILK; |
| 8737 | else |
| 8738 | val |= PIPECONF_PROGRESSIVE; |
| 8739 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8740 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8741 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8742 | } |
| 8743 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8744 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state) |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8745 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8746 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8747 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8748 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8749 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8750 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8751 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8752 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8753 | case 18: |
| 8754 | val |= PIPEMISC_DITHER_6_BPC; |
| 8755 | break; |
| 8756 | case 24: |
| 8757 | val |= PIPEMISC_DITHER_8_BPC; |
| 8758 | break; |
| 8759 | case 30: |
| 8760 | val |= PIPEMISC_DITHER_10_BPC; |
| 8761 | break; |
| 8762 | case 36: |
| 8763 | val |= PIPEMISC_DITHER_12_BPC; |
| 8764 | break; |
| 8765 | default: |
| 8766 | /* Case prevented by pipe_config_set_bpp. */ |
| 8767 | BUG(); |
| 8768 | } |
| 8769 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8770 | if (crtc_state->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8771 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8772 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8773 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 8774 | crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8775 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8776 | |
| 8777 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8778 | val |= PIPEMISC_YUV420_ENABLE | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8779 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8780 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8781 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8782 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8783 | } |
| 8784 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8785 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8786 | { |
| 8787 | /* |
| 8788 | * Account for spread spectrum to avoid |
| 8789 | * oversubscribing the link. Max center spread |
| 8790 | * is 2.5%; use 5% for safety's sake. |
| 8791 | */ |
| 8792 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8793 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8794 | } |
| 8795 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8796 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8797 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8798 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8799 | } |
| 8800 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8801 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8802 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8803 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8804 | { |
| 8805 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8806 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8807 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8808 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8809 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8810 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8811 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8812 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8813 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8814 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8815 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8816 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8817 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8818 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8819 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8820 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8821 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8822 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8823 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8824 | fp |= FP_CB_TUNE; |
| 8825 | |
| 8826 | if (reduced_clock) { |
| 8827 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8828 | |
| 8829 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8830 | fp2 |= FP_CB_TUNE; |
| 8831 | } else { |
| 8832 | fp2 = fp; |
| 8833 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8834 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8835 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8836 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8837 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8838 | dpll |= DPLLB_MODE_LVDS; |
| 8839 | else |
| 8840 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8841 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8842 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8843 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8844 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8845 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8846 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8847 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8848 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8849 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8850 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8851 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8852 | /* |
| 8853 | * The high speed IO clock is only really required for |
| 8854 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8855 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8856 | * the clock needlessly does no real harm, except use up a |
| 8857 | * bit of power potentially. |
| 8858 | * |
| 8859 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8860 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8861 | * driving PCH ports at the same time. On SNB we could do this, |
| 8862 | * and potentially avoid enabling the second DPLL, but it's not |
| 8863 | * clear if it''s a win or loss power wise. No point in doing |
| 8864 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8865 | */ |
| 8866 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8867 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8868 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8869 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8870 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8871 | 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] | 8872 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8873 | 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] | 8874 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8875 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8876 | case 5: |
| 8877 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8878 | break; |
| 8879 | case 7: |
| 8880 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8881 | break; |
| 8882 | case 10: |
| 8883 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8884 | break; |
| 8885 | case 14: |
| 8886 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8887 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8888 | } |
| 8889 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8890 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8891 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8892 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8893 | else |
| 8894 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8895 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8896 | dpll |= DPLL_VCO_ENABLE; |
| 8897 | |
| 8898 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8899 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8900 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8901 | } |
| 8902 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8903 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8904 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8905 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8906 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8907 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8908 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8909 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8910 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8911 | memset(&crtc_state->dpll_hw_state, 0, |
| 8912 | sizeof(crtc_state->dpll_hw_state)); |
| 8913 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8914 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8915 | if (!crtc_state->has_pch_encoder) |
| 8916 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8917 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8918 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8919 | if (intel_panel_use_ssc(dev_priv)) { |
| 8920 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8921 | dev_priv->vbt.lvds_ssc_freq); |
| 8922 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8923 | } |
| 8924 | |
| 8925 | if (intel_is_dual_link_lvds(dev)) { |
| 8926 | if (refclk == 100000) |
| 8927 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8928 | else |
| 8929 | limit = &intel_limits_ironlake_dual_lvds; |
| 8930 | } else { |
| 8931 | if (refclk == 100000) |
| 8932 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8933 | else |
| 8934 | limit = &intel_limits_ironlake_single_lvds; |
| 8935 | } |
| 8936 | } else { |
| 8937 | limit = &intel_limits_ironlake_dac; |
| 8938 | } |
| 8939 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8940 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8941 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8942 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8943 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8944 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8945 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8946 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8947 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8948 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8949 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 8950 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 8951 | pipe_name(crtc->pipe)); |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8952 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8953 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8954 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8955 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8956 | } |
| 8957 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8958 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8959 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8960 | { |
| 8961 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8962 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8963 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8964 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8965 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8966 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8967 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8968 | & ~TU_SIZE_MASK; |
| 8969 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8970 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8971 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8972 | } |
| 8973 | |
| 8974 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8975 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8976 | struct intel_link_m_n *m_n, |
| 8977 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8978 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8979 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8980 | enum pipe pipe = crtc->pipe; |
| 8981 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8982 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8983 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8984 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8985 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8986 | & ~TU_SIZE_MASK; |
| 8987 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8988 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8989 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 8990 | |
| 8991 | if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8992 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8993 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8994 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8995 | & ~TU_SIZE_MASK; |
| 8996 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8997 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8998 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8999 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9000 | } else { |
| 9001 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 9002 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 9003 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 9004 | & ~TU_SIZE_MASK; |
| 9005 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 9006 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 9007 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9008 | } |
| 9009 | } |
| 9010 | |
| 9011 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9012 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9013 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 9014 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9015 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 9016 | else |
| 9017 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9018 | &pipe_config->dp_m_n, |
| 9019 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9020 | } |
| 9021 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9022 | 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] | 9023 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9024 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9025 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9026 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9027 | } |
| 9028 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9029 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9030 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9031 | { |
| 9032 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9033 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9034 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9035 | u32 ps_ctrl = 0; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9036 | int id = -1; |
| 9037 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9038 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9039 | /* find scaler attached to this pipe */ |
| 9040 | for (i = 0; i < crtc->num_scalers; i++) { |
| 9041 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 9042 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 9043 | id = i; |
| 9044 | pipe_config->pch_pfit.enabled = true; |
| 9045 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 9046 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
Maarten Lankhorst | 0cdc1d0 | 2019-01-08 17:08:41 +0100 | [diff] [blame] | 9047 | scaler_state->scalers[i].in_use = true; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9048 | break; |
| 9049 | } |
| 9050 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9051 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9052 | scaler_state->scaler_id = id; |
| 9053 | if (id >= 0) { |
| 9054 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 9055 | } else { |
| 9056 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9057 | } |
| 9058 | } |
| 9059 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9060 | static void |
| 9061 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9062 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9063 | { |
| 9064 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9065 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9066 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 9067 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9068 | enum pipe pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9069 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9070 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9071 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9072 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9073 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9074 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9075 | if (!plane->get_hw_state(plane, &pipe)) |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 9076 | return; |
| 9077 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 9078 | WARN_ON(pipe != crtc->pipe); |
| 9079 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9080 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9081 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9082 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9083 | return; |
| 9084 | } |
| 9085 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9086 | fb = &intel_fb->base; |
| 9087 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 9088 | fb->dev = dev; |
| 9089 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9090 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9091 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 9092 | if (INTEL_GEN(dev_priv) >= 11) |
| 9093 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 9094 | else |
| 9095 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9096 | |
| 9097 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9098 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9099 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 9100 | } else { |
| 9101 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 9102 | } |
| 9103 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9104 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 9105 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 9106 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9107 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9108 | tiling = val & PLANE_CTL_TILED_MASK; |
| 9109 | switch (tiling) { |
| 9110 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 9111 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9112 | break; |
| 9113 | case PLANE_CTL_TILED_X: |
| 9114 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9115 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9116 | break; |
| 9117 | case PLANE_CTL_TILED_Y: |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 9118 | plane_config->tiling = I915_TILING_Y; |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 9119 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 9120 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 9121 | else |
| 9122 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9123 | break; |
| 9124 | case PLANE_CTL_TILED_YF: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 9125 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 9126 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 9127 | else |
| 9128 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9129 | break; |
| 9130 | default: |
| 9131 | MISSING_CASE(tiling); |
| 9132 | goto error; |
| 9133 | } |
| 9134 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 9135 | /* |
| 9136 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 9137 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 9138 | */ |
| 9139 | switch (val & PLANE_CTL_ROTATE_MASK) { |
| 9140 | case PLANE_CTL_ROTATE_0: |
| 9141 | plane_config->rotation = DRM_MODE_ROTATE_0; |
| 9142 | break; |
| 9143 | case PLANE_CTL_ROTATE_90: |
| 9144 | plane_config->rotation = DRM_MODE_ROTATE_270; |
| 9145 | break; |
| 9146 | case PLANE_CTL_ROTATE_180: |
| 9147 | plane_config->rotation = DRM_MODE_ROTATE_180; |
| 9148 | break; |
| 9149 | case PLANE_CTL_ROTATE_270: |
| 9150 | plane_config->rotation = DRM_MODE_ROTATE_90; |
| 9151 | break; |
| 9152 | } |
| 9153 | |
| 9154 | if (INTEL_GEN(dev_priv) >= 10 && |
| 9155 | val & PLANE_CTL_FLIP_HORIZONTAL) |
| 9156 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 9157 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9158 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9159 | plane_config->base = base; |
| 9160 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9161 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9162 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9163 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9164 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 9165 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 9166 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9167 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 9168 | stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9169 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9170 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 9171 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9172 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9173 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9174 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9175 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9176 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 9177 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9178 | plane_config->size); |
| 9179 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9180 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9181 | return; |
| 9182 | |
| 9183 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 9184 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9185 | } |
| 9186 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9187 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9188 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9189 | { |
| 9190 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9191 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9192 | u32 tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9193 | |
| 9194 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9195 | |
| 9196 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9197 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9198 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9199 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9200 | |
| 9201 | /* We currently do not free assignements of panel fitters on |
| 9202 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9203 | * differentiates them) so just WARN about this case for now. */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9204 | if (IS_GEN(dev_priv, 7)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9205 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9206 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9207 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9208 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9209 | } |
| 9210 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9211 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9212 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9213 | { |
| 9214 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9215 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9216 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9217 | intel_wakeref_t wakeref; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9218 | u32 tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9219 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9220 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9221 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9222 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 9223 | if (!wakeref) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9224 | return false; |
| 9225 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 9226 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9227 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9228 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9229 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9230 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9231 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9232 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9233 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9234 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9235 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9236 | case PIPECONF_6BPC: |
| 9237 | pipe_config->pipe_bpp = 18; |
| 9238 | break; |
| 9239 | case PIPECONF_8BPC: |
| 9240 | pipe_config->pipe_bpp = 24; |
| 9241 | break; |
| 9242 | case PIPECONF_10BPC: |
| 9243 | pipe_config->pipe_bpp = 30; |
| 9244 | break; |
| 9245 | case PIPECONF_12BPC: |
| 9246 | pipe_config->pipe_bpp = 36; |
| 9247 | break; |
| 9248 | default: |
| 9249 | break; |
| 9250 | } |
| 9251 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9252 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9253 | pipe_config->limited_color_range = true; |
| 9254 | |
Ville Syrjälä | 9d5441d | 2019-02-07 22:21:40 +0200 | [diff] [blame] | 9255 | pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >> |
| 9256 | PIPECONF_GAMMA_MODE_SHIFT; |
| 9257 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 9258 | i9xx_get_pipe_color_config(pipe_config); |
| 9259 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9260 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9261 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9262 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9263 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9264 | pipe_config->has_pch_encoder = true; |
| 9265 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9266 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9267 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9268 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9269 | |
| 9270 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9271 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9272 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9273 | /* |
| 9274 | * The pipe->pch transcoder and pch transcoder->pll |
| 9275 | * mapping is fixed. |
| 9276 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9277 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9278 | } else { |
| 9279 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9280 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9281 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9282 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9283 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9284 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9285 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9286 | pipe_config->shared_dpll = |
| 9287 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9288 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9289 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9290 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9291 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9292 | |
| 9293 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9294 | pipe_config->pixel_multiplier = |
| 9295 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9296 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9297 | |
| 9298 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9299 | } else { |
| 9300 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9301 | } |
| 9302 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9303 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9304 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9305 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9306 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9307 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9308 | ret = true; |
| 9309 | |
| 9310 | out: |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9311 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9312 | |
| 9313 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9314 | } |
| 9315 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9316 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9317 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 9318 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9319 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9320 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9321 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9322 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9323 | pipe_name(crtc->pipe)); |
| 9324 | |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 9325 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2), |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 9326 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9327 | 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] | 9328 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9329 | 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] | 9330 | 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] | 9331 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9332 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9333 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9334 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9335 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9336 | 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] | 9337 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9338 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9339 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9340 | 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] | 9341 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9342 | /* |
| 9343 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9344 | * interrupts remain enabled. We used to check for that, but since it's |
| 9345 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9346 | * the interrupts, the check below should be enough. |
| 9347 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9348 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9349 | } |
| 9350 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9351 | static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9352 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9353 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9354 | return I915_READ(D_COMP_HSW); |
| 9355 | else |
| 9356 | return I915_READ(D_COMP_BDW); |
| 9357 | } |
| 9358 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9359 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val) |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9360 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9361 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9362 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9363 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9364 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 9365 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9366 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9367 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9368 | I915_WRITE(D_COMP_BDW, val); |
| 9369 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9370 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9371 | } |
| 9372 | |
| 9373 | /* |
| 9374 | * This function implements pieces of two sequences from BSpec: |
| 9375 | * - Sequence for display software to disable LCPLL |
| 9376 | * - Sequence for display software to allow package C8+ |
| 9377 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9378 | * register. Callers should take care of disabling all the display engine |
| 9379 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9380 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9381 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9382 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9383 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9384 | u32 val; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9385 | |
| 9386 | assert_can_disable_lcpll(dev_priv); |
| 9387 | |
| 9388 | val = I915_READ(LCPLL_CTL); |
| 9389 | |
| 9390 | if (switch_to_fclk) { |
| 9391 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9392 | I915_WRITE(LCPLL_CTL, val); |
| 9393 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9394 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9395 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9396 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9397 | |
| 9398 | val = I915_READ(LCPLL_CTL); |
| 9399 | } |
| 9400 | |
| 9401 | val |= LCPLL_PLL_DISABLE; |
| 9402 | I915_WRITE(LCPLL_CTL, val); |
| 9403 | POSTING_READ(LCPLL_CTL); |
| 9404 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 9405 | 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] | 9406 | DRM_ERROR("LCPLL still locked\n"); |
| 9407 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9408 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9409 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9410 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9411 | ndelay(100); |
| 9412 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9413 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9414 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9415 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9416 | |
| 9417 | if (allow_power_down) { |
| 9418 | val = I915_READ(LCPLL_CTL); |
| 9419 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9420 | I915_WRITE(LCPLL_CTL, val); |
| 9421 | POSTING_READ(LCPLL_CTL); |
| 9422 | } |
| 9423 | } |
| 9424 | |
| 9425 | /* |
| 9426 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9427 | * source. |
| 9428 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9429 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9430 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9431 | u32 val; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9432 | |
| 9433 | val = I915_READ(LCPLL_CTL); |
| 9434 | |
| 9435 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9436 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9437 | return; |
| 9438 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9439 | /* |
| 9440 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9441 | * 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] | 9442 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9443 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9444 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9445 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9446 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9447 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9448 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9449 | } |
| 9450 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9451 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9452 | val |= D_COMP_COMP_FORCE; |
| 9453 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9454 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9455 | |
| 9456 | val = I915_READ(LCPLL_CTL); |
| 9457 | val &= ~LCPLL_PLL_DISABLE; |
| 9458 | I915_WRITE(LCPLL_CTL, val); |
| 9459 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9460 | if (intel_wait_for_register(dev_priv, |
| 9461 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9462 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9463 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9464 | |
| 9465 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9466 | val = I915_READ(LCPLL_CTL); |
| 9467 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9468 | I915_WRITE(LCPLL_CTL, val); |
| 9469 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9470 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9471 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9472 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9473 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9474 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9475 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9476 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9477 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9478 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9479 | } |
| 9480 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9481 | /* |
| 9482 | * Package states C8 and deeper are really deep PC states that can only be |
| 9483 | * reached when all the devices on the system allow it, so even if the graphics |
| 9484 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9485 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9486 | * |
| 9487 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9488 | * well is disabled and most interrupts are disabled, and these are also |
| 9489 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9490 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9491 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9492 | * hang the machine. |
| 9493 | * |
| 9494 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9495 | * the state of some registers, so when we come back from PC8+ we need to |
| 9496 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9497 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9498 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9499 | * because of the runtime PM support). |
| 9500 | * |
| 9501 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9502 | * documentation. |
| 9503 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9504 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9505 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9506 | u32 val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9507 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9508 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9509 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9510 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9511 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9512 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9513 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9514 | } |
| 9515 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9516 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9517 | hsw_disable_lcpll(dev_priv, true, true); |
| 9518 | } |
| 9519 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9520 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9521 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9522 | u32 val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9523 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9524 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9525 | |
| 9526 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9527 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9528 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9529 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9530 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9531 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9532 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9533 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9534 | } |
| 9535 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9536 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9537 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9538 | { |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9539 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9540 | struct intel_atomic_state *state = |
| 9541 | to_intel_atomic_state(crtc_state->base.state); |
| 9542 | |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9543 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) || |
| 9544 | IS_ICELAKE(dev_priv)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9545 | struct intel_encoder *encoder = |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9546 | intel_get_crtc_new_encoder(state, crtc_state); |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9547 | |
| 9548 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 9549 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 9550 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9551 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9552 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9553 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9554 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9555 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9556 | } |
| 9557 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9558 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9559 | enum port port, |
| 9560 | struct intel_crtc_state *pipe_config) |
| 9561 | { |
| 9562 | enum intel_dpll_id id; |
| 9563 | u32 temp; |
| 9564 | |
| 9565 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9566 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9567 | |
| 9568 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9569 | return; |
| 9570 | |
| 9571 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9572 | } |
| 9573 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9574 | static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9575 | enum port port, |
| 9576 | struct intel_crtc_state *pipe_config) |
| 9577 | { |
| 9578 | enum intel_dpll_id id; |
| 9579 | u32 temp; |
| 9580 | |
| 9581 | /* TODO: TBT pll not implemented. */ |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9582 | if (intel_port_is_combophy(dev_priv, port)) { |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9583 | temp = I915_READ(DPCLKA_CFGCR0_ICL) & |
| 9584 | DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
| 9585 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
| 9586 | |
Vandita Kulkarni | a54270d | 2018-10-03 12:52:00 +0530 | [diff] [blame] | 9587 | if (WARN_ON(!intel_dpll_is_combophy(id))) |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9588 | return; |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9589 | } else if (intel_port_is_tc(dev_priv, port)) { |
Lucas De Marchi | 584fca1 | 2019-01-25 14:24:41 -0800 | [diff] [blame] | 9590 | id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv, port)); |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9591 | } else { |
| 9592 | WARN(1, "Invalid port %x\n", port); |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9593 | return; |
| 9594 | } |
| 9595 | |
| 9596 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9597 | } |
| 9598 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9599 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9600 | enum port port, |
| 9601 | struct intel_crtc_state *pipe_config) |
| 9602 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9603 | enum intel_dpll_id id; |
| 9604 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9605 | switch (port) { |
| 9606 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9607 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9608 | break; |
| 9609 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9610 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9611 | break; |
| 9612 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9613 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9614 | break; |
| 9615 | default: |
| 9616 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9617 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9618 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9619 | |
| 9620 | 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] | 9621 | } |
| 9622 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9623 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9624 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9625 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9626 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9627 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9628 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9629 | |
| 9630 | 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] | 9631 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9632 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9633 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9634 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9635 | |
| 9636 | 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] | 9637 | } |
| 9638 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9639 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9640 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9641 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9642 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9643 | enum intel_dpll_id id; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9644 | u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9645 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9646 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9647 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9648 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9649 | break; |
| 9650 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9651 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9652 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9653 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9654 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9655 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9656 | case PORT_CLK_SEL_LCPLL_810: |
| 9657 | id = DPLL_ID_LCPLL_810; |
| 9658 | break; |
| 9659 | case PORT_CLK_SEL_LCPLL_1350: |
| 9660 | id = DPLL_ID_LCPLL_1350; |
| 9661 | break; |
| 9662 | case PORT_CLK_SEL_LCPLL_2700: |
| 9663 | id = DPLL_ID_LCPLL_2700; |
| 9664 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9665 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9666 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9667 | /* fall through */ |
| 9668 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9669 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9670 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9671 | |
| 9672 | 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] | 9673 | } |
| 9674 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9675 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9676 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9677 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9678 | { |
| 9679 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9680 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9681 | enum intel_display_power_domain power_domain; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9682 | unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP); |
| 9683 | unsigned long enabled_panel_transcoders = 0; |
| 9684 | enum transcoder panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9685 | u32 tmp; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9686 | |
| 9687 | if (IS_ICELAKE(dev_priv)) |
| 9688 | panel_transcoder_mask |= |
| 9689 | BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9690 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9691 | /* |
| 9692 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9693 | * and DSI transcoders handled below. |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9694 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9695 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9696 | |
| 9697 | /* |
| 9698 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9699 | * consistency and less surprising code; it's in always on power). |
| 9700 | */ |
Chris Wilson | 1b4bd5c | 2019-01-16 15:54:21 +0000 | [diff] [blame] | 9701 | for_each_set_bit(panel_transcoder, |
| 9702 | &panel_transcoder_mask, |
| 9703 | ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) { |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9704 | enum pipe trans_pipe; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9705 | |
| 9706 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder)); |
| 9707 | if (!(tmp & TRANS_DDI_FUNC_ENABLE)) |
| 9708 | continue; |
| 9709 | |
| 9710 | /* |
| 9711 | * Log all enabled ones, only use the first one. |
| 9712 | * |
| 9713 | * FIXME: This won't work for two separate DSI displays. |
| 9714 | */ |
| 9715 | enabled_panel_transcoders |= BIT(panel_transcoder); |
| 9716 | if (enabled_panel_transcoders != BIT(panel_transcoder)) |
| 9717 | continue; |
| 9718 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9719 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9720 | default: |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9721 | WARN(1, "unknown pipe linked to transcoder %s\n", |
| 9722 | transcoder_name(panel_transcoder)); |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 9723 | /* fall through */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9724 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9725 | case TRANS_DDI_EDP_INPUT_A_ON: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9726 | trans_pipe = PIPE_A; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9727 | break; |
| 9728 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9729 | trans_pipe = PIPE_B; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9730 | break; |
| 9731 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9732 | trans_pipe = PIPE_C; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9733 | break; |
| 9734 | } |
| 9735 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9736 | if (trans_pipe == crtc->pipe) |
| 9737 | pipe_config->cpu_transcoder = panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9738 | } |
| 9739 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9740 | /* |
| 9741 | * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1 |
| 9742 | */ |
| 9743 | WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) && |
| 9744 | enabled_panel_transcoders != BIT(TRANSCODER_EDP)); |
| 9745 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9746 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9747 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9748 | return false; |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9749 | |
| 9750 | WARN_ON(*power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9751 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9752 | |
| 9753 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9754 | |
| 9755 | return tmp & PIPECONF_ENABLE; |
| 9756 | } |
| 9757 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9758 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9759 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9760 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9761 | { |
| 9762 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9763 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9764 | enum intel_display_power_domain power_domain; |
| 9765 | enum port port; |
| 9766 | enum transcoder cpu_transcoder; |
| 9767 | u32 tmp; |
| 9768 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9769 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9770 | if (port == PORT_A) |
| 9771 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9772 | else |
| 9773 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9774 | |
| 9775 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9776 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9777 | continue; |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9778 | |
| 9779 | WARN_ON(*power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9780 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9781 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9782 | /* |
| 9783 | * The PLL needs to be enabled with a valid divider |
| 9784 | * configuration, otherwise accessing DSI registers will hang |
| 9785 | * the machine. See BSpec North Display Engine |
| 9786 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9787 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9788 | */ |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 9789 | if (!bxt_dsi_pll_is_enabled(dev_priv)) |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9790 | break; |
| 9791 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9792 | /* XXX: this works for video mode only */ |
| 9793 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9794 | if (!(tmp & DPI_ENABLE)) |
| 9795 | continue; |
| 9796 | |
| 9797 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9798 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9799 | continue; |
| 9800 | |
| 9801 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9802 | break; |
| 9803 | } |
| 9804 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9805 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9806 | } |
| 9807 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9808 | 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] | 9809 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9810 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9811 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9812 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9813 | enum port port; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9814 | u32 tmp; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9815 | |
| 9816 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9817 | |
| 9818 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9819 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9820 | if (IS_ICELAKE(dev_priv)) |
| 9821 | icelake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9822 | else if (IS_CANNONLAKE(dev_priv)) |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9823 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9824 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9825 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9826 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9827 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9828 | else |
| 9829 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9830 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9831 | pll = pipe_config->shared_dpll; |
| 9832 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9833 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9834 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9835 | } |
| 9836 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9837 | /* |
| 9838 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9839 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9840 | * the PCH transcoder is on. |
| 9841 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9842 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9843 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9844 | pipe_config->has_pch_encoder = true; |
| 9845 | |
| 9846 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9847 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9848 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9849 | |
| 9850 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9851 | } |
| 9852 | } |
| 9853 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9854 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9855 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9856 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9857 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9858 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9859 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9860 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9861 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9862 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9863 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9864 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9865 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9866 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9867 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9868 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9869 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9870 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9871 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9872 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9873 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9874 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9875 | WARN_ON(active); |
| 9876 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9877 | } |
| 9878 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9879 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9880 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9881 | |
Madhav Chauhan | 2eae5d6 | 2018-11-29 16:12:28 +0200 | [diff] [blame] | 9882 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || |
| 9883 | IS_ICELAKE(dev_priv)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9884 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9885 | intel_get_pipe_timings(crtc, pipe_config); |
| 9886 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9887 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9888 | intel_get_pipe_src_size(crtc, pipe_config); |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 9889 | intel_get_crtc_ycbcr_config(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9890 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9891 | pipe_config->gamma_mode = |
| 9892 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9893 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 9894 | if (INTEL_GEN(dev_priv) >= 9) { |
| 9895 | u32 tmp = I915_READ(SKL_BOTTOM_COLOR(crtc->pipe)); |
| 9896 | |
| 9897 | if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE) |
| 9898 | pipe_config->gamma_enable = true; |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 9899 | |
| 9900 | if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE) |
| 9901 | pipe_config->csc_enable = true; |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 9902 | } else { |
| 9903 | i9xx_get_pipe_color_config(pipe_config); |
| 9904 | } |
| 9905 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9906 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9907 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9908 | WARN_ON(power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9909 | power_domain_mask |= BIT_ULL(power_domain); |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9910 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9911 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9912 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9913 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9914 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9915 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9916 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9917 | if (hsw_crtc_supports_ips(crtc)) { |
| 9918 | if (IS_HASWELL(dev_priv)) |
| 9919 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9920 | else { |
| 9921 | /* |
| 9922 | * We cannot readout IPS state on broadwell, set to |
| 9923 | * true so we can set it to a defined state on first |
| 9924 | * commit. |
| 9925 | */ |
| 9926 | pipe_config->ips_enabled = true; |
| 9927 | } |
| 9928 | } |
| 9929 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9930 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9931 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9932 | pipe_config->pixel_multiplier = |
| 9933 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9934 | } else { |
| 9935 | pipe_config->pixel_multiplier = 1; |
| 9936 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9937 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9938 | out: |
| 9939 | for_each_power_domain(power_domain, power_domain_mask) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9940 | intel_display_power_put_unchecked(dev_priv, power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9941 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9942 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9943 | } |
| 9944 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9945 | 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] | 9946 | { |
| 9947 | struct drm_i915_private *dev_priv = |
| 9948 | to_i915(plane_state->base.plane->dev); |
| 9949 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9950 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9951 | u32 base; |
| 9952 | |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 9953 | if (INTEL_INFO(dev_priv)->display.cursor_needs_physical) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9954 | base = obj->phys_handle->busaddr; |
| 9955 | else |
| 9956 | base = intel_plane_ggtt_offset(plane_state); |
| 9957 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 9958 | base += plane_state->color_plane[0].offset; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9959 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9960 | /* ILK+ do this automagically */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 9961 | if (HAS_GMCH(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9962 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9963 | base += (plane_state->base.crtc_h * |
| 9964 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9965 | |
| 9966 | return base; |
| 9967 | } |
| 9968 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9969 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9970 | { |
| 9971 | int x = plane_state->base.crtc_x; |
| 9972 | int y = plane_state->base.crtc_y; |
| 9973 | u32 pos = 0; |
| 9974 | |
| 9975 | if (x < 0) { |
| 9976 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9977 | x = -x; |
| 9978 | } |
| 9979 | pos |= x << CURSOR_X_SHIFT; |
| 9980 | |
| 9981 | if (y < 0) { |
| 9982 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9983 | y = -y; |
| 9984 | } |
| 9985 | pos |= y << CURSOR_Y_SHIFT; |
| 9986 | |
| 9987 | return pos; |
| 9988 | } |
| 9989 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9990 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9991 | { |
| 9992 | const struct drm_mode_config *config = |
| 9993 | &plane_state->base.plane->dev->mode_config; |
| 9994 | int width = plane_state->base.crtc_w; |
| 9995 | int height = plane_state->base.crtc_h; |
| 9996 | |
| 9997 | return width > 0 && width <= config->cursor_width && |
| 9998 | height > 0 && height <= config->cursor_height; |
| 9999 | } |
| 10000 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 10001 | 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] | 10002 | { |
| 10003 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10004 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 10005 | int src_x, src_y; |
| 10006 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 10007 | int ret; |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 10008 | |
| 10009 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
| 10010 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 10011 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 10012 | ret = intel_plane_check_stride(plane_state); |
| 10013 | if (ret) |
| 10014 | return ret; |
| 10015 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 10016 | src_x = plane_state->base.src_x >> 16; |
| 10017 | src_y = plane_state->base.src_y >> 16; |
| 10018 | |
| 10019 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 10020 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 10021 | plane_state, 0); |
| 10022 | |
| 10023 | if (src_x != 0 || src_y != 0) { |
| 10024 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 10025 | return -EINVAL; |
| 10026 | } |
| 10027 | |
| 10028 | plane_state->color_plane[0].offset = offset; |
| 10029 | |
| 10030 | return 0; |
| 10031 | } |
| 10032 | |
| 10033 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 10034 | struct intel_plane_state *plane_state) |
| 10035 | { |
| 10036 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10037 | int ret; |
| 10038 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 10039 | if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 10040 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 10041 | return -EINVAL; |
| 10042 | } |
| 10043 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 10044 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 10045 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 10046 | DRM_PLANE_HELPER_NO_SCALING, |
| 10047 | DRM_PLANE_HELPER_NO_SCALING, |
| 10048 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10049 | if (ret) |
| 10050 | return ret; |
| 10051 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 10052 | if (!plane_state->base.visible) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10053 | return 0; |
| 10054 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 10055 | ret = intel_plane_check_src_coordinates(plane_state); |
| 10056 | if (ret) |
| 10057 | return ret; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10058 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 10059 | ret = intel_cursor_check_surface(plane_state); |
| 10060 | if (ret) |
| 10061 | return ret; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 10062 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10063 | return 0; |
| 10064 | } |
| 10065 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 10066 | static unsigned int |
| 10067 | i845_cursor_max_stride(struct intel_plane *plane, |
| 10068 | u32 pixel_format, u64 modifier, |
| 10069 | unsigned int rotation) |
| 10070 | { |
| 10071 | return 2048; |
| 10072 | } |
| 10073 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10074 | static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 10075 | { |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 10076 | u32 cntl = 0; |
| 10077 | |
| 10078 | if (crtc_state->gamma_enable) |
| 10079 | cntl |= CURSOR_GAMMA_ENABLE; |
| 10080 | |
| 10081 | return cntl; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10082 | } |
| 10083 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10084 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 10085 | const struct intel_plane_state *plane_state) |
| 10086 | { |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10087 | return CURSOR_ENABLE | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10088 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10089 | CURSOR_STRIDE(plane_state->color_plane[0].stride); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10090 | } |
| 10091 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10092 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 10093 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10094 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10095 | |
| 10096 | /* |
| 10097 | * 845g/865g are only limited by the width of their cursors, |
| 10098 | * the height is arbitrary up to the precision of the register. |
| 10099 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 10100 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10101 | } |
| 10102 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10103 | static int i845_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10104 | struct intel_plane_state *plane_state) |
| 10105 | { |
| 10106 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10107 | int ret; |
| 10108 | |
| 10109 | ret = intel_check_cursor(crtc_state, plane_state); |
| 10110 | if (ret) |
| 10111 | return ret; |
| 10112 | |
| 10113 | /* 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] | 10114 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10115 | return 0; |
| 10116 | |
| 10117 | /* Check for which cursor types we support */ |
| 10118 | if (!i845_cursor_size_ok(plane_state)) { |
| 10119 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 10120 | plane_state->base.crtc_w, |
| 10121 | plane_state->base.crtc_h); |
| 10122 | return -EINVAL; |
| 10123 | } |
| 10124 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10125 | WARN_ON(plane_state->base.visible && |
| 10126 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 10127 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10128 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10129 | case 256: |
| 10130 | case 512: |
| 10131 | case 1024: |
| 10132 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10133 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10134 | default: |
| 10135 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 10136 | fb->pitches[0]); |
| 10137 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10138 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10139 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10140 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 10141 | |
| 10142 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10143 | } |
| 10144 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10145 | static void i845_update_cursor(struct intel_plane *plane, |
| 10146 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10147 | const struct intel_plane_state *plane_state) |
| 10148 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10149 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10150 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 10151 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10152 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10153 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10154 | unsigned int width = plane_state->base.crtc_w; |
| 10155 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10156 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10157 | cntl = plane_state->ctl | |
| 10158 | i845_cursor_ctl_crtc(crtc_state); |
| 10159 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10160 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10161 | |
| 10162 | base = intel_cursor_base(plane_state); |
| 10163 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10164 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10165 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10166 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10167 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10168 | /* On these chipsets we can only modify the base/size/stride |
| 10169 | * whilst the cursor is disabled. |
| 10170 | */ |
| 10171 | if (plane->cursor.base != base || |
| 10172 | plane->cursor.size != size || |
| 10173 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10174 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10175 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10176 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10177 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 10178 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10179 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10180 | plane->cursor.base = base; |
| 10181 | plane->cursor.size = size; |
| 10182 | plane->cursor.cntl = cntl; |
| 10183 | } else { |
| 10184 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10185 | } |
| 10186 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10187 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 10188 | } |
| 10189 | |
| 10190 | static void i845_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10191 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10192 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10193 | i845_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10194 | } |
| 10195 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10196 | static bool i845_cursor_get_hw_state(struct intel_plane *plane, |
| 10197 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10198 | { |
| 10199 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10200 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10201 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10202 | bool ret; |
| 10203 | |
| 10204 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10205 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 10206 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10207 | return false; |
| 10208 | |
| 10209 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 10210 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10211 | *pipe = PIPE_A; |
| 10212 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10213 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10214 | |
| 10215 | return ret; |
| 10216 | } |
| 10217 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 10218 | static unsigned int |
| 10219 | i9xx_cursor_max_stride(struct intel_plane *plane, |
| 10220 | u32 pixel_format, u64 modifier, |
| 10221 | unsigned int rotation) |
| 10222 | { |
| 10223 | return plane->base.dev->mode_config.cursor_width * 4; |
| 10224 | } |
| 10225 | |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10226 | static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state) |
| 10227 | { |
| 10228 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 10229 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 10230 | u32 cntl = 0; |
| 10231 | |
| 10232 | if (INTEL_GEN(dev_priv) >= 11) |
| 10233 | return cntl; |
| 10234 | |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 10235 | if (crtc_state->gamma_enable) |
| 10236 | cntl = MCURSOR_GAMMA_ENABLE; |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10237 | |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 10238 | if (crtc_state->csc_enable) |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10239 | cntl |= MCURSOR_PIPE_CSC_ENABLE; |
| 10240 | |
| 10241 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 10242 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
| 10243 | |
| 10244 | return cntl; |
| 10245 | } |
| 10246 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10247 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 10248 | const struct intel_plane_state *plane_state) |
| 10249 | { |
| 10250 | struct drm_i915_private *dev_priv = |
| 10251 | to_i915(plane_state->base.plane->dev); |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10252 | u32 cntl = 0; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10253 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10254 | if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | e876b78 | 2018-01-30 22:38:05 +0200 | [diff] [blame] | 10255 | cntl |= MCURSOR_TRICKLE_FEED_DISABLE; |
| 10256 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10257 | switch (plane_state->base.crtc_w) { |
| 10258 | case 64: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10259 | cntl |= MCURSOR_MODE_64_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10260 | break; |
| 10261 | case 128: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10262 | cntl |= MCURSOR_MODE_128_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10263 | break; |
| 10264 | case 256: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10265 | cntl |= MCURSOR_MODE_256_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10266 | break; |
| 10267 | default: |
| 10268 | MISSING_CASE(plane_state->base.crtc_w); |
| 10269 | return 0; |
| 10270 | } |
| 10271 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 10272 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10273 | cntl |= MCURSOR_ROTATE_180; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10274 | |
| 10275 | return cntl; |
| 10276 | } |
| 10277 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10278 | 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] | 10279 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10280 | struct drm_i915_private *dev_priv = |
| 10281 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10282 | int width = plane_state->base.crtc_w; |
| 10283 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10284 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 10285 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10286 | return false; |
| 10287 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10288 | /* Cursor width is limited to a few power-of-two sizes */ |
| 10289 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10290 | case 256: |
| 10291 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10292 | case 64: |
| 10293 | break; |
| 10294 | default: |
| 10295 | return false; |
| 10296 | } |
| 10297 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10298 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10299 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 10300 | * height from 8 lines up to the cursor width, when the |
| 10301 | * cursor is not rotated. Everything else requires square |
| 10302 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10303 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10304 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 10305 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10306 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10307 | return false; |
| 10308 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10309 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10310 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10311 | } |
| 10312 | |
| 10313 | return true; |
| 10314 | } |
| 10315 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10316 | static int i9xx_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10317 | struct intel_plane_state *plane_state) |
| 10318 | { |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10319 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10320 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10321 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10322 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10323 | int ret; |
| 10324 | |
| 10325 | ret = intel_check_cursor(crtc_state, plane_state); |
| 10326 | if (ret) |
| 10327 | return ret; |
| 10328 | |
| 10329 | /* 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] | 10330 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10331 | return 0; |
| 10332 | |
| 10333 | /* Check for which cursor types we support */ |
| 10334 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 10335 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 10336 | plane_state->base.crtc_w, |
| 10337 | plane_state->base.crtc_h); |
| 10338 | return -EINVAL; |
| 10339 | } |
| 10340 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10341 | WARN_ON(plane_state->base.visible && |
| 10342 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 10343 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10344 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 10345 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 10346 | fb->pitches[0], plane_state->base.crtc_w); |
| 10347 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10348 | } |
| 10349 | |
| 10350 | /* |
| 10351 | * There's something wrong with the cursor on CHV pipe C. |
| 10352 | * If it straddles the left edge of the screen then |
| 10353 | * moving it away from the edge or disabling it often |
| 10354 | * results in a pipe underrun, and often that can lead to |
| 10355 | * dead pipe (constant underrun reported, and it scans |
| 10356 | * out just a solid color). To recover from that, the |
| 10357 | * display power well must be turned off and on again. |
| 10358 | * Refuse the put the cursor into that compromised position. |
| 10359 | */ |
| 10360 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 10361 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 10362 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 10363 | return -EINVAL; |
| 10364 | } |
| 10365 | |
| 10366 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 10367 | |
| 10368 | return 0; |
| 10369 | } |
| 10370 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10371 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 10372 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10373 | const struct intel_plane_state *plane_state) |
| 10374 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10375 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10376 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10377 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10378 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10379 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10380 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | 7eb31a0 | 2019-02-05 18:08:36 +0200 | [diff] [blame] | 10381 | cntl = plane_state->ctl | |
| 10382 | i9xx_cursor_ctl_crtc(crtc_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10383 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10384 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 10385 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 10386 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10387 | base = intel_cursor_base(plane_state); |
| 10388 | pos = intel_cursor_position(plane_state); |
| 10389 | } |
| 10390 | |
| 10391 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10392 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10393 | /* |
| 10394 | * On some platforms writing CURCNTR first will also |
| 10395 | * cause CURPOS to be armed by the CURBASE write. |
| 10396 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10397 | * arm itself. Thus we always update CURCNTR before |
| 10398 | * CURPOS. |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10399 | * |
| 10400 | * On other platforms CURPOS always requires the |
| 10401 | * CURBASE write to arm the update. Additonally |
| 10402 | * a write to any of the cursor register will cancel |
| 10403 | * an already armed cursor update. Thus leaving out |
| 10404 | * the CURBASE write after CURPOS could lead to a |
| 10405 | * cursor that doesn't appear to move, or even change |
| 10406 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10407 | * |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10408 | * The other registers are armed by by the CURBASE write |
| 10409 | * except when the plane is getting enabled at which time |
| 10410 | * the CURCNTR write arms the update. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10411 | */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 10412 | |
| 10413 | if (INTEL_GEN(dev_priv) >= 9) |
| 10414 | skl_write_cursor_wm(plane, crtc_state); |
| 10415 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10416 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10417 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10418 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10419 | if (HAS_CUR_FBC(dev_priv)) |
| 10420 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10421 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10422 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10423 | I915_WRITE_FW(CURBASE(pipe), base); |
| 10424 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10425 | plane->cursor.base = base; |
| 10426 | plane->cursor.size = fbc_ctl; |
| 10427 | plane->cursor.cntl = cntl; |
| 10428 | } else { |
| 10429 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10430 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10431 | } |
| 10432 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10433 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10434 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10435 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10436 | static void i9xx_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10437 | const struct intel_crtc_state *crtc_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10438 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10439 | i9xx_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10440 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 10441 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10442 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane, |
| 10443 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10444 | { |
| 10445 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10446 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10447 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10448 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10449 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10450 | |
| 10451 | /* |
| 10452 | * Not 100% correct for planes that can move between pipes, |
| 10453 | * but that's only the case for gen2-3 which don't have any |
| 10454 | * display power wells. |
| 10455 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10456 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10457 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 10458 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10459 | return false; |
| 10460 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10461 | val = I915_READ(CURCNTR(plane->pipe)); |
| 10462 | |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10463 | ret = val & MCURSOR_MODE; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10464 | |
| 10465 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 10466 | *pipe = plane->pipe; |
| 10467 | else |
| 10468 | *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >> |
| 10469 | MCURSOR_PIPE_SELECT_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10470 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10471 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10472 | |
| 10473 | return ret; |
| 10474 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10475 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10476 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10477 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10478 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10479 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10480 | }; |
| 10481 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10482 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10483 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 10484 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10485 | { |
| 10486 | struct intel_framebuffer *intel_fb; |
| 10487 | int ret; |
| 10488 | |
| 10489 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10490 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10491 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10492 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10493 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10494 | if (ret) |
| 10495 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10496 | |
| 10497 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10498 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10499 | err: |
| 10500 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10501 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10502 | } |
| 10503 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10504 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 10505 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10506 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10507 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10508 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10509 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10510 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10511 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10512 | if (ret) |
| 10513 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10514 | |
| 10515 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 10516 | if (plane_state->crtc != crtc) |
| 10517 | continue; |
| 10518 | |
| 10519 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 10520 | if (ret) |
| 10521 | return ret; |
| 10522 | |
| 10523 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 10524 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10525 | |
| 10526 | return 0; |
| 10527 | } |
| 10528 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10529 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10530 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10531 | struct intel_load_detect_pipe *old, |
| 10532 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10533 | { |
| 10534 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10535 | struct intel_encoder *intel_encoder = |
| 10536 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10537 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10538 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10539 | struct drm_crtc *crtc = NULL; |
| 10540 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10541 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10542 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10543 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10544 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10545 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10546 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10547 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10548 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10549 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10550 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10551 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10552 | old->restore_state = NULL; |
| 10553 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10554 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10555 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10556 | /* |
| 10557 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10558 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10559 | * - if the connector already has an assigned crtc, use it (but make |
| 10560 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10561 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10562 | * - try to find the first unused crtc that can drive this connector, |
| 10563 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10564 | */ |
| 10565 | |
| 10566 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10567 | if (connector->state->crtc) { |
| 10568 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10569 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10570 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10571 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10572 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10573 | |
| 10574 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10575 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10576 | } |
| 10577 | |
| 10578 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10579 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10580 | i++; |
| 10581 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10582 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10583 | |
| 10584 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10585 | if (ret) |
| 10586 | goto fail; |
| 10587 | |
| 10588 | if (possible_crtc->state->enable) { |
| 10589 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10590 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10591 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10592 | |
| 10593 | crtc = possible_crtc; |
| 10594 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10595 | } |
| 10596 | |
| 10597 | /* |
| 10598 | * If we didn't find an unused CRTC, don't use any. |
| 10599 | */ |
| 10600 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10601 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10602 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10603 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10604 | } |
| 10605 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10606 | found: |
| 10607 | intel_crtc = to_intel_crtc(crtc); |
| 10608 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10609 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10610 | restore_state = drm_atomic_state_alloc(dev); |
| 10611 | if (!state || !restore_state) { |
| 10612 | ret = -ENOMEM; |
| 10613 | goto fail; |
| 10614 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10615 | |
| 10616 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10617 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10618 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10619 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10620 | if (IS_ERR(connector_state)) { |
| 10621 | ret = PTR_ERR(connector_state); |
| 10622 | goto fail; |
| 10623 | } |
| 10624 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10625 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10626 | if (ret) |
| 10627 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10628 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10629 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10630 | if (IS_ERR(crtc_state)) { |
| 10631 | ret = PTR_ERR(crtc_state); |
| 10632 | goto fail; |
| 10633 | } |
| 10634 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10635 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10636 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10637 | if (!mode) |
| 10638 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10639 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10640 | 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] | 10641 | if (ret) |
| 10642 | goto fail; |
| 10643 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10644 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10645 | if (ret) |
| 10646 | goto fail; |
| 10647 | |
| 10648 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10649 | if (!ret) |
| 10650 | 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] | 10651 | if (!ret) |
| 10652 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10653 | if (ret) { |
| 10654 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10655 | goto fail; |
| 10656 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10657 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10658 | ret = drm_atomic_commit(state); |
| 10659 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10660 | 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] | 10661 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10662 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10663 | |
| 10664 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10665 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10666 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10667 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10668 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10669 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10670 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10671 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10672 | if (state) { |
| 10673 | drm_atomic_state_put(state); |
| 10674 | state = NULL; |
| 10675 | } |
| 10676 | if (restore_state) { |
| 10677 | drm_atomic_state_put(restore_state); |
| 10678 | restore_state = NULL; |
| 10679 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10680 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10681 | if (ret == -EDEADLK) |
| 10682 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10683 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10684 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10685 | } |
| 10686 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10687 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10688 | struct intel_load_detect_pipe *old, |
| 10689 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10690 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10691 | struct intel_encoder *intel_encoder = |
| 10692 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10693 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10694 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10695 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10696 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10697 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10698 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10699 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10700 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10701 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10702 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10703 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10704 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10705 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10706 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10707 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10708 | } |
| 10709 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10710 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10711 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10712 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10713 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10714 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10715 | |
| 10716 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10717 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10718 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10719 | return 120000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10720 | else if (!IS_GEN(dev_priv, 2)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10721 | return 96000; |
| 10722 | else |
| 10723 | return 48000; |
| 10724 | } |
| 10725 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10726 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10727 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10728 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10729 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10730 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10731 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10732 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10733 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10734 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10735 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10736 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10737 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10738 | |
| 10739 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10740 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10741 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10742 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10743 | |
| 10744 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10745 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10746 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10747 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10748 | } else { |
| 10749 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10750 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10751 | } |
| 10752 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10753 | if (!IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10754 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10755 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10756 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10757 | else |
| 10758 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10759 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10760 | |
| 10761 | switch (dpll & DPLL_MODE_MASK) { |
| 10762 | case DPLLB_MODE_DAC_SERIAL: |
| 10763 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10764 | 5 : 10; |
| 10765 | break; |
| 10766 | case DPLLB_MODE_LVDS: |
| 10767 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10768 | 7 : 14; |
| 10769 | break; |
| 10770 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10771 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10772 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10773 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10774 | } |
| 10775 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10776 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10777 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10778 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10779 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10780 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10781 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10782 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10783 | |
| 10784 | if (is_lvds) { |
| 10785 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10786 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10787 | |
| 10788 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10789 | clock.p2 = 7; |
| 10790 | else |
| 10791 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10792 | } else { |
| 10793 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10794 | clock.p1 = 2; |
| 10795 | else { |
| 10796 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10797 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10798 | } |
| 10799 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10800 | clock.p2 = 4; |
| 10801 | else |
| 10802 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10803 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10804 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10805 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10806 | } |
| 10807 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10808 | /* |
| 10809 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10810 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10811 | * encoder's get_config() function. |
| 10812 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10813 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10814 | } |
| 10815 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10816 | int intel_dotclock_calculate(int link_freq, |
| 10817 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10818 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10819 | /* |
| 10820 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10821 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10822 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10823 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10824 | * |
| 10825 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10826 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10827 | */ |
| 10828 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10829 | if (!m_n->link_n) |
| 10830 | return 0; |
| 10831 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10832 | 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] | 10833 | } |
| 10834 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10835 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10836 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10837 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10838 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10839 | |
| 10840 | /* read out port_clock from the DPLL */ |
| 10841 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10842 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10843 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10844 | * In case there is an active pipe without active ports, |
| 10845 | * we may need some idea for the dotclock anyway. |
| 10846 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10847 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10848 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10849 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10850 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10851 | } |
| 10852 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10853 | /* Returns the currently programmed mode of the given encoder. */ |
| 10854 | struct drm_display_mode * |
| 10855 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10856 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10857 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10858 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10859 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10860 | struct intel_crtc *crtc; |
| 10861 | enum pipe pipe; |
| 10862 | |
| 10863 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10864 | return NULL; |
| 10865 | |
| 10866 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10867 | |
| 10868 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10869 | if (!mode) |
| 10870 | return NULL; |
| 10871 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10872 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10873 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10874 | kfree(mode); |
| 10875 | return NULL; |
| 10876 | } |
| 10877 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10878 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10879 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10880 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10881 | kfree(crtc_state); |
| 10882 | kfree(mode); |
| 10883 | return NULL; |
| 10884 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10885 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10886 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10887 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10888 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10889 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10890 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10891 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10892 | return mode; |
| 10893 | } |
| 10894 | |
| 10895 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10896 | { |
| 10897 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10898 | |
| 10899 | drm_crtc_cleanup(crtc); |
| 10900 | kfree(intel_crtc); |
| 10901 | } |
| 10902 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10903 | /** |
| 10904 | * intel_wm_need_update - Check whether watermarks need updating |
Chris Wilson | 6bf1981 | 2018-12-31 14:35:05 +0000 | [diff] [blame] | 10905 | * @cur: current plane state |
| 10906 | * @new: new plane state |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10907 | * |
| 10908 | * Check current plane state versus the new one to determine whether |
| 10909 | * watermarks need to be recalculated. |
| 10910 | * |
| 10911 | * Returns true or false. |
| 10912 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10913 | static bool intel_wm_need_update(struct intel_plane_state *cur, |
| 10914 | struct intel_plane_state *new) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10915 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10916 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10917 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10918 | return true; |
| 10919 | |
| 10920 | if (!cur->base.fb || !new->base.fb) |
| 10921 | return false; |
| 10922 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10923 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10924 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10925 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10926 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10927 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10928 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10929 | return true; |
| 10930 | |
| 10931 | return false; |
| 10932 | } |
| 10933 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10934 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10935 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10936 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10937 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10938 | int dst_w = drm_rect_width(&state->base.dst); |
| 10939 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10940 | |
| 10941 | return (src_w != dst_w || src_h != dst_h); |
| 10942 | } |
| 10943 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10944 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10945 | struct drm_crtc_state *crtc_state, |
| 10946 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10947 | struct drm_plane_state *plane_state) |
| 10948 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10949 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10950 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10951 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10952 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10953 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10954 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10955 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10956 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10957 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10958 | bool turn_off, turn_on, visible, was_visible; |
| 10959 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10960 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10961 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10962 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10963 | ret = skl_update_scaler_plane( |
| 10964 | to_intel_crtc_state(crtc_state), |
| 10965 | to_intel_plane_state(plane_state)); |
| 10966 | if (ret) |
| 10967 | return ret; |
| 10968 | } |
| 10969 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10970 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10971 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10972 | |
| 10973 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10974 | was_visible = false; |
| 10975 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10976 | /* |
| 10977 | * Visibility is calculated as if the crtc was on, but |
| 10978 | * after scaler setup everything depends on it being off |
| 10979 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10980 | * |
| 10981 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10982 | * be computed as if the pipe would be active. Perhaps move |
| 10983 | * per-plane wm computation to the .check_plane() hook, and |
| 10984 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10985 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10986 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10987 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10988 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10989 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10990 | |
| 10991 | if (!was_visible && !visible) |
| 10992 | return 0; |
| 10993 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10994 | if (fb != old_plane_state->base.fb) |
| 10995 | pipe_config->fb_changed = true; |
| 10996 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10997 | turn_off = was_visible && (!visible || mode_changed); |
| 10998 | turn_on = visible && (!was_visible || mode_changed); |
| 10999 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 11000 | 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] | 11001 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 11002 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 11003 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11004 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 11005 | 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] | 11006 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 11007 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11008 | turn_off, turn_on, mode_changed); |
| 11009 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11010 | if (turn_on) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11011 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 11012 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11013 | |
| 11014 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 11015 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11016 | pipe_config->disable_cxsr = true; |
| 11017 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11018 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 11019 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11020 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11021 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 11022 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11023 | pipe_config->disable_cxsr = true; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11024 | } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state), |
| 11025 | to_intel_plane_state(plane_state))) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11026 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 11027 | /* FIXME bollocks */ |
| 11028 | pipe_config->update_wm_pre = true; |
| 11029 | pipe_config->update_wm_post = true; |
| 11030 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11031 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11032 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 11033 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 11034 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11035 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11036 | /* |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 11037 | * ILK/SNB DVSACNTR/Sprite Enable |
| 11038 | * IVB SPR_CTL/Sprite Enable |
| 11039 | * "When in Self Refresh Big FIFO mode, a write to enable the |
| 11040 | * plane will be internally buffered and delayed while Big FIFO |
| 11041 | * mode is exiting." |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11042 | * |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 11043 | * Which means that enabling the sprite can take an extra frame |
| 11044 | * when we start in big FIFO mode (LP1+). Thus we need to drop |
| 11045 | * down to LP0 and wait for vblank in order to make sure the |
| 11046 | * sprite gets enabled on the next vblank after the register write. |
| 11047 | * Doing otherwise would risk enabling the sprite one frame after |
| 11048 | * we've already signalled flip completion. We can resume LP1+ |
| 11049 | * once the sprite has been enabled. |
| 11050 | * |
| 11051 | * |
| 11052 | * WaCxSRDisabledForSpriteScaling:ivb |
| 11053 | * IVB SPR_SCALE/Scaling Enable |
| 11054 | * "Low Power watermarks must be disabled for at least one |
| 11055 | * frame before enabling sprite scaling, and kept disabled |
| 11056 | * until sprite scaling is disabled." |
| 11057 | * |
| 11058 | * ILK/SNB DVSASCALE/Scaling Enable |
| 11059 | * "When in Self Refresh Big FIFO mode, scaling enable will be |
| 11060 | * masked off while Big FIFO mode is exiting." |
| 11061 | * |
| 11062 | * Despite the w/a only being listed for IVB we assume that |
| 11063 | * the ILK/SNB note has similar ramifications, hence we apply |
| 11064 | * the w/a on all three platforms. |
Juha-Pekka Heikkila | d8af327 | 2018-12-20 13:26:08 +0200 | [diff] [blame] | 11065 | * |
| 11066 | * With experimental results seems this is needed also for primary |
| 11067 | * plane, not only sprite plane. |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11068 | */ |
Juha-Pekka Heikkila | d8af327 | 2018-12-20 13:26:08 +0200 | [diff] [blame] | 11069 | if (plane->id != PLANE_CURSOR && |
Lucas De Marchi | f3ce44a | 2018-12-12 10:10:44 -0800 | [diff] [blame] | 11070 | (IS_GEN_RANGE(dev_priv, 5, 6) || |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 11071 | IS_IVYBRIDGE(dev_priv)) && |
| 11072 | (turn_on || (!needs_scaling(old_plane_state) && |
| 11073 | needs_scaling(to_intel_plane_state(plane_state))))) |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11074 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11075 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11076 | return 0; |
| 11077 | } |
| 11078 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11079 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 11080 | const struct intel_encoder *b) |
| 11081 | { |
| 11082 | /* masks could be asymmetric, so check both ways */ |
| 11083 | return a == b || (a->cloneable & (1 << b->type) && |
| 11084 | b->cloneable & (1 << a->type)); |
| 11085 | } |
| 11086 | |
| 11087 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 11088 | struct intel_crtc *crtc, |
| 11089 | struct intel_encoder *encoder) |
| 11090 | { |
| 11091 | struct intel_encoder *source_encoder; |
| 11092 | struct drm_connector *connector; |
| 11093 | struct drm_connector_state *connector_state; |
| 11094 | int i; |
| 11095 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11096 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11097 | if (connector_state->crtc != &crtc->base) |
| 11098 | continue; |
| 11099 | |
| 11100 | source_encoder = |
| 11101 | to_intel_encoder(connector_state->best_encoder); |
| 11102 | if (!encoders_cloneable(encoder, source_encoder)) |
| 11103 | return false; |
| 11104 | } |
| 11105 | |
| 11106 | return true; |
| 11107 | } |
| 11108 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11109 | static int icl_add_linked_planes(struct intel_atomic_state *state) |
| 11110 | { |
| 11111 | struct intel_plane *plane, *linked; |
| 11112 | struct intel_plane_state *plane_state, *linked_plane_state; |
| 11113 | int i; |
| 11114 | |
| 11115 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 11116 | linked = plane_state->linked_plane; |
| 11117 | |
| 11118 | if (!linked) |
| 11119 | continue; |
| 11120 | |
| 11121 | linked_plane_state = intel_atomic_get_plane_state(state, linked); |
| 11122 | if (IS_ERR(linked_plane_state)) |
| 11123 | return PTR_ERR(linked_plane_state); |
| 11124 | |
| 11125 | WARN_ON(linked_plane_state->linked_plane != plane); |
| 11126 | WARN_ON(linked_plane_state->slave == plane_state->slave); |
| 11127 | } |
| 11128 | |
| 11129 | return 0; |
| 11130 | } |
| 11131 | |
| 11132 | static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state) |
| 11133 | { |
| 11134 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 11135 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 11136 | struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state); |
| 11137 | struct intel_plane *plane, *linked; |
| 11138 | struct intel_plane_state *plane_state; |
| 11139 | int i; |
| 11140 | |
| 11141 | if (INTEL_GEN(dev_priv) < 11) |
| 11142 | return 0; |
| 11143 | |
| 11144 | /* |
| 11145 | * Destroy all old plane links and make the slave plane invisible |
| 11146 | * in the crtc_state->active_planes mask. |
| 11147 | */ |
| 11148 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 11149 | if (plane->pipe != crtc->pipe || !plane_state->linked_plane) |
| 11150 | continue; |
| 11151 | |
| 11152 | plane_state->linked_plane = NULL; |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 11153 | if (plane_state->slave && !plane_state->base.visible) { |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11154 | crtc_state->active_planes &= ~BIT(plane->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 11155 | crtc_state->update_planes |= BIT(plane->id); |
| 11156 | } |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11157 | |
| 11158 | plane_state->slave = false; |
| 11159 | } |
| 11160 | |
| 11161 | if (!crtc_state->nv12_planes) |
| 11162 | return 0; |
| 11163 | |
| 11164 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 11165 | struct intel_plane_state *linked_state = NULL; |
| 11166 | |
| 11167 | if (plane->pipe != crtc->pipe || |
| 11168 | !(crtc_state->nv12_planes & BIT(plane->id))) |
| 11169 | continue; |
| 11170 | |
| 11171 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) { |
| 11172 | if (!icl_is_nv12_y_plane(linked->id)) |
| 11173 | continue; |
| 11174 | |
| 11175 | if (crtc_state->active_planes & BIT(linked->id)) |
| 11176 | continue; |
| 11177 | |
| 11178 | linked_state = intel_atomic_get_plane_state(state, linked); |
| 11179 | if (IS_ERR(linked_state)) |
| 11180 | return PTR_ERR(linked_state); |
| 11181 | |
| 11182 | break; |
| 11183 | } |
| 11184 | |
| 11185 | if (!linked_state) { |
| 11186 | DRM_DEBUG_KMS("Need %d free Y planes for NV12\n", |
| 11187 | hweight8(crtc_state->nv12_planes)); |
| 11188 | |
| 11189 | return -EINVAL; |
| 11190 | } |
| 11191 | |
| 11192 | plane_state->linked_plane = linked; |
| 11193 | |
| 11194 | linked_state->slave = true; |
| 11195 | linked_state->linked_plane = plane; |
| 11196 | crtc_state->active_planes |= BIT(linked->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 11197 | crtc_state->update_planes |= BIT(linked->id); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11198 | DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name); |
| 11199 | } |
| 11200 | |
| 11201 | return 0; |
| 11202 | } |
| 11203 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11204 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 11205 | struct drm_crtc_state *crtc_state) |
| 11206 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11207 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11208 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11209 | struct intel_crtc_state *pipe_config = |
| 11210 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11211 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11212 | bool mode_changed = needs_modeset(crtc_state); |
| 11213 | |
Ville Syrjälä | 440e84a | 2019-02-06 20:54:33 +0200 | [diff] [blame] | 11214 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) && |
| 11215 | mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11216 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 11217 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11218 | if (mode_changed && crtc_state->enable && |
| 11219 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11220 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11221 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11222 | pipe_config); |
| 11223 | if (ret) |
| 11224 | return ret; |
| 11225 | } |
| 11226 | |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 11227 | if (mode_changed || crtc_state->color_mgmt_changed) { |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 11228 | ret = intel_color_check(pipe_config); |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11229 | if (ret) |
| 11230 | return ret; |
| 11231 | } |
| 11232 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11233 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11234 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 11235 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11236 | if (ret) { |
| 11237 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11238 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11239 | } |
| 11240 | } |
| 11241 | |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 11242 | if (dev_priv->display.compute_intermediate_wm) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11243 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 11244 | return 0; |
| 11245 | |
| 11246 | /* |
| 11247 | * Calculate 'intermediate' watermarks that satisfy both the |
| 11248 | * old state and the new state. We can program these |
| 11249 | * immediately. |
| 11250 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11251 | ret = dev_priv->display.compute_intermediate_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11252 | if (ret) { |
| 11253 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 11254 | return ret; |
| 11255 | } |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11256 | } |
| 11257 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11258 | if (INTEL_GEN(dev_priv) >= 9) { |
Hans de Goede | 2c5c415 | 2018-12-17 15:19:03 +0100 | [diff] [blame] | 11259 | if (mode_changed || pipe_config->update_pipe) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11260 | ret = skl_update_scaler_crtc(pipe_config); |
| 11261 | |
| 11262 | if (!ret) |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11263 | ret = icl_check_nv12_planes(pipe_config); |
| 11264 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 11265 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 11266 | pipe_config); |
| 11267 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 11268 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11269 | pipe_config); |
| 11270 | } |
| 11271 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 11272 | if (HAS_IPS(dev_priv)) |
| 11273 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 11274 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11275 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11276 | } |
| 11277 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11278 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11279 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11280 | }; |
| 11281 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11282 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11283 | { |
| 11284 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11285 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11286 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11287 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11288 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11289 | if (connector->base.state->crtc) |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11290 | drm_connector_put(&connector->base); |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11291 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11292 | if (connector->base.encoder) { |
| 11293 | connector->base.state->best_encoder = |
| 11294 | connector->base.encoder; |
| 11295 | connector->base.state->crtc = |
| 11296 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11297 | |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11298 | drm_connector_get(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11299 | } else { |
| 11300 | connector->base.state->best_encoder = NULL; |
| 11301 | connector->base.state->crtc = NULL; |
| 11302 | } |
| 11303 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11304 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11305 | } |
| 11306 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11307 | static int |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11308 | compute_sink_pipe_bpp(const struct drm_connector_state *conn_state, |
| 11309 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11310 | { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11311 | struct drm_connector *connector = conn_state->connector; |
| 11312 | const struct drm_display_info *info = &connector->display_info; |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11313 | int bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11314 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11315 | switch (conn_state->max_bpc) { |
| 11316 | case 6 ... 7: |
| 11317 | bpp = 6 * 3; |
| 11318 | break; |
| 11319 | case 8 ... 9: |
| 11320 | bpp = 8 * 3; |
| 11321 | break; |
| 11322 | case 10 ... 11: |
| 11323 | bpp = 10 * 3; |
| 11324 | break; |
| 11325 | case 12: |
| 11326 | bpp = 12 * 3; |
| 11327 | break; |
| 11328 | default: |
| 11329 | return -EINVAL; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11330 | } |
| 11331 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11332 | if (bpp < pipe_config->pipe_bpp) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11333 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of " |
| 11334 | "EDID bpp %d, requested bpp %d, max platform bpp %d\n", |
| 11335 | connector->base.id, connector->name, |
| 11336 | bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc, |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11337 | pipe_config->pipe_bpp); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11338 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11339 | pipe_config->pipe_bpp = bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11340 | } |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11341 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11342 | return 0; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11343 | } |
| 11344 | |
| 11345 | static int |
| 11346 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11347 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11348 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11349 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11350 | struct drm_atomic_state *state = pipe_config->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11351 | struct drm_connector *connector; |
| 11352 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11353 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11354 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11355 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 11356 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11357 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11358 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11359 | bpp = 12*3; |
| 11360 | else |
| 11361 | bpp = 8*3; |
| 11362 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11363 | pipe_config->pipe_bpp = bpp; |
| 11364 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11365 | /* Clamp display bpp to connector max bpp */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11366 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11367 | int ret; |
| 11368 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11369 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11370 | continue; |
| 11371 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11372 | ret = compute_sink_pipe_bpp(connector_state, pipe_config); |
| 11373 | if (ret) |
| 11374 | return ret; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11375 | } |
| 11376 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11377 | return 0; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11378 | } |
| 11379 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11380 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11381 | { |
| 11382 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11383 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11384 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11385 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11386 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11387 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11388 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11389 | } |
| 11390 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11391 | static inline void |
| 11392 | 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] | 11393 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11394 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11395 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11396 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11397 | m_n->gmch_m, m_n->gmch_n, |
| 11398 | m_n->link_m, m_n->link_n, m_n->tu); |
| 11399 | } |
| 11400 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11401 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 11402 | |
| 11403 | static const char * const output_type_str[] = { |
| 11404 | OUTPUT_TYPE(UNUSED), |
| 11405 | OUTPUT_TYPE(ANALOG), |
| 11406 | OUTPUT_TYPE(DVO), |
| 11407 | OUTPUT_TYPE(SDVO), |
| 11408 | OUTPUT_TYPE(LVDS), |
| 11409 | OUTPUT_TYPE(TVOUT), |
| 11410 | OUTPUT_TYPE(HDMI), |
| 11411 | OUTPUT_TYPE(DP), |
| 11412 | OUTPUT_TYPE(EDP), |
| 11413 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11414 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11415 | OUTPUT_TYPE(DP_MST), |
| 11416 | }; |
| 11417 | |
| 11418 | #undef OUTPUT_TYPE |
| 11419 | |
| 11420 | static void snprintf_output_types(char *buf, size_t len, |
| 11421 | unsigned int output_types) |
| 11422 | { |
| 11423 | char *str = buf; |
| 11424 | int i; |
| 11425 | |
| 11426 | str[0] = '\0'; |
| 11427 | |
| 11428 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 11429 | int r; |
| 11430 | |
| 11431 | if ((output_types & BIT(i)) == 0) |
| 11432 | continue; |
| 11433 | |
| 11434 | r = snprintf(str, len, "%s%s", |
| 11435 | str != buf ? "," : "", output_type_str[i]); |
| 11436 | if (r >= len) |
| 11437 | break; |
| 11438 | str += r; |
| 11439 | len -= r; |
| 11440 | |
| 11441 | output_types &= ~BIT(i); |
| 11442 | } |
| 11443 | |
| 11444 | WARN_ON_ONCE(output_types != 0); |
| 11445 | } |
| 11446 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11447 | static const char * const output_format_str[] = { |
| 11448 | [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid", |
| 11449 | [INTEL_OUTPUT_FORMAT_RGB] = "RGB", |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11450 | [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0", |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 11451 | [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4", |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11452 | }; |
| 11453 | |
| 11454 | static const char *output_formats(enum intel_output_format format) |
| 11455 | { |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11456 | if (format >= ARRAY_SIZE(output_format_str)) |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11457 | format = INTEL_OUTPUT_FORMAT_INVALID; |
| 11458 | return output_format_str[format]; |
| 11459 | } |
| 11460 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11461 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11462 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11463 | const char *context) |
| 11464 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11465 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11466 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11467 | struct drm_plane *plane; |
| 11468 | struct intel_plane *intel_plane; |
| 11469 | struct intel_plane_state *state; |
| 11470 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11471 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11472 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 11473 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 11474 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11475 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11476 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 11477 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 11478 | buf, pipe_config->output_types); |
| 11479 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11480 | DRM_DEBUG_KMS("output format: %s\n", |
| 11481 | output_formats(pipe_config->output_format)); |
| 11482 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11483 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 11484 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11485 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11486 | |
| 11487 | if (pipe_config->has_pch_encoder) |
| 11488 | intel_dump_m_n_config(pipe_config, "fdi", |
| 11489 | pipe_config->fdi_lanes, |
| 11490 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11491 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11492 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11493 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 11494 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 11495 | if (pipe_config->has_drrs) |
| 11496 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 11497 | pipe_config->lane_count, |
| 11498 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11499 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11500 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11501 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11502 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11503 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11504 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11505 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11506 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11507 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11508 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11509 | 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] | 11510 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11511 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 11512 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11513 | |
| 11514 | if (INTEL_GEN(dev_priv) >= 9) |
| 11515 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11516 | crtc->num_scalers, |
| 11517 | pipe_config->scaler_state.scaler_users, |
| 11518 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11519 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 11520 | if (HAS_GMCH(dev_priv)) |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11521 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11522 | pipe_config->gmch_pfit.control, |
| 11523 | pipe_config->gmch_pfit.pgm_ratios, |
| 11524 | pipe_config->gmch_pfit.lvds_border_bits); |
| 11525 | else |
| 11526 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 11527 | pipe_config->pch_pfit.pos, |
| 11528 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 11529 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11530 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11531 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 11532 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11533 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 11534 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11535 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11536 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11537 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11538 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11539 | intel_plane = to_intel_plane(plane); |
| 11540 | if (intel_plane->pipe != crtc->pipe) |
| 11541 | continue; |
| 11542 | |
| 11543 | state = to_intel_plane_state(plane->state); |
| 11544 | fb = state->base.fb; |
| 11545 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 11546 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 11547 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11548 | continue; |
| 11549 | } |
| 11550 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11551 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 11552 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11553 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 11554 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11555 | if (INTEL_GEN(dev_priv) >= 9) |
| 11556 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 11557 | state->scaler_id, |
| 11558 | state->base.src.x1 >> 16, |
| 11559 | state->base.src.y1 >> 16, |
| 11560 | drm_rect_width(&state->base.src) >> 16, |
| 11561 | drm_rect_height(&state->base.src) >> 16, |
| 11562 | state->base.dst.x1, state->base.dst.y1, |
| 11563 | drm_rect_width(&state->base.dst), |
| 11564 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11565 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11566 | } |
| 11567 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11568 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11569 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11570 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11571 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11572 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11573 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11574 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11575 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11576 | |
| 11577 | /* |
| 11578 | * Walk the connector list instead of the encoder |
| 11579 | * list to detect the problem on ddi platforms |
| 11580 | * where there's just one encoder per digital port. |
| 11581 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11582 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11583 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11584 | struct drm_connector_state *connector_state; |
| 11585 | struct intel_encoder *encoder; |
| 11586 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 11587 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11588 | if (!connector_state) |
| 11589 | connector_state = connector->state; |
| 11590 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11591 | if (!connector_state->best_encoder) |
| 11592 | continue; |
| 11593 | |
| 11594 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11595 | |
| 11596 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11597 | |
| 11598 | switch (encoder->type) { |
| 11599 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11600 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11601 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11602 | break; |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 11603 | /* else: fall through */ |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 11604 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11605 | case INTEL_OUTPUT_HDMI: |
| 11606 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11607 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11608 | |
| 11609 | /* the same port mustn't appear more than once */ |
| 11610 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11611 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11612 | |
| 11613 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11614 | break; |
| 11615 | case INTEL_OUTPUT_DP_MST: |
| 11616 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11617 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11618 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11619 | default: |
| 11620 | break; |
| 11621 | } |
| 11622 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11623 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11624 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11625 | /* can't mix MST and SST/HDMI on the same port */ |
| 11626 | if (used_ports & used_mst_ports) |
| 11627 | return false; |
| 11628 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11629 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11630 | } |
| 11631 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11632 | static int |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11633 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11634 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11635 | struct drm_i915_private *dev_priv = |
| 11636 | to_i915(crtc_state->base.crtc->dev); |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11637 | struct intel_crtc_state *saved_state; |
| 11638 | |
| 11639 | saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL); |
| 11640 | if (!saved_state) |
| 11641 | return -ENOMEM; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11642 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 11643 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 11644 | * kzalloc'd. Code that depends on any field being zero should be |
| 11645 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 11646 | * only fields that are know to not cause problems are preserved. */ |
| 11647 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11648 | saved_state->scaler_state = crtc_state->scaler_state; |
| 11649 | saved_state->shared_dpll = crtc_state->shared_dpll; |
| 11650 | saved_state->dpll_hw_state = crtc_state->dpll_hw_state; |
| 11651 | saved_state->pch_pfit.force_thru = crtc_state->pch_pfit.force_thru; |
| 11652 | saved_state->ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11653 | if (IS_G4X(dev_priv) || |
| 11654 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11655 | saved_state->wm = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11656 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11657 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 11658 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11659 | memcpy(&crtc_state->base + 1, &saved_state->base + 1, |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11660 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11661 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11662 | kfree(saved_state); |
| 11663 | return 0; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11664 | } |
| 11665 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11666 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11667 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11668 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11669 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11670 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11671 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11672 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11673 | struct drm_connector_state *connector_state; |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11674 | int base_bpp, ret; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11675 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11676 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11677 | |
Chris Wilson | f81b845 | 2019-02-05 09:27:59 +0000 | [diff] [blame] | 11678 | ret = clear_intel_crtc_state(pipe_config); |
| 11679 | if (ret) |
| 11680 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11681 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11682 | pipe_config->cpu_transcoder = |
| 11683 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11684 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11685 | /* |
| 11686 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11687 | * positive or negative polarity is requested, treat this as meaning |
| 11688 | * negative polarity. |
| 11689 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11690 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11691 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11692 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11693 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11694 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11695 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11696 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11697 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11698 | ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11699 | pipe_config); |
| 11700 | if (ret) |
| 11701 | return ret; |
| 11702 | |
| 11703 | base_bpp = pipe_config->pipe_bpp; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11704 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11705 | /* |
| 11706 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11707 | * increase the actual pipe size due to the frame doubling and |
| 11708 | * insertion of additional space for blanks between the frame. This |
| 11709 | * is stored in the crtc timings. We use the requested mode to do this |
| 11710 | * computation to clearly distinguish it from the adjusted mode, which |
| 11711 | * can be changed by the connectors in the below retry loop. |
| 11712 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 11713 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11714 | &pipe_config->pipe_src_w, |
| 11715 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11716 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11717 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11718 | if (connector_state->crtc != crtc) |
| 11719 | continue; |
| 11720 | |
| 11721 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11722 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11723 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11724 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11725 | return -EINVAL; |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11726 | } |
| 11727 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11728 | /* |
| 11729 | * Determine output_types before calling the .compute_config() |
| 11730 | * hooks so that the hooks can use this information safely. |
| 11731 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11732 | if (encoder->compute_output_type) |
| 11733 | pipe_config->output_types |= |
| 11734 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11735 | connector_state)); |
| 11736 | else |
| 11737 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11738 | } |
| 11739 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11740 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11741 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11742 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11743 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11744 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11745 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11746 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11747 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11748 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11749 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11750 | * adjust it according to limitations or connector properties, and also |
| 11751 | * a chance to reject the mode entirely. |
| 11752 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11753 | 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] | 11754 | if (connector_state->crtc != crtc) |
| 11755 | continue; |
| 11756 | |
| 11757 | encoder = to_intel_encoder(connector_state->best_encoder); |
Lyude Paul | 204474a | 2019-01-15 15:08:00 -0500 | [diff] [blame] | 11758 | ret = encoder->compute_config(encoder, pipe_config, |
| 11759 | connector_state); |
| 11760 | if (ret < 0) { |
| 11761 | if (ret != -EDEADLK) |
| 11762 | DRM_DEBUG_KMS("Encoder config failure: %d\n", |
| 11763 | ret); |
| 11764 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11765 | } |
| 11766 | } |
| 11767 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11768 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11769 | * done afterwards in case the encoder adjusts the mode. */ |
| 11770 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11771 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11772 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11773 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11774 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 11775 | if (ret == -EDEADLK) |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11776 | return ret; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11777 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11778 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11779 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11780 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11781 | |
| 11782 | if (ret == RETRY) { |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11783 | if (WARN(!retry, "loop in pipe configuration computation\n")) |
| 11784 | return -EINVAL; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11785 | |
| 11786 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11787 | retry = false; |
| 11788 | goto encoder_retry; |
| 11789 | } |
| 11790 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11791 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11792 | * only enable it on 6bpc panels and when its not a compliance |
| 11793 | * test requesting 6bpc video pattern. |
| 11794 | */ |
| 11795 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11796 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11797 | 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] | 11798 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11799 | |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11800 | return 0; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11801 | } |
| 11802 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11803 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11804 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11805 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11806 | |
| 11807 | if (clock1 == clock2) |
| 11808 | return true; |
| 11809 | |
| 11810 | if (!clock1 || !clock2) |
| 11811 | return false; |
| 11812 | |
| 11813 | diff = abs(clock1 - clock2); |
| 11814 | |
| 11815 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11816 | return true; |
| 11817 | |
| 11818 | return false; |
| 11819 | } |
| 11820 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11821 | static bool |
| 11822 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11823 | unsigned int m2, unsigned int n2, |
| 11824 | bool exact) |
| 11825 | { |
| 11826 | if (m == m2 && n == n2) |
| 11827 | return true; |
| 11828 | |
| 11829 | if (exact || !m || !n || !m2 || !n2) |
| 11830 | return false; |
| 11831 | |
| 11832 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11833 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11834 | if (n > n2) { |
| 11835 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11836 | m2 <<= 1; |
| 11837 | n2 <<= 1; |
| 11838 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11839 | } else if (n < n2) { |
| 11840 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11841 | m <<= 1; |
| 11842 | n <<= 1; |
| 11843 | } |
| 11844 | } |
| 11845 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11846 | if (n != n2) |
| 11847 | return false; |
| 11848 | |
| 11849 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11850 | } |
| 11851 | |
| 11852 | static bool |
| 11853 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11854 | struct intel_link_m_n *m2_n2, |
| 11855 | bool adjust) |
| 11856 | { |
| 11857 | if (m_n->tu == m2_n2->tu && |
| 11858 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11859 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11860 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11861 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11862 | if (adjust) |
| 11863 | *m2_n2 = *m_n; |
| 11864 | |
| 11865 | return true; |
| 11866 | } |
| 11867 | |
| 11868 | return false; |
| 11869 | } |
| 11870 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11871 | static void __printf(3, 4) |
| 11872 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11873 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11874 | struct va_format vaf; |
| 11875 | va_list args; |
| 11876 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11877 | va_start(args, format); |
| 11878 | vaf.fmt = format; |
| 11879 | vaf.va = &args; |
| 11880 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11881 | if (adjust) |
| 11882 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11883 | else |
| 11884 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11885 | |
| 11886 | va_end(args); |
| 11887 | } |
| 11888 | |
Hans de Goede | 3d6535c | 2019-01-24 14:01:14 +0100 | [diff] [blame] | 11889 | static bool fastboot_enabled(struct drm_i915_private *dev_priv) |
| 11890 | { |
| 11891 | if (i915_modparams.fastboot != -1) |
| 11892 | return i915_modparams.fastboot; |
| 11893 | |
| 11894 | /* Enable fastboot by default on Skylake and newer */ |
Hans de Goede | 7360c9f | 2019-01-29 15:22:37 +0100 | [diff] [blame] | 11895 | if (INTEL_GEN(dev_priv) >= 9) |
| 11896 | return true; |
| 11897 | |
| 11898 | /* Enable fastboot by default on VLV and CHV */ |
| 11899 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 11900 | return true; |
| 11901 | |
| 11902 | /* Disabled by default on all others */ |
| 11903 | return false; |
Hans de Goede | 3d6535c | 2019-01-24 14:01:14 +0100 | [diff] [blame] | 11904 | } |
| 11905 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11906 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11907 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11908 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11909 | struct intel_crtc_state *pipe_config, |
| 11910 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11911 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11912 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11913 | bool fixup_inherited = adjust && |
| 11914 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11915 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11916 | |
Hans de Goede | 3d6535c | 2019-01-24 14:01:14 +0100 | [diff] [blame] | 11917 | if (fixup_inherited && !fastboot_enabled(dev_priv)) { |
Maarten Lankhorst | d19f958 | 2019-01-08 17:08:40 +0100 | [diff] [blame] | 11918 | DRM_DEBUG_KMS("initial modeset and fastboot not set\n"); |
| 11919 | ret = false; |
| 11920 | } |
| 11921 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11922 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11923 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11924 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11925 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11926 | current_config->name, \ |
| 11927 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11928 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11929 | } \ |
| 11930 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11931 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11932 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11933 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11934 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11935 | "(expected %i, found %i)\n", \ |
| 11936 | current_config->name, \ |
| 11937 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11938 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11939 | } \ |
| 11940 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11941 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11942 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11943 | if (current_config->name != pipe_config->name) { \ |
| 11944 | pipe_config_err(adjust, __stringify(name), \ |
| 11945 | "(expected %s, found %s)\n", \ |
| 11946 | yesno(current_config->name), \ |
| 11947 | yesno(pipe_config->name)); \ |
| 11948 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11949 | } \ |
| 11950 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11951 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11952 | /* |
| 11953 | * Checks state where we only read out the enabling, but not the entire |
| 11954 | * state itself (like full infoframes or ELD for audio). These states |
| 11955 | * require a full modeset on bootup to fix up. |
| 11956 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11957 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11958 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11959 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11960 | } else { \ |
| 11961 | pipe_config_err(adjust, __stringify(name), \ |
| 11962 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11963 | yesno(current_config->name), \ |
| 11964 | yesno(pipe_config->name)); \ |
| 11965 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11966 | } \ |
| 11967 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11968 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11969 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11970 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11971 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11972 | "(expected %p, found %p)\n", \ |
| 11973 | current_config->name, \ |
| 11974 | pipe_config->name); \ |
| 11975 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11976 | } \ |
| 11977 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11978 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11979 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11980 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11981 | &pipe_config->name,\ |
| 11982 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11983 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11984 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11985 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11986 | current_config->name.tu, \ |
| 11987 | current_config->name.gmch_m, \ |
| 11988 | current_config->name.gmch_n, \ |
| 11989 | current_config->name.link_m, \ |
| 11990 | current_config->name.link_n, \ |
| 11991 | pipe_config->name.tu, \ |
| 11992 | pipe_config->name.gmch_m, \ |
| 11993 | pipe_config->name.gmch_n, \ |
| 11994 | pipe_config->name.link_m, \ |
| 11995 | pipe_config->name.link_n); \ |
| 11996 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11997 | } \ |
| 11998 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11999 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 12000 | /* This is required for BDW+ where there is only one set of registers for |
| 12001 | * switching between high and low RR. |
| 12002 | * This macro can be used whenever a comparison has to be made between one |
| 12003 | * hw state and multiple sw state variables. |
| 12004 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12005 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12006 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12007 | &pipe_config->name, adjust) && \ |
| 12008 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 12009 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 12010 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12011 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12012 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 12013 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12014 | current_config->name.tu, \ |
| 12015 | current_config->name.gmch_m, \ |
| 12016 | current_config->name.gmch_n, \ |
| 12017 | current_config->name.link_m, \ |
| 12018 | current_config->name.link_n, \ |
| 12019 | current_config->alt_name.tu, \ |
| 12020 | current_config->alt_name.gmch_m, \ |
| 12021 | current_config->alt_name.gmch_n, \ |
| 12022 | current_config->alt_name.link_m, \ |
| 12023 | current_config->alt_name.link_n, \ |
| 12024 | pipe_config->name.tu, \ |
| 12025 | pipe_config->name.gmch_m, \ |
| 12026 | pipe_config->name.gmch_n, \ |
| 12027 | pipe_config->name.link_m, \ |
| 12028 | pipe_config->name.link_n); \ |
| 12029 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12030 | } \ |
| 12031 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 12032 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12033 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12034 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 12035 | pipe_config_err(adjust, __stringify(name), \ |
| 12036 | "(%x) (expected %i, found %i)\n", \ |
| 12037 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12038 | current_config->name & (mask), \ |
| 12039 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12040 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12041 | } \ |
| 12042 | } while (0) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12043 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12044 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12045 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 12046 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12047 | "(expected %i, found %i)\n", \ |
| 12048 | current_config->name, \ |
| 12049 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12050 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 12051 | } \ |
| 12052 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12053 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12054 | #define PIPE_CONF_QUIRK(quirk) \ |
| 12055 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 12056 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 12057 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 12058 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12059 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12060 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12061 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12062 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12063 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 12064 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12065 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12066 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12067 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12068 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12069 | if (current_config->has_drrs) |
| 12070 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 12071 | } else |
| 12072 | 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] | 12073 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 12074 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 12075 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12076 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 12077 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 12078 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 12079 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 12080 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 12081 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12082 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12083 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 12084 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 12085 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 12086 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 12087 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 12088 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12089 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 12090 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 12091 | PIPE_CONF_CHECK_I(output_format); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12092 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 12093 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 12094 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12095 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 12096 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12097 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 12098 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 12099 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12100 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 12101 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 12102 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12103 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12104 | DRM_MODE_FLAG_INTERLACE); |
| 12105 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12106 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12107 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12108 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12109 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12110 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12111 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12112 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12113 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12114 | DRM_MODE_FLAG_NVSYNC); |
| 12115 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12116 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12117 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 12118 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12119 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 12120 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12121 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 12122 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12123 | if (!adjust) { |
| 12124 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 12125 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 12126 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12127 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12128 | if (current_config->pch_pfit.enabled) { |
| 12129 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 12130 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 12131 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12132 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12133 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12134 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Ville Syrjälä | 9d5441d | 2019-02-07 22:21:40 +0200 | [diff] [blame] | 12135 | |
| 12136 | PIPE_CONF_CHECK_X(gamma_mode); |
Ville Syrjälä | 5f29ab2 | 2019-02-07 22:39:13 +0200 | [diff] [blame] | 12137 | PIPE_CONF_CHECK_BOOL(gamma_enable); |
Ville Syrjälä | 8271b2e | 2019-02-07 22:21:42 +0200 | [diff] [blame] | 12138 | PIPE_CONF_CHECK_BOOL(csc_enable); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12139 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 12140 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12141 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 12142 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12143 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12144 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 12145 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12146 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 12147 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 12148 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12149 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 12150 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 12151 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 12152 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 12153 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 12154 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 12155 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 12156 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 12157 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 12158 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 12159 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 12160 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 12161 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 12162 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 12163 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 12164 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 12165 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 12166 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 12167 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 12168 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 12169 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 12170 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 12171 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 12172 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 12173 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 12174 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12175 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 12176 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 12177 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 12178 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 12179 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 12180 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 12181 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12182 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 12183 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12184 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12185 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 12186 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12187 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12188 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 12189 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 12190 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12191 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12192 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12193 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12194 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 12195 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12196 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12197 | } |
| 12198 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12199 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 12200 | const struct intel_crtc_state *pipe_config) |
| 12201 | { |
| 12202 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 12203 | 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] | 12204 | &pipe_config->fdi_m_n); |
| 12205 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 12206 | |
| 12207 | /* |
| 12208 | * FDI already provided one idea for the dotclock. |
| 12209 | * Yell if the encoder disagrees. |
| 12210 | */ |
| 12211 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 12212 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 12213 | fdi_dotclock, dotclock); |
| 12214 | } |
| 12215 | } |
| 12216 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12217 | static void verify_wm_state(struct drm_crtc *crtc, |
| 12218 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12219 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12220 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12221 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12222 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 12223 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 12224 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12225 | struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES]; |
| 12226 | struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12227 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12228 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12229 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12230 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12231 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12232 | return; |
| 12233 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12234 | skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 12235 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12236 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12237 | skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv); |
| 12238 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12239 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12240 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12241 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 12242 | if (INTEL_GEN(dev_priv) >= 11) |
| 12243 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 12244 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 12245 | sw_ddb->enabled_slices, |
| 12246 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12247 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 12248 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12249 | hw_plane_wm = &hw_wm.planes[plane]; |
| 12250 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12251 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12252 | /* Watermarks */ |
| 12253 | for (level = 0; level <= max_level; level++) { |
| 12254 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12255 | &sw_plane_wm->wm[level])) |
| 12256 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12257 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12258 | 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", |
| 12259 | pipe_name(pipe), plane + 1, level, |
| 12260 | sw_plane_wm->wm[level].plane_en, |
| 12261 | sw_plane_wm->wm[level].plane_res_b, |
| 12262 | sw_plane_wm->wm[level].plane_res_l, |
| 12263 | hw_plane_wm->wm[level].plane_en, |
| 12264 | hw_plane_wm->wm[level].plane_res_b, |
| 12265 | hw_plane_wm->wm[level].plane_res_l); |
| 12266 | } |
| 12267 | |
| 12268 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12269 | &sw_plane_wm->trans_wm)) { |
| 12270 | 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", |
| 12271 | pipe_name(pipe), plane + 1, |
| 12272 | sw_plane_wm->trans_wm.plane_en, |
| 12273 | sw_plane_wm->trans_wm.plane_res_b, |
| 12274 | sw_plane_wm->trans_wm.plane_res_l, |
| 12275 | hw_plane_wm->trans_wm.plane_en, |
| 12276 | hw_plane_wm->trans_wm.plane_res_b, |
| 12277 | hw_plane_wm->trans_wm.plane_res_l); |
| 12278 | } |
| 12279 | |
| 12280 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12281 | hw_ddb_entry = &hw_ddb_y[plane]; |
| 12282 | sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane]; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12283 | |
| 12284 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12285 | 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] | 12286 | pipe_name(pipe), plane + 1, |
| 12287 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12288 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 12289 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12290 | } |
| 12291 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12292 | /* |
| 12293 | * cursor |
| 12294 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 12295 | * allocation. In that case since the ddb allocation will be updated |
| 12296 | * once the plane becomes visible, we can skip this check |
| 12297 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 12298 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12299 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 12300 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12301 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12302 | /* Watermarks */ |
| 12303 | for (level = 0; level <= max_level; level++) { |
| 12304 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12305 | &sw_plane_wm->wm[level])) |
| 12306 | continue; |
| 12307 | |
| 12308 | 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", |
| 12309 | pipe_name(pipe), level, |
| 12310 | sw_plane_wm->wm[level].plane_en, |
| 12311 | sw_plane_wm->wm[level].plane_res_b, |
| 12312 | sw_plane_wm->wm[level].plane_res_l, |
| 12313 | hw_plane_wm->wm[level].plane_en, |
| 12314 | hw_plane_wm->wm[level].plane_res_b, |
| 12315 | hw_plane_wm->wm[level].plane_res_l); |
| 12316 | } |
| 12317 | |
| 12318 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12319 | &sw_plane_wm->trans_wm)) { |
| 12320 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12321 | pipe_name(pipe), |
| 12322 | sw_plane_wm->trans_wm.plane_en, |
| 12323 | sw_plane_wm->trans_wm.plane_res_b, |
| 12324 | sw_plane_wm->trans_wm.plane_res_l, |
| 12325 | hw_plane_wm->trans_wm.plane_en, |
| 12326 | hw_plane_wm->trans_wm.plane_res_b, |
| 12327 | hw_plane_wm->trans_wm.plane_res_l); |
| 12328 | } |
| 12329 | |
| 12330 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12331 | hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR]; |
| 12332 | sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR]; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12333 | |
| 12334 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12335 | 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] | 12336 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12337 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12338 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12339 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12340 | } |
| 12341 | } |
| 12342 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12343 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12344 | verify_connector_state(struct drm_device *dev, |
| 12345 | struct drm_atomic_state *state, |
| 12346 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12347 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12348 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12349 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12350 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12351 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12352 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12353 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12354 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12355 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12356 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12357 | continue; |
| 12358 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12359 | if (crtc) |
| 12360 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 12361 | |
| 12362 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12363 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12364 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12365 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12366 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12367 | } |
| 12368 | |
| 12369 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12370 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12371 | { |
| 12372 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12373 | struct drm_connector *connector; |
| 12374 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 12375 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12376 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12377 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12378 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12379 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12380 | |
| 12381 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12382 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12383 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12384 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12385 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 12386 | new_conn_state, i) { |
| 12387 | if (old_conn_state->best_encoder == &encoder->base) |
| 12388 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12389 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12390 | if (new_conn_state->best_encoder != &encoder->base) |
| 12391 | continue; |
| 12392 | found = enabled = true; |
| 12393 | |
| 12394 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12395 | encoder->base.crtc, |
| 12396 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12397 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12398 | |
| 12399 | if (!found) |
| 12400 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12401 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12402 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12403 | "encoder's enabled state mismatch " |
| 12404 | "(expected %i, found %i)\n", |
| 12405 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12406 | |
| 12407 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12408 | bool active; |
| 12409 | |
| 12410 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12411 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12412 | "encoder detached but still enabled on pipe %c.\n", |
| 12413 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12414 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12415 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12416 | } |
| 12417 | |
| 12418 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12419 | verify_crtc_state(struct drm_crtc *crtc, |
| 12420 | struct drm_crtc_state *old_crtc_state, |
| 12421 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12422 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12423 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12424 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12425 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12426 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12427 | struct intel_crtc_state *pipe_config, *sw_config; |
| 12428 | struct drm_atomic_state *old_state; |
| 12429 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12430 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12431 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 12432 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12433 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12434 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12435 | pipe_config->base.crtc = crtc; |
| 12436 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12437 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12438 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12439 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12440 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12441 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 12442 | /* we keep both pipes enabled on 830 */ |
| 12443 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12444 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12445 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12446 | I915_STATE_WARN(new_crtc_state->active != active, |
| 12447 | "crtc active state doesn't match with hw state " |
| 12448 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12449 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12450 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 12451 | "transitional active state does not match atomic hw state " |
| 12452 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12453 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12454 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12455 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12456 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12457 | active = encoder->get_hw_state(encoder, &pipe); |
| 12458 | I915_STATE_WARN(active != new_crtc_state->active, |
| 12459 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12460 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12461 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12462 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12463 | "Encoder connected to wrong pipe %c\n", |
| 12464 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12465 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 12466 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12467 | encoder->get_config(encoder, pipe_config); |
| 12468 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12469 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12470 | intel_crtc_compute_pixel_rate(pipe_config); |
| 12471 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12472 | if (!new_crtc_state->active) |
| 12473 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12474 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12475 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12476 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12477 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12478 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12479 | pipe_config, false)) { |
| 12480 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 12481 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 12482 | "[hw state]"); |
| 12483 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 12484 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12485 | } |
| 12486 | } |
| 12487 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12488 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12489 | intel_verify_planes(struct intel_atomic_state *state) |
| 12490 | { |
| 12491 | struct intel_plane *plane; |
| 12492 | const struct intel_plane_state *plane_state; |
| 12493 | int i; |
| 12494 | |
| 12495 | for_each_new_intel_plane_in_state(state, plane, |
| 12496 | plane_state, i) |
| 12497 | assert_plane(plane, plane_state->base.visible); |
| 12498 | } |
| 12499 | |
| 12500 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12501 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 12502 | struct intel_shared_dpll *pll, |
| 12503 | struct drm_crtc *crtc, |
| 12504 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12505 | { |
| 12506 | struct intel_dpll_hw_state dpll_hw_state; |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12507 | unsigned int crtc_mask; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12508 | bool active; |
| 12509 | |
| 12510 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12511 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 12512 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12513 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 12514 | 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] | 12515 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 12516 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12517 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12518 | "pll in active use but not on in sw tracking\n"); |
| 12519 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12520 | "pll is on but not used by any active crtc\n"); |
| 12521 | I915_STATE_WARN(pll->on != active, |
| 12522 | "pll on state mismatch (expected %i, found %i)\n", |
| 12523 | pll->on, active); |
| 12524 | } |
| 12525 | |
| 12526 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12527 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12528 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12529 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12530 | |
| 12531 | return; |
| 12532 | } |
| 12533 | |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12534 | crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12535 | |
| 12536 | if (new_state->active) |
| 12537 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 12538 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 12539 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12540 | else |
| 12541 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12542 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 12543 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12544 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12545 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12546 | "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] | 12547 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12548 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12549 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12550 | &dpll_hw_state, |
| 12551 | sizeof(dpll_hw_state)), |
| 12552 | "pll hw state mismatch\n"); |
| 12553 | } |
| 12554 | |
| 12555 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12556 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 12557 | struct drm_crtc_state *old_crtc_state, |
| 12558 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12559 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12560 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12561 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 12562 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 12563 | |
| 12564 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12565 | 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] | 12566 | |
| 12567 | if (old_state->shared_dpll && |
| 12568 | old_state->shared_dpll != new_state->shared_dpll) { |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12569 | unsigned int crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12570 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 12571 | |
| 12572 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12573 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 12574 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12575 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12576 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 12577 | pipe_name(drm_crtc_index(crtc))); |
| 12578 | } |
| 12579 | } |
| 12580 | |
| 12581 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12582 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12583 | struct drm_atomic_state *state, |
| 12584 | struct drm_crtc_state *old_state, |
| 12585 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12586 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12587 | if (!needs_modeset(new_state) && |
| 12588 | !to_intel_crtc_state(new_state)->update_pipe) |
| 12589 | return; |
| 12590 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12591 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12592 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12593 | verify_crtc_state(crtc, old_state, new_state); |
| 12594 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12595 | } |
| 12596 | |
| 12597 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12598 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12599 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12600 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12601 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12602 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12603 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12604 | 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] | 12605 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12606 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12607 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12608 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 12609 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12610 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12611 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12612 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12613 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12614 | } |
| 12615 | |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12616 | static void update_scanline_offset(const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12617 | { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12618 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12619 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12620 | |
| 12621 | /* |
| 12622 | * The scanline counter increments at the leading edge of hsync. |
| 12623 | * |
| 12624 | * On most platforms it starts counting from vtotal-1 on the |
| 12625 | * first active line. That means the scanline counter value is |
| 12626 | * always one less than what we would expect. Ie. just after |
| 12627 | * start of vblank, which also occurs at start of hsync (on the |
| 12628 | * last active line), the scanline counter will read vblank_start-1. |
| 12629 | * |
| 12630 | * On gen2 the scanline counter starts counting from 1 instead |
| 12631 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12632 | * to keep the value positive), instead of adding one. |
| 12633 | * |
| 12634 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12635 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12636 | * there's an extra 1 line difference. So we need to add two instead of |
| 12637 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 12638 | * |
| 12639 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 12640 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 12641 | * that means we can't tell whether we're in vblank or not while |
| 12642 | * we're on that particular line. We must still set scanline_offset |
| 12643 | * to 1 so that the vblank timestamps come out correct when we query |
| 12644 | * the scanline counter from within the vblank interrupt handler. |
| 12645 | * However if queried just before the start of vblank we'll get an |
| 12646 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12647 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 12648 | if (IS_GEN(dev_priv, 2)) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12649 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12650 | int vtotal; |
| 12651 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12652 | vtotal = adjusted_mode->crtc_vtotal; |
| 12653 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12654 | vtotal /= 2; |
| 12655 | |
| 12656 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12657 | } else if (HAS_DDI(dev_priv) && |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12658 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12659 | crtc->scanline_offset = 2; |
| 12660 | } else |
| 12661 | crtc->scanline_offset = 1; |
| 12662 | } |
| 12663 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12664 | 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] | 12665 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12666 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12667 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12668 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12669 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12670 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12671 | |
| 12672 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12673 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12674 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12675 | 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] | 12676 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12677 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12678 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12679 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12680 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12681 | continue; |
| 12682 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12683 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12684 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12685 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12686 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12687 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 12688 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12689 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12690 | } |
| 12691 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12692 | /* |
| 12693 | * This implements the workaround described in the "notes" section of the mode |
| 12694 | * set sequence documentation. When going from no pipes or single pipe to |
| 12695 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12696 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12697 | */ |
| 12698 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12699 | { |
| 12700 | struct drm_crtc_state *crtc_state; |
| 12701 | struct intel_crtc *intel_crtc; |
| 12702 | struct drm_crtc *crtc; |
| 12703 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12704 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12705 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12706 | int i; |
| 12707 | |
| 12708 | /* 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] | 12709 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12710 | intel_crtc = to_intel_crtc(crtc); |
| 12711 | |
| 12712 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12713 | continue; |
| 12714 | |
| 12715 | if (first_crtc_state) { |
| 12716 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12717 | break; |
| 12718 | } else { |
| 12719 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12720 | first_pipe = intel_crtc->pipe; |
| 12721 | } |
| 12722 | } |
| 12723 | |
| 12724 | /* No workaround needed? */ |
| 12725 | if (!first_crtc_state) |
| 12726 | return 0; |
| 12727 | |
| 12728 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12729 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12730 | struct intel_crtc_state *pipe_config; |
| 12731 | |
| 12732 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12733 | if (IS_ERR(pipe_config)) |
| 12734 | return PTR_ERR(pipe_config); |
| 12735 | |
| 12736 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12737 | |
| 12738 | if (!pipe_config->base.active || |
| 12739 | needs_modeset(&pipe_config->base)) |
| 12740 | continue; |
| 12741 | |
| 12742 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12743 | if (enabled_pipe != INVALID_PIPE) |
| 12744 | return 0; |
| 12745 | |
| 12746 | enabled_pipe = intel_crtc->pipe; |
| 12747 | } |
| 12748 | |
| 12749 | if (enabled_pipe != INVALID_PIPE) |
| 12750 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12751 | else if (other_crtc_state) |
| 12752 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12753 | |
| 12754 | return 0; |
| 12755 | } |
| 12756 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12757 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12758 | { |
| 12759 | struct drm_crtc *crtc; |
| 12760 | |
| 12761 | /* Add all pipes to the state */ |
| 12762 | for_each_crtc(state->dev, crtc) { |
| 12763 | struct drm_crtc_state *crtc_state; |
| 12764 | |
| 12765 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12766 | if (IS_ERR(crtc_state)) |
| 12767 | return PTR_ERR(crtc_state); |
| 12768 | } |
| 12769 | |
| 12770 | return 0; |
| 12771 | } |
| 12772 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12773 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12774 | { |
| 12775 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12776 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12777 | /* |
| 12778 | * Add all pipes to the state, and force |
| 12779 | * a modeset on all the active ones. |
| 12780 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12781 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12782 | struct drm_crtc_state *crtc_state; |
| 12783 | int ret; |
| 12784 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12785 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12786 | if (IS_ERR(crtc_state)) |
| 12787 | return PTR_ERR(crtc_state); |
| 12788 | |
| 12789 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12790 | continue; |
| 12791 | |
| 12792 | crtc_state->mode_changed = true; |
| 12793 | |
| 12794 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12795 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12796 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12797 | |
| 12798 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12799 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12800 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12801 | } |
| 12802 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12803 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12804 | } |
| 12805 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12806 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12807 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12808 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12809 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12810 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12811 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12812 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12813 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12814 | if (!check_digital_port_conflicts(state)) { |
| 12815 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12816 | return -EINVAL; |
| 12817 | } |
| 12818 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12819 | intel_state->modeset = true; |
| 12820 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12821 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12822 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12823 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12824 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12825 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12826 | intel_state->active_crtcs |= 1 << i; |
| 12827 | else |
| 12828 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12829 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12830 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12831 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12832 | } |
| 12833 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12834 | /* |
| 12835 | * See if the config requires any additional preparation, e.g. |
| 12836 | * to adjust global state with pipes off. We need to do this |
| 12837 | * here so we can get the modeset_pipe updated config for the new |
| 12838 | * mode set on this crtc. For other crtcs we need to use the |
| 12839 | * adjusted_mode bits in the crtc directly. |
| 12840 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12841 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12842 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12843 | if (ret < 0) |
| 12844 | return ret; |
| 12845 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12846 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12847 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12848 | * holding all the crtc locks, even if we don't end up |
| 12849 | * touching the hardware |
| 12850 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12851 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12852 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12853 | ret = intel_lock_all_pipes(state); |
| 12854 | if (ret < 0) |
| 12855 | return ret; |
| 12856 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12857 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12858 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12859 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12860 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12861 | ret = intel_modeset_all_pipes(state); |
| 12862 | if (ret < 0) |
| 12863 | return ret; |
| 12864 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12865 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12866 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12867 | intel_state->cdclk.logical.cdclk, |
| 12868 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12869 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12870 | intel_state->cdclk.logical.voltage_level, |
| 12871 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12872 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12873 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12874 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12875 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12876 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12877 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12878 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12879 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12880 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12881 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12882 | } |
| 12883 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12884 | /* |
| 12885 | * Handle calculation of various watermark data at the end of the atomic check |
| 12886 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12887 | * handlers to ensure that all derived state has been updated. |
| 12888 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12889 | static int calc_watermark_data(struct intel_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12890 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12891 | struct drm_device *dev = state->base.dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12892 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12893 | |
| 12894 | /* Is there platform-specific watermark information to calculate? */ |
| 12895 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12896 | return dev_priv->display.compute_global_watermarks(state); |
| 12897 | |
| 12898 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12899 | } |
| 12900 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12901 | /** |
| 12902 | * intel_atomic_check - validate state object |
| 12903 | * @dev: drm device |
| 12904 | * @state: state to validate |
| 12905 | */ |
| 12906 | static int intel_atomic_check(struct drm_device *dev, |
| 12907 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12908 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12909 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12910 | 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] | 12911 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12912 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12913 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12914 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12915 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12916 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12917 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12918 | crtc_state, i) { |
| 12919 | if (crtc_state->mode.private_flags != |
| 12920 | old_crtc_state->mode.private_flags) |
| 12921 | crtc_state->mode_changed = true; |
| 12922 | } |
| 12923 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12924 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12925 | if (ret) |
| 12926 | return ret; |
| 12927 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12928 | 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] | 12929 | struct intel_crtc_state *pipe_config = |
| 12930 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12931 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12932 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12933 | continue; |
| 12934 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12935 | if (!crtc_state->enable) { |
| 12936 | any_ms = true; |
| 12937 | continue; |
| 12938 | } |
| 12939 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12940 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 12941 | if (ret == -EDEADLK) |
| 12942 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12943 | if (ret) { |
| 12944 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12945 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12946 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12947 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12948 | |
Maarten Lankhorst | d19f958 | 2019-01-08 17:08:40 +0100 | [diff] [blame] | 12949 | if (intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12950 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12951 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12952 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12953 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12954 | } |
| 12955 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12956 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12957 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12958 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12959 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12960 | needs_modeset(crtc_state) ? |
| 12961 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12962 | } |
| 12963 | |
Lyude Paul | eceae14 | 2019-01-10 19:53:41 -0500 | [diff] [blame] | 12964 | ret = drm_dp_mst_atomic_check(state); |
| 12965 | if (ret) |
| 12966 | return ret; |
| 12967 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12968 | if (any_ms) { |
| 12969 | ret = intel_modeset_checks(state); |
| 12970 | |
| 12971 | if (ret) |
| 12972 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12973 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12974 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12975 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12976 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 12977 | ret = icl_add_linked_planes(intel_state); |
| 12978 | if (ret) |
| 12979 | return ret; |
| 12980 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12981 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12982 | if (ret) |
| 12983 | return ret; |
| 12984 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12985 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12986 | return calc_watermark_data(intel_state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12987 | } |
| 12988 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12989 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12990 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12991 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12992 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12993 | } |
| 12994 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12995 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12996 | { |
| 12997 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 12998 | struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)]; |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12999 | |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 13000 | if (!vblank->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 13001 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 13002 | |
| 13003 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 13004 | } |
| 13005 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13006 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 13007 | struct drm_atomic_state *state, |
| 13008 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13009 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13010 | { |
| 13011 | struct drm_device *dev = crtc->dev; |
| 13012 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 13013 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13014 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 13015 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13016 | struct intel_plane_state *new_plane_state = |
| 13017 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 13018 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13019 | |
| 13020 | if (modeset) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 13021 | update_scanline_offset(pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13022 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 13023 | |
| 13024 | /* vblanks work again, re-enable pipe CRC. */ |
| 13025 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13026 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13027 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 13028 | pipe_config); |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 13029 | |
| 13030 | if (pipe_config->update_pipe) |
| 13031 | intel_encoders_update_pipe(crtc, pipe_config, state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13032 | } |
| 13033 | |
Maarten Lankhorst | 50c42fc | 2018-12-20 16:17:19 +0100 | [diff] [blame] | 13034 | if (pipe_config->update_pipe && !pipe_config->enable_fbc) |
| 13035 | intel_fbc_disable(intel_crtc); |
| 13036 | else if (new_plane_state) |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13037 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13038 | |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 13039 | intel_begin_crtc_commit(crtc, old_crtc_state); |
| 13040 | |
Ville Syrjälä | 5f2e511 | 2018-11-14 23:07:27 +0200 | [diff] [blame] | 13041 | if (INTEL_GEN(dev_priv) >= 9) |
| 13042 | skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
| 13043 | else |
| 13044 | i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 13045 | |
| 13046 | intel_finish_crtc_commit(crtc, old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13047 | } |
| 13048 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13049 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13050 | { |
| 13051 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13052 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13053 | int i; |
| 13054 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13055 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 13056 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13057 | continue; |
| 13058 | |
| 13059 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13060 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13061 | } |
| 13062 | } |
| 13063 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13064 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13065 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 13066 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13067 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13068 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13069 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13070 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13071 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13072 | unsigned int updated = 0; |
| 13073 | bool progress; |
| 13074 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13075 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 13076 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 13077 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13078 | struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13079 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13080 | 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] | 13081 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13082 | if (new_crtc_state->active) |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13083 | entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13084 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 13085 | /* If 2nd DBuf slice required, enable it here */ |
| 13086 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 13087 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 13088 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13089 | /* |
| 13090 | * Whenever the number of active pipes changes, we need to make sure we |
| 13091 | * update the pipes in the right order so that their ddb allocations |
| 13092 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 13093 | * cause pipe underruns and other bad stuff. |
| 13094 | */ |
| 13095 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13096 | progress = false; |
| 13097 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13098 | 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] | 13099 | bool vbl_wait = false; |
| 13100 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13101 | |
| 13102 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 13103 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13104 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13105 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13106 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13107 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 13108 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13109 | if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb, |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 13110 | entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13111 | INTEL_INFO(dev_priv)->num_pipes, i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13112 | continue; |
| 13113 | |
| 13114 | updated |= cmask; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 13115 | entries[i] = cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13116 | |
| 13117 | /* |
| 13118 | * If this is an already active pipe, it's DDB changed, |
| 13119 | * and this isn't the last pipe that needs updating |
| 13120 | * then we need to wait for a vblank to pass for the |
| 13121 | * new ddb allocation to take effect. |
| 13122 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 13123 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 13124 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13125 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13126 | intel_state->wm_results.dirty_pipes != updated) |
| 13127 | vbl_wait = true; |
| 13128 | |
| 13129 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13130 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13131 | |
| 13132 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 13133 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13134 | |
| 13135 | progress = true; |
| 13136 | } |
| 13137 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 13138 | |
| 13139 | /* If 2nd DBuf slice is no more required disable it */ |
| 13140 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 13141 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13142 | } |
| 13143 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 13144 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 13145 | { |
| 13146 | struct intel_atomic_state *state, *next; |
| 13147 | struct llist_node *freed; |
| 13148 | |
| 13149 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 13150 | llist_for_each_entry_safe(state, next, freed, freed) |
| 13151 | drm_atomic_state_put(&state->base); |
| 13152 | } |
| 13153 | |
| 13154 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 13155 | { |
| 13156 | struct drm_i915_private *dev_priv = |
| 13157 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 13158 | |
| 13159 | intel_atomic_helper_free_state(dev_priv); |
| 13160 | } |
| 13161 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 13162 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 13163 | { |
| 13164 | struct wait_queue_entry wait_fence, wait_reset; |
| 13165 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 13166 | |
| 13167 | init_wait_entry(&wait_fence, 0); |
| 13168 | init_wait_entry(&wait_reset, 0); |
| 13169 | for (;;) { |
| 13170 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 13171 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 13172 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 13173 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 13174 | |
| 13175 | |
| 13176 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 13177 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 13178 | break; |
| 13179 | |
| 13180 | schedule(); |
| 13181 | } |
| 13182 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 13183 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 13184 | } |
| 13185 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 13186 | static void intel_atomic_cleanup_work(struct work_struct *work) |
| 13187 | { |
| 13188 | struct drm_atomic_state *state = |
| 13189 | container_of(work, struct drm_atomic_state, commit_work); |
| 13190 | struct drm_i915_private *i915 = to_i915(state->dev); |
| 13191 | |
| 13192 | drm_atomic_helper_cleanup_planes(&i915->drm, state); |
| 13193 | drm_atomic_helper_commit_cleanup_done(state); |
| 13194 | drm_atomic_state_put(state); |
| 13195 | |
| 13196 | intel_atomic_helper_free_state(i915); |
| 13197 | } |
| 13198 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13199 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13200 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13201 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13202 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13203 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13204 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13205 | struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13206 | struct drm_crtc *crtc; |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13207 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 13208 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13209 | intel_wakeref_t wakeref = 0; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 13210 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13211 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 13212 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13213 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 13214 | drm_atomic_helper_wait_for_dependencies(state); |
| 13215 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13216 | if (intel_state->modeset) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13217 | wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13218 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13219 | 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] | 13220 | old_intel_crtc_state = to_intel_crtc_state(old_crtc_state); |
| 13221 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 13222 | intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13223 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13224 | if (needs_modeset(new_crtc_state) || |
| 13225 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13226 | |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13227 | put_domains[intel_crtc->pipe] = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13228 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13229 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13230 | } |
| 13231 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13232 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13233 | continue; |
| 13234 | |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13235 | intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13236 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13237 | if (old_crtc_state->active) { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 13238 | intel_crtc_disable_planes(intel_state, intel_crtc); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 13239 | |
| 13240 | /* |
| 13241 | * We need to disable pipe CRC before disabling the pipe, |
| 13242 | * or we race against vblank off. |
| 13243 | */ |
| 13244 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 13245 | |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13246 | dev_priv->display.crtc_disable(old_intel_crtc_state, state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13247 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 13248 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 13249 | intel_disable_shared_dpll(old_intel_crtc_state); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 13250 | |
| 13251 | /* |
| 13252 | * Underruns don't always raise |
| 13253 | * interrupts, so check manually. |
| 13254 | */ |
| 13255 | intel_check_cpu_fifo_underruns(dev_priv); |
| 13256 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13257 | |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 13258 | /* FIXME unify this for all platforms */ |
| 13259 | if (!new_crtc_state->active && |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 13260 | !HAS_GMCH(dev_priv) && |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 13261 | dev_priv->display.initial_watermarks) |
| 13262 | dev_priv->display.initial_watermarks(intel_state, |
| 13263 | new_intel_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13264 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13265 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13266 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 13267 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 13268 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 13269 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13270 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13271 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13272 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13273 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 13274 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 13275 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13276 | /* |
| 13277 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 13278 | * have more then one pipe enabled |
| 13279 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13280 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13281 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13282 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13283 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13284 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13285 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13286 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13287 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 13288 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13289 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13290 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13291 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13292 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13293 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13294 | spin_unlock_irq(&dev->event_lock); |
| 13295 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13296 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13297 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13298 | } |
| 13299 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13300 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13301 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13302 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13303 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 13304 | * already, but still need the state for the delayed optimization. To |
| 13305 | * fix this: |
| 13306 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 13307 | * - schedule that vblank worker _before_ calling hw_done |
| 13308 | * - at the start of commit_tail, cancel it _synchrously |
| 13309 | * - switch over to the vblank wait helper in the core after that since |
| 13310 | * we don't need out special handling any more. |
| 13311 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13312 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13313 | |
Ville Syrjälä | 051a6d8 | 2019-02-05 18:08:41 +0200 | [diff] [blame] | 13314 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 13315 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 13316 | |
| 13317 | if (new_crtc_state->active && |
| 13318 | !needs_modeset(new_crtc_state) && |
| 13319 | (new_intel_crtc_state->base.color_mgmt_changed || |
| 13320 | new_intel_crtc_state->update_pipe)) |
| 13321 | intel_color_load_luts(new_intel_crtc_state); |
| 13322 | } |
| 13323 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13324 | /* |
| 13325 | * Now that the vblank has passed, we can go ahead and program the |
| 13326 | * optimal watermarks on platforms that need two-step watermark |
| 13327 | * programming. |
| 13328 | * |
| 13329 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13330 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13331 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13332 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13333 | |
| 13334 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13335 | dev_priv->display.optimize_watermarks(intel_state, |
Maarten Lankhorst | a1cccdc | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13336 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13337 | } |
| 13338 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13339 | 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] | 13340 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13341 | |
| 13342 | if (put_domains[i]) |
| 13343 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13344 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13345 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13346 | } |
| 13347 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 13348 | if (intel_state->modeset) |
| 13349 | intel_verify_planes(intel_state); |
| 13350 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13351 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13352 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13353 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13354 | drm_atomic_helper_commit_hw_done(state); |
| 13355 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13356 | if (intel_state->modeset) { |
| 13357 | /* As one of the primary mmio accessors, KMS has a high |
| 13358 | * likelihood of triggering bugs in unclaimed access. After we |
| 13359 | * finish modesetting, see if an error has been flagged, and if |
| 13360 | * so enable debugging for the next modeset - and hope we catch |
| 13361 | * the culprit. |
| 13362 | */ |
| 13363 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13364 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13365 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13366 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 13367 | /* |
| 13368 | * Defer the cleanup of the old state to a separate worker to not |
| 13369 | * impede the current task (userspace for blocking modesets) that |
| 13370 | * are executed inline. For out-of-line asynchronous modesets/flips, |
| 13371 | * deferring to a new worker seems overkill, but we would place a |
| 13372 | * schedule point (cond_resched()) here anyway to keep latencies |
| 13373 | * down. |
| 13374 | */ |
| 13375 | INIT_WORK(&state->commit_work, intel_atomic_cleanup_work); |
Chris Wilson | 41db645 | 2018-07-12 12:57:29 +0100 | [diff] [blame] | 13376 | queue_work(system_highpri_wq, &state->commit_work); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13377 | } |
| 13378 | |
| 13379 | static void intel_atomic_commit_work(struct work_struct *work) |
| 13380 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13381 | struct drm_atomic_state *state = |
| 13382 | container_of(work, struct drm_atomic_state, commit_work); |
| 13383 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13384 | intel_atomic_commit_tail(state); |
| 13385 | } |
| 13386 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13387 | static int __i915_sw_fence_call |
| 13388 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 13389 | enum i915_sw_fence_notify notify) |
| 13390 | { |
| 13391 | struct intel_atomic_state *state = |
| 13392 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 13393 | |
| 13394 | switch (notify) { |
| 13395 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13396 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13397 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13398 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 13399 | { |
| 13400 | struct intel_atomic_helper *helper = |
| 13401 | &to_i915(state->base.dev)->atomic_helper; |
| 13402 | |
| 13403 | if (llist_add(&state->freed, &helper->free_list)) |
| 13404 | schedule_work(&helper->free_work); |
| 13405 | break; |
| 13406 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13407 | } |
| 13408 | |
| 13409 | return NOTIFY_DONE; |
| 13410 | } |
| 13411 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13412 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 13413 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13414 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13415 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13416 | int i; |
| 13417 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13418 | 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] | 13419 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13420 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 13421 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13422 | } |
| 13423 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13424 | /** |
| 13425 | * intel_atomic_commit - commit validated state object |
| 13426 | * @dev: DRM device |
| 13427 | * @state: the top-level driver state object |
| 13428 | * @nonblock: nonblocking commit |
| 13429 | * |
| 13430 | * This function commits a top-level state object that has been validated |
| 13431 | * with drm_atomic_helper_check(). |
| 13432 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13433 | * RETURNS |
| 13434 | * Zero for success or -errno. |
| 13435 | */ |
| 13436 | static int intel_atomic_commit(struct drm_device *dev, |
| 13437 | struct drm_atomic_state *state, |
| 13438 | bool nonblock) |
| 13439 | { |
| 13440 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13441 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13442 | int ret = 0; |
| 13443 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13444 | drm_atomic_state_get(state); |
| 13445 | i915_sw_fence_init(&intel_state->commit_ready, |
| 13446 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13447 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13448 | /* |
| 13449 | * The intel_legacy_cursor_update() fast path takes care |
| 13450 | * of avoiding the vblank waits for simple cursor |
| 13451 | * movement and flips. For cursor on/off and size changes, |
| 13452 | * we want to perform the vblank waits so that watermark |
| 13453 | * updates happen during the correct frames. Gen9+ have |
| 13454 | * double buffered watermarks and so shouldn't need this. |
| 13455 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13456 | * Unset state->legacy_cursor_update before the call to |
| 13457 | * drm_atomic_helper_setup_commit() because otherwise |
| 13458 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 13459 | * we get FIFO underruns because we didn't wait |
| 13460 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13461 | * |
| 13462 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 13463 | * (assuming we had any) would solve these problems. |
| 13464 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 13465 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 13466 | struct intel_crtc_state *new_crtc_state; |
| 13467 | struct intel_crtc *crtc; |
| 13468 | int i; |
| 13469 | |
| 13470 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 13471 | if (new_crtc_state->wm.need_postvbl_update || |
| 13472 | new_crtc_state->update_wm_post) |
| 13473 | state->legacy_cursor_update = false; |
| 13474 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13475 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13476 | ret = intel_atomic_prepare_commit(dev, state); |
| 13477 | if (ret) { |
| 13478 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 13479 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13480 | return ret; |
| 13481 | } |
| 13482 | |
| 13483 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 13484 | if (!ret) |
| 13485 | ret = drm_atomic_helper_swap_state(state, true); |
| 13486 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13487 | if (ret) { |
| 13488 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13489 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13490 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13491 | return ret; |
| 13492 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13493 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 13494 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13495 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13496 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13497 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 13498 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 13499 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 13500 | memcpy(dev_priv->min_voltage_level, |
| 13501 | intel_state->min_voltage_level, |
| 13502 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13503 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 13504 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 13505 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13506 | } |
| 13507 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 13508 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13509 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13510 | |
| 13511 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13512 | if (nonblock && intel_state->modeset) { |
| 13513 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 13514 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13515 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13516 | } else { |
| 13517 | if (intel_state->modeset) |
| 13518 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13519 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13520 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13521 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13522 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13523 | } |
| 13524 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13525 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 13526 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13527 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13528 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 13529 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13530 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13531 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 13532 | .set_crc_source = intel_crtc_set_crc_source, |
Mahesh Kumar | a8c2083 | 2018-07-13 19:29:38 +0530 | [diff] [blame] | 13533 | .verify_crc_source = intel_crtc_verify_crc_source, |
Mahesh Kumar | 260bc55 | 2018-07-13 19:29:39 +0530 | [diff] [blame] | 13534 | .get_crc_sources = intel_crtc_get_crc_sources, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13535 | }; |
| 13536 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13537 | struct wait_rps_boost { |
| 13538 | struct wait_queue_entry wait; |
| 13539 | |
| 13540 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13541 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13542 | }; |
| 13543 | |
| 13544 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 13545 | unsigned mode, int sync, void *key) |
| 13546 | { |
| 13547 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13548 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13549 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13550 | /* |
| 13551 | * If we missed the vblank, but the request is already running it |
| 13552 | * is reasonable to assume that it will complete before the next |
| 13553 | * vblank without our intervention, so leave RPS alone. |
| 13554 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13555 | if (!i915_request_started(rq)) |
Chris Wilson | 62eb3c2 | 2019-02-13 09:25:04 +0000 | [diff] [blame] | 13556 | gen6_rps_boost(rq); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13557 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13558 | |
| 13559 | drm_crtc_vblank_put(wait->crtc); |
| 13560 | |
| 13561 | list_del(&wait->wait.entry); |
| 13562 | kfree(wait); |
| 13563 | return 1; |
| 13564 | } |
| 13565 | |
| 13566 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 13567 | struct dma_fence *fence) |
| 13568 | { |
| 13569 | struct wait_rps_boost *wait; |
| 13570 | |
| 13571 | if (!dma_fence_is_i915(fence)) |
| 13572 | return; |
| 13573 | |
| 13574 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 13575 | return; |
| 13576 | |
| 13577 | if (drm_crtc_vblank_get(crtc)) |
| 13578 | return; |
| 13579 | |
| 13580 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 13581 | if (!wait) { |
| 13582 | drm_crtc_vblank_put(crtc); |
| 13583 | return; |
| 13584 | } |
| 13585 | |
| 13586 | wait->request = to_request(dma_fence_get(fence)); |
| 13587 | wait->crtc = crtc; |
| 13588 | |
| 13589 | wait->wait.func = do_rps_boost; |
| 13590 | wait->wait.flags = 0; |
| 13591 | |
| 13592 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 13593 | } |
| 13594 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13595 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 13596 | { |
| 13597 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 13598 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 13599 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 13600 | struct i915_vma *vma; |
| 13601 | |
| 13602 | if (plane->id == PLANE_CURSOR && |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 13603 | INTEL_INFO(dev_priv)->display.cursor_needs_physical) { |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13604 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13605 | const int align = intel_cursor_alignment(dev_priv); |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13606 | int err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13607 | |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13608 | err = i915_gem_object_attach_phys(obj, align); |
| 13609 | if (err) |
| 13610 | return err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13611 | } |
| 13612 | |
| 13613 | vma = intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 13614 | &plane_state->view, |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13615 | intel_plane_uses_fence(plane_state), |
| 13616 | &plane_state->flags); |
| 13617 | if (IS_ERR(vma)) |
| 13618 | return PTR_ERR(vma); |
| 13619 | |
| 13620 | plane_state->vma = vma; |
| 13621 | |
| 13622 | return 0; |
| 13623 | } |
| 13624 | |
| 13625 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 13626 | { |
| 13627 | struct i915_vma *vma; |
| 13628 | |
| 13629 | vma = fetch_and_zero(&old_plane_state->vma); |
| 13630 | if (vma) |
| 13631 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 13632 | } |
| 13633 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 13634 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 13635 | { |
| 13636 | struct i915_sched_attr attr = { |
| 13637 | .priority = I915_PRIORITY_DISPLAY, |
| 13638 | }; |
| 13639 | |
| 13640 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 13641 | } |
| 13642 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13643 | /** |
| 13644 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13645 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13646 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13647 | * |
| 13648 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13649 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13650 | * bits. Some older platforms need special physical address handling for |
| 13651 | * cursor planes. |
| 13652 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13653 | * Must be called with struct_mutex held. |
| 13654 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13655 | * Returns 0 on success, negative error code on failure. |
| 13656 | */ |
| 13657 | int |
| 13658 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13659 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13660 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13661 | struct intel_atomic_state *intel_state = |
| 13662 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 13663 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13664 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13665 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13666 | 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] | 13667 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13668 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13669 | if (old_obj) { |
| 13670 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13671 | drm_atomic_get_new_crtc_state(new_state->state, |
| 13672 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13673 | |
| 13674 | /* Big Hammer, we also need to ensure that any pending |
| 13675 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13676 | * current scanout is retired before unpinning the old |
| 13677 | * framebuffer. Note that we rely on userspace rendering |
| 13678 | * into the buffer attached to the pipe they are waiting |
| 13679 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13680 | * point to the MI_WAIT_FOR_EVENT. |
| 13681 | * |
| 13682 | * This should only fail upon a hung GPU, in which case we |
| 13683 | * can safely continue. |
| 13684 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13685 | if (needs_modeset(crtc_state)) { |
| 13686 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13687 | old_obj->resv, NULL, |
| 13688 | false, 0, |
| 13689 | GFP_KERNEL); |
| 13690 | if (ret < 0) |
| 13691 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13692 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13693 | } |
| 13694 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13695 | if (new_state->fence) { /* explicit fencing */ |
| 13696 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 13697 | new_state->fence, |
| 13698 | I915_FENCE_TIMEOUT, |
| 13699 | GFP_KERNEL); |
| 13700 | if (ret < 0) |
| 13701 | return ret; |
| 13702 | } |
| 13703 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 13704 | if (!obj) |
| 13705 | return 0; |
| 13706 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13707 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13708 | if (ret) |
| 13709 | return ret; |
| 13710 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13711 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13712 | if (ret) { |
| 13713 | i915_gem_object_unpin_pages(obj); |
| 13714 | return ret; |
| 13715 | } |
| 13716 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13717 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13718 | |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13719 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13720 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13721 | if (ret) |
| 13722 | return ret; |
| 13723 | |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 13724 | fb_obj_bump_render_priority(obj); |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13725 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 13726 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13727 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13728 | struct dma_fence *fence; |
| 13729 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13730 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13731 | obj->resv, NULL, |
| 13732 | false, I915_FENCE_TIMEOUT, |
| 13733 | GFP_KERNEL); |
| 13734 | if (ret < 0) |
| 13735 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13736 | |
| 13737 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 13738 | if (fence) { |
| 13739 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 13740 | dma_fence_put(fence); |
| 13741 | } |
| 13742 | } else { |
| 13743 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13744 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13745 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13746 | /* |
| 13747 | * We declare pageflips to be interactive and so merit a small bias |
| 13748 | * towards upclocking to deliver the frame on time. By only changing |
| 13749 | * the RPS thresholds to sample more regularly and aim for higher |
| 13750 | * clocks we can hopefully deliver low power workloads (like kodi) |
| 13751 | * that are not quite steady state without resorting to forcing |
| 13752 | * maximum clocks following a vblank miss (see do_rps_boost()). |
| 13753 | */ |
| 13754 | if (!intel_state->rps_interactive) { |
| 13755 | intel_rps_mark_interactive(dev_priv, true); |
| 13756 | intel_state->rps_interactive = true; |
| 13757 | } |
| 13758 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 13759 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13760 | } |
| 13761 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13762 | /** |
| 13763 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13764 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13765 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13766 | * |
| 13767 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13768 | * |
| 13769 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13770 | */ |
| 13771 | void |
| 13772 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13773 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13774 | { |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13775 | struct intel_atomic_state *intel_state = |
| 13776 | to_intel_atomic_state(old_state->state); |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13777 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13778 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13779 | if (intel_state->rps_interactive) { |
| 13780 | intel_rps_mark_interactive(dev_priv, false); |
| 13781 | intel_state->rps_interactive = false; |
| 13782 | } |
| 13783 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 13784 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13785 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 13786 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 13787 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13788 | } |
| 13789 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13790 | int |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13791 | skl_max_scale(const struct intel_crtc_state *crtc_state, |
| 13792 | u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13793 | { |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13794 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 13795 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13796 | int max_scale, mult; |
| 13797 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13798 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13799 | if (!crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13800 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13801 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13802 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 13803 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 13804 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 13805 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13806 | max_dotclk *= 2; |
| 13807 | |
| 13808 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13809 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13810 | |
| 13811 | /* |
| 13812 | * skl max scale is lower of: |
| 13813 | * close to 3 but not 3, -1 is for that purpose |
| 13814 | * or |
| 13815 | * cdclk/crtc_clock |
| 13816 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13817 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 13818 | tmpclk1 = (1 << 16) * mult - 1; |
| 13819 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 13820 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13821 | |
| 13822 | return max_scale; |
| 13823 | } |
| 13824 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13825 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13826 | struct drm_crtc_state *old_crtc_state) |
| 13827 | { |
| 13828 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13829 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13830 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13831 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13832 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13833 | struct intel_atomic_state *old_intel_state = |
| 13834 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13835 | struct intel_crtc_state *intel_cstate = |
| 13836 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13837 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13838 | |
| 13839 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13840 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13841 | |
| 13842 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13843 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13844 | |
Ville Syrjälä | 4d8ed54 | 2019-02-05 18:08:40 +0200 | [diff] [blame] | 13845 | if (intel_cstate->base.color_mgmt_changed || |
| 13846 | intel_cstate->update_pipe) |
| 13847 | intel_color_commit(intel_cstate); |
| 13848 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13849 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13850 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13851 | else if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 13852 | skl_detach_scalers(intel_cstate); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13853 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13854 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13855 | if (dev_priv->display.atomic_update_watermarks) |
| 13856 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13857 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13858 | } |
| 13859 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13860 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13861 | struct intel_crtc_state *crtc_state) |
| 13862 | { |
| 13863 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13864 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 13865 | if (!IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13866 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13867 | |
| 13868 | if (crtc_state->has_pch_encoder) { |
| 13869 | enum pipe pch_transcoder = |
| 13870 | intel_crtc_pch_transcoder(crtc); |
| 13871 | |
| 13872 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13873 | } |
| 13874 | } |
| 13875 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13876 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13877 | struct drm_crtc_state *old_crtc_state) |
| 13878 | { |
| 13879 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13880 | struct intel_atomic_state *old_intel_state = |
| 13881 | to_intel_atomic_state(old_crtc_state->state); |
| 13882 | struct intel_crtc_state *new_crtc_state = |
| 13883 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13884 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13885 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13886 | |
| 13887 | if (new_crtc_state->update_pipe && |
| 13888 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13889 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13890 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13891 | } |
| 13892 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13893 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13894 | * intel_plane_destroy - destroy a plane |
| 13895 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13896 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13897 | * Common destruction function for all types of planes (primary, cursor, |
| 13898 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13899 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13900 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13901 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13902 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13903 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13904 | } |
| 13905 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13906 | static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane, |
| 13907 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13908 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13909 | switch (modifier) { |
| 13910 | case DRM_FORMAT_MOD_LINEAR: |
| 13911 | case I915_FORMAT_MOD_X_TILED: |
| 13912 | break; |
| 13913 | default: |
| 13914 | return false; |
| 13915 | } |
| 13916 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13917 | switch (format) { |
| 13918 | case DRM_FORMAT_C8: |
| 13919 | case DRM_FORMAT_RGB565: |
| 13920 | case DRM_FORMAT_XRGB1555: |
| 13921 | case DRM_FORMAT_XRGB8888: |
| 13922 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13923 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13924 | default: |
| 13925 | return false; |
| 13926 | } |
| 13927 | } |
| 13928 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13929 | static bool i965_plane_format_mod_supported(struct drm_plane *_plane, |
| 13930 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13931 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13932 | switch (modifier) { |
| 13933 | case DRM_FORMAT_MOD_LINEAR: |
| 13934 | case I915_FORMAT_MOD_X_TILED: |
| 13935 | break; |
| 13936 | default: |
| 13937 | return false; |
| 13938 | } |
| 13939 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13940 | switch (format) { |
| 13941 | case DRM_FORMAT_C8: |
| 13942 | case DRM_FORMAT_RGB565: |
| 13943 | case DRM_FORMAT_XRGB8888: |
| 13944 | case DRM_FORMAT_XBGR8888: |
| 13945 | case DRM_FORMAT_XRGB2101010: |
| 13946 | case DRM_FORMAT_XBGR2101010: |
| 13947 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13948 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13949 | default: |
| 13950 | return false; |
| 13951 | } |
| 13952 | } |
| 13953 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13954 | static bool intel_cursor_format_mod_supported(struct drm_plane *_plane, |
| 13955 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13956 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13957 | return modifier == DRM_FORMAT_MOD_LINEAR && |
| 13958 | format == DRM_FORMAT_ARGB8888; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13959 | } |
| 13960 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13961 | static const struct drm_plane_funcs i965_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13962 | .update_plane = drm_atomic_helper_update_plane, |
| 13963 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13964 | .destroy = intel_plane_destroy, |
| 13965 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13966 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13967 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13968 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13969 | .format_mod_supported = i965_plane_format_mod_supported, |
| 13970 | }; |
| 13971 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13972 | static const struct drm_plane_funcs i8xx_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13973 | .update_plane = drm_atomic_helper_update_plane, |
| 13974 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13975 | .destroy = intel_plane_destroy, |
| 13976 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13977 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13978 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13979 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13980 | .format_mod_supported = i8xx_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13981 | }; |
| 13982 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13983 | static int |
| 13984 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13985 | struct drm_crtc *crtc, |
| 13986 | struct drm_framebuffer *fb, |
| 13987 | int crtc_x, int crtc_y, |
| 13988 | unsigned int crtc_w, unsigned int crtc_h, |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 13989 | u32 src_x, u32 src_y, |
| 13990 | u32 src_w, u32 src_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13991 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13992 | { |
| 13993 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13994 | int ret; |
| 13995 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13996 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13997 | struct drm_framebuffer *old_fb; |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13998 | struct intel_crtc_state *crtc_state = |
| 13999 | to_intel_crtc_state(crtc->state); |
| 14000 | struct intel_crtc_state *new_crtc_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14001 | |
| 14002 | /* |
| 14003 | * When crtc is inactive or there is a modeset pending, |
| 14004 | * wait for it to complete in the slowpath |
| 14005 | */ |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14006 | if (!crtc_state->base.active || needs_modeset(&crtc_state->base) || |
| 14007 | crtc_state->update_pipe) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14008 | goto slow; |
| 14009 | |
| 14010 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 14011 | /* |
| 14012 | * Don't do an async update if there is an outstanding commit modifying |
| 14013 | * the plane. This prevents our async update's changes from getting |
| 14014 | * overridden by a previous synchronous update's state. |
| 14015 | */ |
| 14016 | if (old_plane_state->commit && |
| 14017 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 14018 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14019 | |
| 14020 | /* |
| 14021 | * If any parameters change that may affect watermarks, |
| 14022 | * take the slowpath. Only changing fb or position should be |
| 14023 | * in the fastpath. |
| 14024 | */ |
| 14025 | if (old_plane_state->crtc != crtc || |
| 14026 | old_plane_state->src_w != src_w || |
| 14027 | old_plane_state->src_h != src_h || |
| 14028 | old_plane_state->crtc_w != crtc_w || |
| 14029 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 14030 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14031 | goto slow; |
| 14032 | |
| 14033 | new_plane_state = intel_plane_duplicate_state(plane); |
| 14034 | if (!new_plane_state) |
| 14035 | return -ENOMEM; |
| 14036 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14037 | new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc)); |
| 14038 | if (!new_crtc_state) { |
| 14039 | ret = -ENOMEM; |
| 14040 | goto out_free; |
| 14041 | } |
| 14042 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14043 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 14044 | |
| 14045 | new_plane_state->src_x = src_x; |
| 14046 | new_plane_state->src_y = src_y; |
| 14047 | new_plane_state->src_w = src_w; |
| 14048 | new_plane_state->src_h = src_h; |
| 14049 | new_plane_state->crtc_x = crtc_x; |
| 14050 | new_plane_state->crtc_y = crtc_y; |
| 14051 | new_plane_state->crtc_w = crtc_w; |
| 14052 | new_plane_state->crtc_h = crtc_h; |
| 14053 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14054 | ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state, |
| 14055 | to_intel_plane_state(old_plane_state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14056 | to_intel_plane_state(new_plane_state)); |
| 14057 | if (ret) |
| 14058 | goto out_free; |
| 14059 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14060 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 14061 | if (ret) |
| 14062 | goto out_free; |
| 14063 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 14064 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 14065 | if (ret) |
| 14066 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14067 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 14068 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14069 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 14070 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14071 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 14072 | intel_plane->frontbuffer_bit); |
| 14073 | |
| 14074 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 14075 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14076 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14077 | /* |
| 14078 | * We cannot swap crtc_state as it may be in use by an atomic commit or |
| 14079 | * page flip that's running simultaneously. If we swap crtc_state and |
| 14080 | * destroy the old state, we will cause a use-after-free there. |
| 14081 | * |
| 14082 | * Only update active_planes, which is needed for our internal |
| 14083 | * bookkeeping. Either value will do the right thing when updating |
| 14084 | * planes atomically. If the cursor was part of the atomic update then |
| 14085 | * we would have taken the slowpath. |
| 14086 | */ |
| 14087 | crtc_state->active_planes = new_crtc_state->active_planes; |
| 14088 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 14089 | if (plane->state->visible) { |
| 14090 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14091 | intel_plane->update_plane(intel_plane, crtc_state, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 14092 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 14093 | } else { |
| 14094 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 14095 | intel_plane->disable_plane(intel_plane, crtc_state); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 14096 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14097 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 14098 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14099 | |
| 14100 | out_unlock: |
| 14101 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 14102 | out_free: |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 14103 | if (new_crtc_state) |
| 14104 | intel_crtc_destroy_state(crtc, &new_crtc_state->base); |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 14105 | if (ret) |
| 14106 | intel_plane_destroy_state(plane, new_plane_state); |
| 14107 | else |
| 14108 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14109 | return ret; |
| 14110 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14111 | slow: |
| 14112 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 14113 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 14114 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14115 | } |
| 14116 | |
| 14117 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 14118 | .update_plane = intel_legacy_cursor_update, |
| 14119 | .disable_plane = drm_atomic_helper_disable_plane, |
| 14120 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14121 | .atomic_get_property = intel_plane_atomic_get_property, |
| 14122 | .atomic_set_property = intel_plane_atomic_set_property, |
| 14123 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 14124 | .atomic_destroy_state = intel_plane_destroy_state, |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14125 | .format_mod_supported = intel_cursor_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 14126 | }; |
| 14127 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14128 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 14129 | enum i9xx_plane_id i9xx_plane) |
| 14130 | { |
| 14131 | if (!HAS_FBC(dev_priv)) |
| 14132 | return false; |
| 14133 | |
| 14134 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 14135 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 14136 | else if (IS_IVYBRIDGE(dev_priv)) |
| 14137 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 14138 | i9xx_plane == PLANE_C; |
| 14139 | else if (INTEL_GEN(dev_priv) >= 4) |
| 14140 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 14141 | else |
| 14142 | return i9xx_plane == PLANE_A; |
| 14143 | } |
| 14144 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14145 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14146 | 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] | 14147 | { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14148 | struct intel_plane *plane; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14149 | const struct drm_plane_funcs *plane_funcs; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14150 | unsigned int supported_rotations; |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14151 | unsigned int possible_crtcs; |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14152 | const u64 *modifiers; |
| 14153 | const u32 *formats; |
| 14154 | int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14155 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14156 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14157 | if (INTEL_GEN(dev_priv) >= 9) |
| 14158 | return skl_universal_plane_create(dev_priv, pipe, |
| 14159 | PLANE_PRIMARY); |
| 14160 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14161 | plane = intel_plane_alloc(); |
| 14162 | if (IS_ERR(plane)) |
| 14163 | return plane; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14164 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14165 | plane->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 14166 | /* |
| 14167 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 14168 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 14169 | */ |
| 14170 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14171 | plane->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 14172 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14173 | plane->i9xx_plane = (enum i9xx_plane_id) pipe; |
| 14174 | plane->id = PLANE_PRIMARY; |
| 14175 | plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14176 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14177 | plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane); |
| 14178 | if (plane->has_fbc) { |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14179 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 14180 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14181 | fbc->possible_framebuffer_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 14182 | } |
| 14183 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14184 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14185 | formats = i965_primary_formats; |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 14186 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14187 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14188 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14189 | plane->max_stride = i9xx_plane_max_stride; |
| 14190 | plane->update_plane = i9xx_update_plane; |
| 14191 | plane->disable_plane = i9xx_disable_plane; |
| 14192 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 14193 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14194 | |
| 14195 | plane_funcs = &i965_plane_funcs; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14196 | } else { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14197 | formats = i8xx_primary_formats; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14198 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14199 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14200 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14201 | plane->max_stride = i9xx_plane_max_stride; |
| 14202 | plane->update_plane = i9xx_update_plane; |
| 14203 | plane->disable_plane = i9xx_disable_plane; |
| 14204 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 14205 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 14206 | |
| 14207 | plane_funcs = &i8xx_plane_funcs; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14208 | } |
| 14209 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14210 | possible_crtcs = BIT(pipe); |
| 14211 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14212 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14213 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14214 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14215 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14216 | DRM_PLANE_TYPE_PRIMARY, |
| 14217 | "primary %c", pipe_name(pipe)); |
| 14218 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14219 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14220 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14221 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14222 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 14223 | "plane %c", |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14224 | plane_name(plane->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14225 | if (ret) |
| 14226 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14227 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14228 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 14229 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14230 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 14231 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14232 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14233 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14234 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14235 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14236 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14237 | } |
| 14238 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14239 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14240 | drm_plane_create_rotation_property(&plane->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14241 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14242 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14243 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14244 | drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14245 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14246 | return plane; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14247 | |
| 14248 | fail: |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14249 | intel_plane_free(plane); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14250 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14251 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14252 | } |
| 14253 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14254 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14255 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 14256 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14257 | { |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14258 | unsigned int possible_crtcs; |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14259 | struct intel_plane *cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14260 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14261 | |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14262 | cursor = intel_plane_alloc(); |
| 14263 | if (IS_ERR(cursor)) |
| 14264 | return cursor; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14265 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14266 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 14267 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 14268 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 14269 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14270 | |
| 14271 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14272 | cursor->max_stride = i845_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14273 | cursor->update_plane = i845_update_cursor; |
| 14274 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14275 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14276 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14277 | } else { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14278 | cursor->max_stride = i9xx_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14279 | cursor->update_plane = i9xx_update_cursor; |
| 14280 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14281 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14282 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14283 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14284 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 14285 | cursor->cursor.base = ~0; |
| 14286 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 14287 | |
| 14288 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 14289 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14290 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14291 | possible_crtcs = BIT(pipe); |
| 14292 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14293 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14294 | possible_crtcs, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14295 | intel_cursor_formats, |
| 14296 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14297 | cursor_format_modifiers, |
| 14298 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14299 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14300 | if (ret) |
| 14301 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14302 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14303 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14304 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14305 | DRM_MODE_ROTATE_0, |
| 14306 | DRM_MODE_ROTATE_0 | |
| 14307 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14308 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14309 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14310 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14311 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14312 | |
| 14313 | fail: |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14314 | intel_plane_free(cursor); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14315 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14316 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14317 | } |
| 14318 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14319 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 14320 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14321 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14322 | struct intel_crtc_scaler_state *scaler_state = |
| 14323 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14324 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14325 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14326 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 14327 | crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe]; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14328 | if (!crtc->num_scalers) |
| 14329 | return; |
| 14330 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14331 | for (i = 0; i < crtc->num_scalers; i++) { |
| 14332 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 14333 | |
| 14334 | scaler->in_use = 0; |
Maarten Lankhorst | 0aaf29b | 2018-09-21 16:44:37 +0200 | [diff] [blame] | 14335 | scaler->mode = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14336 | } |
| 14337 | |
| 14338 | scaler_state->scaler_id = -1; |
| 14339 | } |
| 14340 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14341 | 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] | 14342 | { |
| 14343 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14344 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14345 | struct intel_plane *primary = NULL; |
| 14346 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14347 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14348 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14349 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14350 | if (!intel_crtc) |
| 14351 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14352 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14353 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14354 | if (!crtc_state) { |
| 14355 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14356 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14357 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14358 | intel_crtc->config = crtc_state; |
| 14359 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14360 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14361 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14362 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14363 | if (IS_ERR(primary)) { |
| 14364 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14365 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14366 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14367 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14368 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14369 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14370 | struct intel_plane *plane; |
| 14371 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14372 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14373 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14374 | ret = PTR_ERR(plane); |
| 14375 | goto fail; |
| 14376 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14377 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14378 | } |
| 14379 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14380 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14381 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14382 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14383 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14384 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14385 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14386 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14387 | 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] | 14388 | &primary->base, &cursor->base, |
| 14389 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 14390 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14391 | if (ret) |
| 14392 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14393 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14394 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14395 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14396 | /* initialize shared scalers */ |
| 14397 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 14398 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 14399 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 14400 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 14401 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 14402 | |
| 14403 | if (INTEL_GEN(dev_priv) < 9) { |
| 14404 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 14405 | |
| 14406 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14407 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 14408 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 14409 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14410 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14411 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14412 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 14413 | intel_color_init(intel_crtc); |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14414 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14415 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14416 | |
| 14417 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14418 | |
| 14419 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14420 | /* |
| 14421 | * drm_mode_config_cleanup() will free up any |
| 14422 | * crtcs/planes already initialized. |
| 14423 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14424 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14425 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14426 | |
| 14427 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14428 | } |
| 14429 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 14430 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 14431 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14432 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14433 | 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] | 14434 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14435 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14436 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 14437 | 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] | 14438 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14439 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14440 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14441 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14442 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14443 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14444 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14445 | } |
| 14446 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14447 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14448 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14449 | struct drm_device *dev = encoder->base.dev; |
| 14450 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14451 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14452 | int entry = 0; |
| 14453 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14454 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14455 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14456 | index_mask |= (1 << entry); |
| 14457 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14458 | entry++; |
| 14459 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14460 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14461 | return index_mask; |
| 14462 | } |
| 14463 | |
Jani Nikula | a5916fd | 2019-01-22 10:23:05 +0200 | [diff] [blame] | 14464 | static bool ilk_has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14465 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14466 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14467 | return false; |
| 14468 | |
| 14469 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14470 | return false; |
| 14471 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14472 | if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14473 | return false; |
| 14474 | |
| 14475 | return true; |
| 14476 | } |
| 14477 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14478 | static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14479 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14480 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14481 | return false; |
| 14482 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 14483 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14484 | return false; |
| 14485 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14486 | if (HAS_PCH_LPT_H(dev_priv) && |
| 14487 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14488 | return false; |
| 14489 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14490 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14491 | if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14492 | return false; |
| 14493 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14494 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14495 | return false; |
| 14496 | |
| 14497 | return true; |
| 14498 | } |
| 14499 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14500 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 14501 | { |
| 14502 | int pps_num; |
| 14503 | int pps_idx; |
| 14504 | |
| 14505 | if (HAS_DDI(dev_priv)) |
| 14506 | return; |
| 14507 | /* |
| 14508 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 14509 | * everywhere where registers can be write protected. |
| 14510 | */ |
| 14511 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14512 | pps_num = 2; |
| 14513 | else |
| 14514 | pps_num = 1; |
| 14515 | |
| 14516 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 14517 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 14518 | |
| 14519 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 14520 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 14521 | } |
| 14522 | } |
| 14523 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14524 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 14525 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 14526 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14527 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 14528 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14529 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 14530 | else |
| 14531 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14532 | |
| 14533 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14534 | } |
| 14535 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14536 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14537 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14538 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14539 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14540 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14541 | intel_pps_init(dev_priv); |
| 14542 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 14543 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | fc0c5a9 | 2018-08-15 21:12:07 +0100 | [diff] [blame] | 14544 | return; |
| 14545 | |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14546 | if (IS_ICELAKE(dev_priv)) { |
| 14547 | intel_ddi_init(dev_priv, PORT_A); |
| 14548 | intel_ddi_init(dev_priv, PORT_B); |
| 14549 | intel_ddi_init(dev_priv, PORT_C); |
| 14550 | intel_ddi_init(dev_priv, PORT_D); |
| 14551 | intel_ddi_init(dev_priv, PORT_E); |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14552 | /* |
| 14553 | * On some ICL SKUs port F is not present. No strap bits for |
| 14554 | * this, so rely on VBT. |
Imre Deak | 2b34e562 | 2018-12-20 17:52:11 +0200 | [diff] [blame] | 14555 | * Work around broken VBTs on SKUs known to have no port F. |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14556 | */ |
Imre Deak | 2b34e562 | 2018-12-20 17:52:11 +0200 | [diff] [blame] | 14557 | if (IS_ICL_WITH_PORT_F(dev_priv) && |
| 14558 | intel_bios_is_port_present(dev_priv, PORT_F)) |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14559 | intel_ddi_init(dev_priv, PORT_F); |
| 14560 | |
Madhav Chauhan | bf4d57f | 2018-10-30 13:56:23 +0200 | [diff] [blame] | 14561 | icl_dsi_init(dev_priv); |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14562 | } else if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14563 | /* |
| 14564 | * FIXME: Broxton doesn't support port detection via the |
| 14565 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14566 | * detect the ports. |
| 14567 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14568 | intel_ddi_init(dev_priv, PORT_A); |
| 14569 | intel_ddi_init(dev_priv, PORT_B); |
| 14570 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14571 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14572 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14573 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14574 | int found; |
| 14575 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14576 | if (intel_ddi_crt_present(dev_priv)) |
| 14577 | intel_crt_init(dev_priv); |
| 14578 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14579 | /* |
| 14580 | * Haswell uses DDI functions to detect digital outputs. |
| 14581 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14582 | * it's there. |
| 14583 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14584 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14585 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14586 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14587 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14588 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14589 | /* 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] | 14590 | * register */ |
| 14591 | found = I915_READ(SFUSE_STRAP); |
| 14592 | |
| 14593 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14594 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14595 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14596 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14597 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14598 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14599 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 14600 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14601 | /* |
| 14602 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14603 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14604 | if (IS_GEN9_BC(dev_priv) && |
Imre Deak | e9d49bb | 2018-12-20 15:26:02 +0200 | [diff] [blame] | 14605 | intel_bios_is_port_present(dev_priv, PORT_E)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14606 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14607 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14608 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14609 | int found; |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14610 | |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14611 | /* |
| 14612 | * intel_edp_init_connector() depends on this completing first, |
| 14613 | * to prevent the registration of both eDP and LVDS and the |
| 14614 | * incorrect sharing of the PPS. |
| 14615 | */ |
| 14616 | intel_lvds_init(dev_priv); |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14617 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14618 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14619 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14620 | |
Jani Nikula | a5916fd | 2019-01-22 10:23:05 +0200 | [diff] [blame] | 14621 | if (ilk_has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14622 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14623 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14624 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14625 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14626 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14627 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14628 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14629 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14630 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14631 | } |
| 14632 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14633 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14634 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14635 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14636 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14637 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14638 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14639 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14640 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14641 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14642 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14643 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14644 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14645 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 14646 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14647 | if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support) |
| 14648 | intel_crt_init(dev_priv); |
| 14649 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14650 | /* |
| 14651 | * The DP_DETECTED bit is the latched state of the DDC |
| 14652 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14653 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14654 | * eDP ports may have been muxed to an alternate function. |
| 14655 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14656 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14657 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14658 | * |
| 14659 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 14660 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 14661 | * and VBT for the presence of the port. Additionally we can't |
| 14662 | * trust the port type the VBT declares as we've seen at least |
| 14663 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14664 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14665 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14666 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14667 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14668 | 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] | 14669 | 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] | 14670 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14671 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14672 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14673 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14674 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14675 | 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] | 14676 | 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] | 14677 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14678 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14679 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14680 | /* |
| 14681 | * eDP not supported on port D, |
| 14682 | * so no need to worry about it |
| 14683 | */ |
| 14684 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14685 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14686 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14687 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14688 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14689 | } |
| 14690 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14691 | vlv_dsi_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14692 | } else if (IS_PINEVIEW(dev_priv)) { |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14693 | intel_lvds_init(dev_priv); |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14694 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14695 | } else if (IS_GEN_RANGE(dev_priv, 3, 4)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14696 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14697 | |
Jani Nikula | 9bedc7e | 2019-01-22 10:23:03 +0200 | [diff] [blame] | 14698 | if (IS_MOBILE(dev_priv)) |
| 14699 | intel_lvds_init(dev_priv); |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14700 | |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14701 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14702 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14703 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14704 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14705 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14706 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14707 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14708 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14709 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14710 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14711 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14712 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14713 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14714 | |
| 14715 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14716 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14717 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14718 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14719 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14720 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14721 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14722 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14723 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14724 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14725 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14726 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14727 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14728 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14729 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14730 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14731 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14732 | 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] | 14733 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Jani Nikula | d652146 | 2019-01-22 10:23:04 +0200 | [diff] [blame] | 14734 | |
| 14735 | if (SUPPORTS_TV(dev_priv)) |
| 14736 | intel_tv_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14737 | } else if (IS_GEN(dev_priv, 2)) { |
Jani Nikula | 346073c | 2019-01-22 10:23:06 +0200 | [diff] [blame] | 14738 | if (IS_I85X(dev_priv)) |
Jani Nikula | 9bedc7e | 2019-01-22 10:23:03 +0200 | [diff] [blame] | 14739 | intel_lvds_init(dev_priv); |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14740 | |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14741 | intel_crt_init(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14742 | intel_dvo_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14743 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14744 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14745 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14746 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14747 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14748 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14749 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14750 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14751 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14752 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14753 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14754 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14755 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14756 | } |
| 14757 | |
| 14758 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14759 | { |
| 14760 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14761 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14762 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14763 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14764 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14765 | i915_gem_object_lock(obj); |
| 14766 | WARN_ON(!obj->framebuffer_references--); |
| 14767 | i915_gem_object_unlock(obj); |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14768 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14769 | i915_gem_object_put(obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14770 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14771 | kfree(intel_fb); |
| 14772 | } |
| 14773 | |
| 14774 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14775 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14776 | unsigned int *handle) |
| 14777 | { |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14778 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14779 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14780 | if (obj->userptr.mm) { |
| 14781 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14782 | return -EINVAL; |
| 14783 | } |
| 14784 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14785 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14786 | } |
| 14787 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14788 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14789 | struct drm_file *file, |
| 14790 | unsigned flags, unsigned color, |
| 14791 | struct drm_clip_rect *clips, |
| 14792 | unsigned num_clips) |
| 14793 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14794 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14795 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14796 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14797 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14798 | |
| 14799 | return 0; |
| 14800 | } |
| 14801 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14802 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14803 | .destroy = intel_user_framebuffer_destroy, |
| 14804 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14805 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14806 | }; |
| 14807 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14808 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14809 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14810 | u32 pixel_format, u64 fb_modifier) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14811 | { |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14812 | struct intel_crtc *crtc; |
| 14813 | struct intel_plane *plane; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14814 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14815 | /* |
| 14816 | * We assume the primary plane for pipe A has |
| 14817 | * the highest stride limits of them all. |
| 14818 | */ |
| 14819 | crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A); |
| 14820 | plane = to_intel_plane(crtc->base.primary); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14821 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14822 | return plane->max_stride(plane, pixel_format, fb_modifier, |
| 14823 | DRM_MODE_ROTATE_0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14824 | } |
| 14825 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14826 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14827 | struct drm_i915_gem_object *obj, |
| 14828 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14829 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14830 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14831 | struct drm_framebuffer *fb = &intel_fb->base; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14832 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14833 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14834 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14835 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14836 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14837 | i915_gem_object_lock(obj); |
| 14838 | obj->framebuffer_references++; |
| 14839 | tiling = i915_gem_object_get_tiling(obj); |
| 14840 | stride = i915_gem_object_get_stride(obj); |
| 14841 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14842 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14843 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14844 | /* |
| 14845 | * If there's a fence, enforce that |
| 14846 | * the fb modifier and tiling mode match. |
| 14847 | */ |
| 14848 | if (tiling != I915_TILING_NONE && |
| 14849 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14850 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14851 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14852 | } |
| 14853 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14854 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14855 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14856 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14857 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14858 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14859 | } |
| 14860 | } |
| 14861 | |
Ville Syrjälä | 17e8fd1 | 2018-10-29 20:34:53 +0200 | [diff] [blame] | 14862 | if (!drm_any_plane_has_format(&dev_priv->drm, |
| 14863 | mode_cmd->pixel_format, |
| 14864 | mode_cmd->modifier[0])) { |
| 14865 | struct drm_format_name_buf format_name; |
| 14866 | |
| 14867 | DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n", |
| 14868 | drm_get_format_name(mode_cmd->pixel_format, |
| 14869 | &format_name), |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14870 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14871 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14872 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14873 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14874 | /* |
| 14875 | * gen2/3 display engine uses the fence if present, |
| 14876 | * so the tiling mode must match the fb modifier exactly. |
| 14877 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14878 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14879 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14880 | 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] | 14881 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14882 | } |
| 14883 | |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14884 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format, |
| 14885 | mode_cmd->modifier[0]); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14886 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14887 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14888 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14889 | "tiled" : "linear", |
| 14890 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14891 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14892 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14893 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14894 | /* |
| 14895 | * If there's a fence, enforce that |
| 14896 | * the fb pitch and fence stride match. |
| 14897 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14898 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14899 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14900 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14901 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14902 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14903 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14904 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14905 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14906 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14907 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14908 | 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] | 14909 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14910 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14911 | u32 stride_alignment; |
| 14912 | |
| 14913 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14914 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14915 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14916 | } |
| 14917 | |
| 14918 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14919 | |
| 14920 | /* |
| 14921 | * Display WA #0531: skl,bxt,kbl,glk |
| 14922 | * |
| 14923 | * Render decompression and plane width > 3840 |
| 14924 | * combined with horizontal panning requires the |
| 14925 | * plane stride to be a multiple of 4. We'll just |
| 14926 | * require the entire fb to accommodate that to avoid |
| 14927 | * potential runtime errors at plane configuration time. |
| 14928 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14929 | if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 && |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 14930 | is_ccs_modifier(fb->modifier)) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14931 | stride_alignment *= 4; |
| 14932 | |
| 14933 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14934 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14935 | i, fb->pitches[i], stride_alignment); |
| 14936 | goto err; |
| 14937 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14938 | |
Daniel Stone | a268bcd | 2018-05-18 15:30:08 +0100 | [diff] [blame] | 14939 | fb->obj[i] = &obj->base; |
| 14940 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14941 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14942 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14943 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14944 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14945 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14946 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14947 | if (ret) { |
| 14948 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14949 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14950 | } |
| 14951 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14952 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14953 | |
| 14954 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14955 | i915_gem_object_lock(obj); |
| 14956 | obj->framebuffer_references--; |
| 14957 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14958 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14959 | } |
| 14960 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14961 | static struct drm_framebuffer * |
| 14962 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14963 | struct drm_file *filp, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14964 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14965 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14966 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14967 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14968 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14969 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14970 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14971 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14972 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14973 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14974 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14975 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14976 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14977 | |
| 14978 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14979 | } |
| 14980 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14981 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14982 | { |
| 14983 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14984 | |
| 14985 | drm_atomic_state_default_release(state); |
| 14986 | |
| 14987 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14988 | |
| 14989 | kfree(state); |
| 14990 | } |
| 14991 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14992 | static enum drm_mode_status |
| 14993 | intel_mode_valid(struct drm_device *dev, |
| 14994 | const struct drm_display_mode *mode) |
| 14995 | { |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14996 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14997 | int hdisplay_max, htotal_max; |
| 14998 | int vdisplay_max, vtotal_max; |
| 14999 | |
Ville Syrjälä | e4dd27a | 2018-05-24 15:54:03 +0300 | [diff] [blame] | 15000 | /* |
| 15001 | * Can't reject DBLSCAN here because Xorg ddxen can add piles |
| 15002 | * of DBLSCAN modes to the output's mode list when they detect |
| 15003 | * the scaling mode property on the connector. And they don't |
| 15004 | * ask the kernel to validate those modes in any way until |
| 15005 | * modeset time at which point the client gets a protocol error. |
| 15006 | * So in order to not upset those clients we silently ignore the |
| 15007 | * DBLSCAN flag on such connectors. For other connectors we will |
| 15008 | * reject modes with the DBLSCAN flag in encoder->compute_config(). |
| 15009 | * And we always reject DBLSCAN modes in connector->mode_valid() |
| 15010 | * as we never want such modes on the connector's mode list. |
| 15011 | */ |
| 15012 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 15013 | if (mode->vscan > 1) |
| 15014 | return MODE_NO_VSCAN; |
| 15015 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 15016 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 15017 | return MODE_H_ILLEGAL; |
| 15018 | |
| 15019 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 15020 | DRM_MODE_FLAG_NCSYNC | |
| 15021 | DRM_MODE_FLAG_PCSYNC)) |
| 15022 | return MODE_HSYNC; |
| 15023 | |
| 15024 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 15025 | DRM_MODE_FLAG_PIXMUX | |
| 15026 | DRM_MODE_FLAG_CLKDIV2)) |
| 15027 | return MODE_BAD; |
| 15028 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15029 | if (INTEL_GEN(dev_priv) >= 9 || |
| 15030 | IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { |
| 15031 | hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ |
| 15032 | vdisplay_max = 4096; |
| 15033 | htotal_max = 8192; |
| 15034 | vtotal_max = 8192; |
| 15035 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 15036 | hdisplay_max = 4096; |
| 15037 | vdisplay_max = 4096; |
| 15038 | htotal_max = 8192; |
| 15039 | vtotal_max = 8192; |
| 15040 | } else { |
| 15041 | hdisplay_max = 2048; |
| 15042 | vdisplay_max = 2048; |
| 15043 | htotal_max = 4096; |
| 15044 | vtotal_max = 4096; |
| 15045 | } |
| 15046 | |
| 15047 | if (mode->hdisplay > hdisplay_max || |
| 15048 | mode->hsync_start > htotal_max || |
| 15049 | mode->hsync_end > htotal_max || |
| 15050 | mode->htotal > htotal_max) |
| 15051 | return MODE_H_ILLEGAL; |
| 15052 | |
| 15053 | if (mode->vdisplay > vdisplay_max || |
| 15054 | mode->vsync_start > vtotal_max || |
| 15055 | mode->vsync_end > vtotal_max || |
| 15056 | mode->vtotal > vtotal_max) |
| 15057 | return MODE_V_ILLEGAL; |
| 15058 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 15059 | return MODE_OK; |
| 15060 | } |
| 15061 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15062 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15063 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 15064 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 15065 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 15066 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 15067 | .atomic_check = intel_atomic_check, |
| 15068 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 15069 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 15070 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 15071 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15072 | }; |
| 15073 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15074 | /** |
| 15075 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 15076 | * @dev_priv: device private |
| 15077 | */ |
| 15078 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15079 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 15080 | intel_init_cdclk_hooks(dev_priv); |
| 15081 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 15082 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15083 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15084 | dev_priv->display.get_initial_plane_config = |
| 15085 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15086 | dev_priv->display.crtc_compute_clock = |
| 15087 | haswell_crtc_compute_clock; |
| 15088 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 15089 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15090 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15091 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15092 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 15093 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 15094 | dev_priv->display.crtc_compute_clock = |
| 15095 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 15096 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 15097 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15098 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15099 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15100 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 15101 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 15102 | dev_priv->display.crtc_compute_clock = |
| 15103 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 15104 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 15105 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 15106 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 15107 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15108 | dev_priv->display.get_initial_plane_config = |
| 15109 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 15110 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 15111 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 15112 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 15113 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 15114 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15115 | dev_priv->display.get_initial_plane_config = |
| 15116 | i9xx_get_initial_plane_config; |
| 15117 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 15118 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 15119 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 15120 | } else if (IS_G4X(dev_priv)) { |
| 15121 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15122 | dev_priv->display.get_initial_plane_config = |
| 15123 | i9xx_get_initial_plane_config; |
| 15124 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 15125 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15126 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 15127 | } else if (IS_PINEVIEW(dev_priv)) { |
| 15128 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15129 | dev_priv->display.get_initial_plane_config = |
| 15130 | i9xx_get_initial_plane_config; |
| 15131 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 15132 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15133 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15134 | } else if (!IS_GEN(dev_priv, 2)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 15135 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15136 | dev_priv->display.get_initial_plane_config = |
| 15137 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 15138 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 15139 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15140 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 15141 | } else { |
| 15142 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 15143 | dev_priv->display.get_initial_plane_config = |
| 15144 | i9xx_get_initial_plane_config; |
| 15145 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 15146 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 15147 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 15148 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15149 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15150 | if (IS_GEN(dev_priv, 5)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15151 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15152 | } else if (IS_GEN(dev_priv, 6)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15153 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15154 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15155 | /* FIXME: detect B0+ stepping and use auto training */ |
| 15156 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15157 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 15158 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 15159 | } |
| 15160 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 15161 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 15162 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 15163 | else |
| 15164 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15165 | } |
| 15166 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15167 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15168 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15169 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 15170 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15171 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15172 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15173 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 15174 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 15175 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 15176 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15177 | sr1 = inb(VGA_SR_DATA); |
| 15178 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 15179 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15180 | udelay(300); |
| 15181 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 15182 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15183 | POSTING_READ(vga_reg); |
| 15184 | } |
| 15185 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15186 | void intel_modeset_init_hw(struct drm_device *dev) |
| 15187 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15188 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15189 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15190 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 15191 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 15192 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15193 | } |
| 15194 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15195 | /* |
| 15196 | * Calculate what we think the watermarks should be for the state we've read |
| 15197 | * out of the hardware and then immediately program those watermarks so that |
| 15198 | * we ensure the hardware settings match our internal state. |
| 15199 | * |
| 15200 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 15201 | * current state (which was constructed during hardware readout) and running it |
| 15202 | * through the atomic check code to calculate new watermark values in the |
| 15203 | * state object. |
| 15204 | */ |
| 15205 | static void sanitize_watermarks(struct drm_device *dev) |
| 15206 | { |
| 15207 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15208 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15209 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15210 | struct drm_crtc *crtc; |
| 15211 | struct drm_crtc_state *cstate; |
| 15212 | struct drm_modeset_acquire_ctx ctx; |
| 15213 | int ret; |
| 15214 | int i; |
| 15215 | |
| 15216 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15217 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15218 | return; |
| 15219 | |
| 15220 | /* |
| 15221 | * We need to hold connection_mutex before calling duplicate_state so |
| 15222 | * that the connector loop is protected. |
| 15223 | */ |
| 15224 | drm_modeset_acquire_init(&ctx, 0); |
| 15225 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15226 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15227 | if (ret == -EDEADLK) { |
| 15228 | drm_modeset_backoff(&ctx); |
| 15229 | goto retry; |
| 15230 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15231 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15232 | } |
| 15233 | |
| 15234 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 15235 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15236 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15237 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15238 | intel_state = to_intel_atomic_state(state); |
| 15239 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15240 | /* |
| 15241 | * Hardware readout is the only time we don't want to calculate |
| 15242 | * intermediate watermarks (since we don't trust the current |
| 15243 | * watermarks). |
| 15244 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 15245 | if (!HAS_GMCH(dev_priv)) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15246 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15247 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15248 | ret = intel_atomic_check(dev, state); |
| 15249 | if (ret) { |
| 15250 | /* |
| 15251 | * If we fail here, it means that the hardware appears to be |
| 15252 | * programmed in a way that shouldn't be possible, given our |
| 15253 | * understanding of watermark requirements. This might mean a |
| 15254 | * mistake in the hardware readout code or a mistake in the |
| 15255 | * watermark calculations for a given platform. Raise a WARN |
| 15256 | * so that this is noticeable. |
| 15257 | * |
| 15258 | * If this actually happens, we'll have to just leave the |
| 15259 | * BIOS-programmed watermarks untouched and hope for the best. |
| 15260 | */ |
| 15261 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 15262 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15263 | } |
| 15264 | |
| 15265 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 15266 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15267 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 15268 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15269 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15270 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 15271 | |
| 15272 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15273 | } |
| 15274 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 15275 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15276 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15277 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15278 | drm_modeset_drop_locks(&ctx); |
| 15279 | drm_modeset_acquire_fini(&ctx); |
| 15280 | } |
| 15281 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15282 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 15283 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15284 | if (IS_GEN(dev_priv, 5)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15285 | u32 fdi_pll_clk = |
| 15286 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 15287 | |
| 15288 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15289 | } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15290 | dev_priv->fdi_pll_freq = 270000; |
| 15291 | } else { |
| 15292 | return; |
| 15293 | } |
| 15294 | |
| 15295 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 15296 | } |
| 15297 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15298 | static int intel_initial_commit(struct drm_device *dev) |
| 15299 | { |
| 15300 | struct drm_atomic_state *state = NULL; |
| 15301 | struct drm_modeset_acquire_ctx ctx; |
| 15302 | struct drm_crtc *crtc; |
| 15303 | struct drm_crtc_state *crtc_state; |
| 15304 | int ret = 0; |
| 15305 | |
| 15306 | state = drm_atomic_state_alloc(dev); |
| 15307 | if (!state) |
| 15308 | return -ENOMEM; |
| 15309 | |
| 15310 | drm_modeset_acquire_init(&ctx, 0); |
| 15311 | |
| 15312 | retry: |
| 15313 | state->acquire_ctx = &ctx; |
| 15314 | |
| 15315 | drm_for_each_crtc(crtc, dev) { |
| 15316 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 15317 | if (IS_ERR(crtc_state)) { |
| 15318 | ret = PTR_ERR(crtc_state); |
| 15319 | goto out; |
| 15320 | } |
| 15321 | |
| 15322 | if (crtc_state->active) { |
| 15323 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 15324 | if (ret) |
| 15325 | goto out; |
Ville Syrjälä | fa6af514 | 2018-11-20 15:54:49 +0200 | [diff] [blame] | 15326 | |
| 15327 | /* |
| 15328 | * FIXME hack to force a LUT update to avoid the |
| 15329 | * plane update forcing the pipe gamma on without |
| 15330 | * having a proper LUT loaded. Remove once we |
| 15331 | * have readout for pipe gamma enable. |
| 15332 | */ |
| 15333 | crtc_state->color_mgmt_changed = true; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15334 | } |
| 15335 | } |
| 15336 | |
| 15337 | ret = drm_atomic_commit(state); |
| 15338 | |
| 15339 | out: |
| 15340 | if (ret == -EDEADLK) { |
| 15341 | drm_atomic_state_clear(state); |
| 15342 | drm_modeset_backoff(&ctx); |
| 15343 | goto retry; |
| 15344 | } |
| 15345 | |
| 15346 | drm_atomic_state_put(state); |
| 15347 | |
| 15348 | drm_modeset_drop_locks(&ctx); |
| 15349 | drm_modeset_acquire_fini(&ctx); |
| 15350 | |
| 15351 | return ret; |
| 15352 | } |
| 15353 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15354 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15355 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15356 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15357 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15358 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15359 | struct intel_crtc *crtc; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15360 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15361 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15362 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 15363 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15364 | drm_mode_config_init(dev); |
| 15365 | |
| 15366 | dev->mode_config.min_width = 0; |
| 15367 | dev->mode_config.min_height = 0; |
| 15368 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15369 | dev->mode_config.preferred_depth = 24; |
| 15370 | dev->mode_config.prefer_shadow = 1; |
| 15371 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15372 | dev->mode_config.allow_fb_modifiers = true; |
| 15373 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15374 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15375 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 15376 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15377 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 15378 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15379 | |
Jani Nikula | 27a981b | 2018-10-17 12:35:39 +0300 | [diff] [blame] | 15380 | intel_init_quirks(dev_priv); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15381 | |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 15382 | intel_fbc_init(dev_priv); |
| 15383 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 15384 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15385 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15386 | /* |
| 15387 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15388 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15389 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15390 | * indicates as much. |
| 15391 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15392 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15393 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15394 | DREF_SSC1_ENABLE); |
| 15395 | |
| 15396 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15397 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15398 | bios_lvds_use_ssc ? "en" : "dis", |
| 15399 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15400 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15401 | } |
| 15402 | } |
| 15403 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15404 | /* maximum framebuffer dimensions */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15405 | if (IS_GEN(dev_priv, 2)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15406 | dev->mode_config.max_width = 2048; |
| 15407 | dev->mode_config.max_height = 2048; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15408 | } else if (IS_GEN(dev_priv, 3)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15409 | dev->mode_config.max_width = 4096; |
| 15410 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15411 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15412 | dev->mode_config.max_width = 8192; |
| 15413 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15414 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15415 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 15416 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 15417 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15418 | dev->mode_config.cursor_height = 1023; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15419 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15420 | dev->mode_config.cursor_width = 64; |
| 15421 | dev->mode_config.cursor_height = 64; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15422 | } else { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15423 | dev->mode_config.cursor_width = 256; |
| 15424 | dev->mode_config.cursor_height = 256; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15425 | } |
| 15426 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 15427 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15428 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15429 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15430 | INTEL_INFO(dev_priv)->num_pipes, |
| 15431 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15432 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15433 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15434 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15435 | if (ret) { |
| 15436 | drm_mode_config_cleanup(dev); |
| 15437 | return ret; |
| 15438 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15439 | } |
| 15440 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15441 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15442 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15443 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 15444 | intel_update_czclk(dev_priv); |
| 15445 | intel_modeset_init_hw(dev); |
| 15446 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15447 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15448 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15449 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15450 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15451 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15452 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15453 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15454 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15455 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15456 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15457 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15458 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15459 | struct intel_initial_plane_config plane_config = {}; |
| 15460 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15461 | if (!crtc->active) |
| 15462 | continue; |
| 15463 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15464 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15465 | * Note that reserving the BIOS fb up front prevents us |
| 15466 | * from stuffing other stolen allocations like the ring |
| 15467 | * on top. This prevents some ugliness at boot time, and |
| 15468 | * can even allow for smooth boot transitions if the BIOS |
| 15469 | * fb is large enough for the active pipe configuration. |
| 15470 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15471 | dev_priv->display.get_initial_plane_config(crtc, |
| 15472 | &plane_config); |
| 15473 | |
| 15474 | /* |
| 15475 | * If the fb is shared between multiple heads, we'll |
| 15476 | * just get the first one. |
| 15477 | */ |
| 15478 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15479 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15480 | |
| 15481 | /* |
| 15482 | * Make sure hardware watermarks really match the state we read out. |
| 15483 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15484 | * since the watermark calculation done here will use pstate->fb. |
| 15485 | */ |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 15486 | if (!HAS_GMCH(dev_priv)) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15487 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15488 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15489 | /* |
| 15490 | * Force all active planes to recompute their states. So that on |
| 15491 | * mode_setcrtc after probe, all the intel_plane_state variables |
| 15492 | * are already calculated and there is no assert_plane warnings |
| 15493 | * during bootup. |
| 15494 | */ |
| 15495 | ret = intel_initial_commit(dev); |
| 15496 | if (ret) |
| 15497 | DRM_DEBUG_KMS("Initial commit in probe failed.\n"); |
| 15498 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15499 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15500 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15501 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15502 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15503 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15504 | 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] | 15505 | /* 640x480@60Hz, ~25175 kHz */ |
| 15506 | struct dpll clock = { |
| 15507 | .m1 = 18, |
| 15508 | .m2 = 7, |
| 15509 | .p1 = 13, |
| 15510 | .p2 = 4, |
| 15511 | .n = 2, |
| 15512 | }; |
| 15513 | u32 dpll, fp; |
| 15514 | int i; |
| 15515 | |
| 15516 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 15517 | |
| 15518 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 15519 | pipe_name(pipe), clock.vco, clock.dot); |
| 15520 | |
| 15521 | fp = i9xx_dpll_compute_fp(&clock); |
| 15522 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 15523 | DPLL_VGA_MODE_DIS | |
| 15524 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 15525 | PLL_P2_DIVIDE_BY_4 | |
| 15526 | PLL_REF_INPUT_DREFCLK | |
| 15527 | DPLL_VCO_ENABLE; |
| 15528 | |
| 15529 | I915_WRITE(FP0(pipe), fp); |
| 15530 | I915_WRITE(FP1(pipe), fp); |
| 15531 | |
| 15532 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15533 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15534 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15535 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15536 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15537 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15538 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15539 | |
| 15540 | /* |
| 15541 | * Apparently we need to have VGA mode enabled prior to changing |
| 15542 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15543 | * dividers, even though the register value does change. |
| 15544 | */ |
| 15545 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15546 | I915_WRITE(DPLL(pipe), dpll); |
| 15547 | |
| 15548 | /* Wait for the clocks to stabilize. */ |
| 15549 | POSTING_READ(DPLL(pipe)); |
| 15550 | udelay(150); |
| 15551 | |
| 15552 | /* The pixel multiplier can only be updated once the |
| 15553 | * DPLL is enabled and the clocks are stable. |
| 15554 | * |
| 15555 | * So write it again. |
| 15556 | */ |
| 15557 | I915_WRITE(DPLL(pipe), dpll); |
| 15558 | |
| 15559 | /* We do this three times for luck */ |
| 15560 | for (i = 0; i < 3 ; i++) { |
| 15561 | I915_WRITE(DPLL(pipe), dpll); |
| 15562 | POSTING_READ(DPLL(pipe)); |
| 15563 | udelay(150); /* wait for warmup */ |
| 15564 | } |
| 15565 | |
| 15566 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15567 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15568 | |
| 15569 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15570 | } |
| 15571 | |
| 15572 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15573 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15574 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15575 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15576 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15577 | pipe_name(pipe)); |
| 15578 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15579 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15580 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15581 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 15582 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE); |
| 15583 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15584 | |
| 15585 | I915_WRITE(PIPECONF(pipe), 0); |
| 15586 | POSTING_READ(PIPECONF(pipe)); |
| 15587 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15588 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15589 | |
| 15590 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15591 | POSTING_READ(DPLL(pipe)); |
| 15592 | } |
| 15593 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15594 | static void |
| 15595 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15596 | { |
| 15597 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15598 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15599 | if (INTEL_GEN(dev_priv) >= 4) |
| 15600 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15601 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15602 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15603 | struct intel_plane *plane = |
| 15604 | to_intel_plane(crtc->base.primary); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15605 | struct intel_crtc *plane_crtc; |
| 15606 | enum pipe pipe; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15607 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15608 | if (!plane->get_hw_state(plane, &pipe)) |
| 15609 | continue; |
| 15610 | |
| 15611 | if (pipe == crtc->pipe) |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15612 | continue; |
| 15613 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15614 | DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", |
| 15615 | plane->base.base.id, plane->base.name); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15616 | |
| 15617 | plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15618 | intel_plane_disable_noatomic(plane_crtc, plane); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15619 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15620 | } |
| 15621 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15622 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15623 | { |
| 15624 | struct drm_device *dev = crtc->base.dev; |
| 15625 | struct intel_encoder *encoder; |
| 15626 | |
| 15627 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15628 | return true; |
| 15629 | |
| 15630 | return false; |
| 15631 | } |
| 15632 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15633 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15634 | { |
| 15635 | struct drm_device *dev = encoder->base.dev; |
| 15636 | struct intel_connector *connector; |
| 15637 | |
| 15638 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15639 | return connector; |
| 15640 | |
| 15641 | return NULL; |
| 15642 | } |
| 15643 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15644 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15645 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15646 | { |
| 15647 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15648 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15649 | } |
| 15650 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15651 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15652 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15653 | { |
| 15654 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15655 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15656 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15657 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15658 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15659 | /* 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] | 15660 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15661 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15662 | |
| 15663 | I915_WRITE(reg, |
| 15664 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15665 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15666 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15667 | if (crtc_state->base.active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15668 | struct intel_plane *plane; |
| 15669 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15670 | /* Disable everything but the primary plane */ |
| 15671 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15672 | const struct intel_plane_state *plane_state = |
| 15673 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15674 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15675 | if (plane_state->base.visible && |
| 15676 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15677 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15678 | } |
Matt Roper | c055030 | 2019-01-30 10:51:20 -0800 | [diff] [blame] | 15679 | |
| 15680 | /* |
| 15681 | * Disable any background color set by the BIOS, but enable the |
| 15682 | * gamma and CSC to match how we program our planes. |
| 15683 | */ |
| 15684 | if (INTEL_GEN(dev_priv) >= 9) |
| 15685 | I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe), |
| 15686 | SKL_BOTTOM_COLOR_GAMMA_ENABLE | |
| 15687 | SKL_BOTTOM_COLOR_CSC_ENABLE); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15688 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15689 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15690 | /* Adjust the state of the output pipe according to whether we |
| 15691 | * have active connectors/encoders. */ |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15692 | if (crtc_state->base.active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15693 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15694 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 15695 | if (crtc_state->base.active || HAS_GMCH(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15696 | /* |
| 15697 | * We start out with underrun reporting disabled to avoid races. |
| 15698 | * For correct bookkeeping mark this on active crtcs. |
| 15699 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15700 | * Also on gmch platforms we dont have any hardware bits to |
| 15701 | * disable the underrun reporting. Which means we need to start |
| 15702 | * out with underrun reporting disabled also on inactive pipes, |
| 15703 | * since otherwise we'll complain about the garbage we read when |
| 15704 | * e.g. coming up after runtime pm. |
| 15705 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15706 | * No protection against concurrent access is required - at |
| 15707 | * worst a fifo underrun happens which also sets this to false. |
| 15708 | */ |
| 15709 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15710 | /* |
| 15711 | * We track the PCH trancoder underrun reporting state |
| 15712 | * within the crtc. With crtc for pipe A housing the underrun |
| 15713 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15714 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15715 | * and marking underrun reporting as disabled for the non-existing |
| 15716 | * PCH transcoders B and C would prevent enabling the south |
| 15717 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15718 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15719 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15720 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15721 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15722 | } |
| 15723 | |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15724 | static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state) |
| 15725 | { |
| 15726 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 15727 | |
| 15728 | /* |
| 15729 | * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram |
| 15730 | * the hardware when a high res displays plugged in. DPLL P |
| 15731 | * divider is zero, and the pipe timings are bonkers. We'll |
| 15732 | * try to disable everything in that case. |
| 15733 | * |
| 15734 | * FIXME would be nice to be able to sanitize this state |
| 15735 | * without several WARNs, but for now let's take the easy |
| 15736 | * road. |
| 15737 | */ |
| 15738 | return IS_GEN(dev_priv, 6) && |
| 15739 | crtc_state->base.active && |
| 15740 | crtc_state->shared_dpll && |
| 15741 | crtc_state->port_clock == 0; |
| 15742 | } |
| 15743 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15744 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15745 | { |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15746 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15747 | struct intel_connector *connector; |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15748 | struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); |
| 15749 | struct intel_crtc_state *crtc_state = crtc ? |
| 15750 | to_intel_crtc_state(crtc->base.state) : NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15751 | |
| 15752 | /* We need to check both for a crtc link (meaning that the |
| 15753 | * encoder is active and trying to read from a pipe) and the |
| 15754 | * pipe itself being active. */ |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15755 | bool has_active_crtc = crtc_state && |
| 15756 | crtc_state->base.active; |
| 15757 | |
| 15758 | if (crtc_state && has_bogus_dpll_config(crtc_state)) { |
| 15759 | DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n", |
| 15760 | pipe_name(crtc->pipe)); |
| 15761 | has_active_crtc = false; |
| 15762 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15763 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15764 | connector = intel_encoder_find_connector(encoder); |
| 15765 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15766 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15767 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15768 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15769 | |
| 15770 | /* Connector is active, but has no active pipe. This is |
| 15771 | * fallout from our resume register restoring. Disable |
| 15772 | * the encoder manually again. */ |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15773 | if (crtc_state) { |
| 15774 | struct drm_encoder *best_encoder; |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15775 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15776 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15777 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15778 | encoder->base.name); |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15779 | |
| 15780 | /* avoid oopsing in case the hooks consult best_encoder */ |
| 15781 | best_encoder = connector->base.state->best_encoder; |
| 15782 | connector->base.state->best_encoder = &encoder->base; |
| 15783 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 15784 | if (encoder->disable) |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15785 | encoder->disable(encoder, crtc_state, |
| 15786 | connector->base.state); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15787 | if (encoder->post_disable) |
Ville Syrjälä | 7bed8ad | 2019-01-11 19:49:50 +0200 | [diff] [blame] | 15788 | encoder->post_disable(encoder, crtc_state, |
| 15789 | connector->base.state); |
| 15790 | |
| 15791 | connector->base.state->best_encoder = best_encoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15792 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15793 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15794 | |
| 15795 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15796 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15797 | * in our code, like the register restore mess on resume. Clamp |
| 15798 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15799 | |
| 15800 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15801 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15802 | } |
Maarten Lankhorst | d6cae4a | 2018-05-16 10:50:38 +0200 | [diff] [blame] | 15803 | |
| 15804 | /* notify opregion of the sanitized encoder state */ |
| 15805 | intel_opregion_notify_encoder(encoder, connector && has_active_crtc); |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15806 | |
| 15807 | if (INTEL_GEN(dev_priv) >= 11) |
| 15808 | icl_sanitize_encoder_pll_mapping(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15809 | } |
| 15810 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15811 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15812 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15813 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15814 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15815 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15816 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15817 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15818 | } |
| 15819 | } |
| 15820 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15821 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15822 | { |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15823 | intel_wakeref_t wakeref; |
| 15824 | |
| 15825 | /* |
| 15826 | * This function can be called both from intel_modeset_setup_hw_state or |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15827 | * at a very early point in our resume sequence, where the power well |
| 15828 | * structures are not yet restored. Since this function is at a very |
| 15829 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15830 | * level, just check if the power well is enabled instead of trying to |
| 15831 | * follow the "don't touch the power well if we don't need it" policy |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15832 | * the rest of the driver uses. |
| 15833 | */ |
| 15834 | wakeref = intel_display_power_get_if_enabled(dev_priv, |
| 15835 | POWER_DOMAIN_VGA); |
| 15836 | if (!wakeref) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15837 | return; |
| 15838 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15839 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15840 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15841 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15842 | } |
| 15843 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15844 | /* FIXME read out full plane state for all planes */ |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15845 | static void readout_plane_state(struct drm_i915_private *dev_priv) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15846 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15847 | struct intel_plane *plane; |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15848 | struct intel_crtc *crtc; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15849 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15850 | for_each_intel_plane(&dev_priv->drm, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15851 | struct intel_plane_state *plane_state = |
| 15852 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15853 | struct intel_crtc_state *crtc_state; |
| 15854 | enum pipe pipe = PIPE_A; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 15855 | bool visible; |
| 15856 | |
| 15857 | visible = plane->get_hw_state(plane, &pipe); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15858 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15859 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15860 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15861 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15862 | intel_set_plane_visible(crtc_state, plane_state, visible); |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15863 | |
| 15864 | DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n", |
| 15865 | plane->base.base.id, plane->base.name, |
| 15866 | enableddisabled(visible), pipe_name(pipe)); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15867 | } |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15868 | |
| 15869 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15870 | struct intel_crtc_state *crtc_state = |
| 15871 | to_intel_crtc_state(crtc->base.state); |
| 15872 | |
| 15873 | fixup_active_planes(crtc_state); |
| 15874 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15875 | } |
| 15876 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15877 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15878 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15879 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15880 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15881 | struct intel_crtc *crtc; |
| 15882 | struct intel_encoder *encoder; |
| 15883 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15884 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15885 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15886 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15887 | dev_priv->active_crtcs = 0; |
| 15888 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15889 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15890 | struct intel_crtc_state *crtc_state = |
| 15891 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15892 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15893 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15894 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15895 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15896 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15897 | crtc_state->base.active = crtc_state->base.enable = |
| 15898 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15899 | |
| 15900 | crtc->base.enabled = crtc_state->base.enable; |
| 15901 | crtc->active = crtc_state->base.active; |
| 15902 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15903 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15904 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15905 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15906 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15907 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15908 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15909 | } |
| 15910 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15911 | readout_plane_state(dev_priv); |
| 15912 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15913 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15914 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15915 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15916 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15917 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15918 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15919 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15920 | struct intel_crtc_state *crtc_state = |
| 15921 | to_intel_crtc_state(crtc->base.state); |
| 15922 | |
| 15923 | if (crtc_state->base.active && |
| 15924 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15925 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15926 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15927 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15928 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15929 | 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] | 15930 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15931 | } |
| 15932 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15933 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15934 | pipe = 0; |
| 15935 | |
| 15936 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15937 | struct intel_crtc_state *crtc_state; |
| 15938 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15939 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15940 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15941 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15942 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15943 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15944 | } else { |
| 15945 | encoder->base.crtc = NULL; |
| 15946 | } |
| 15947 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15948 | 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] | 15949 | encoder->base.base.id, encoder->base.name, |
| 15950 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15951 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15952 | } |
| 15953 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15954 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15955 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15956 | if (connector->get_hw_state(connector)) { |
| 15957 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15958 | |
| 15959 | encoder = connector->encoder; |
| 15960 | connector->base.encoder = &encoder->base; |
| 15961 | |
| 15962 | if (encoder->base.crtc && |
| 15963 | encoder->base.crtc->state->active) { |
| 15964 | /* |
| 15965 | * This has to be done during hardware readout |
| 15966 | * because anything calling .crtc_disable may |
| 15967 | * rely on the connector_mask being accurate. |
| 15968 | */ |
| 15969 | encoder->base.crtc->state->connector_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15970 | drm_connector_mask(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15971 | encoder->base.crtc->state->encoder_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15972 | drm_encoder_mask(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15973 | } |
| 15974 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15975 | } else { |
| 15976 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15977 | connector->base.encoder = NULL; |
| 15978 | } |
| 15979 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15980 | connector->base.base.id, connector->base.name, |
| 15981 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15982 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15983 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15984 | |
| 15985 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15986 | struct intel_crtc_state *crtc_state = |
| 15987 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15988 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15989 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15990 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15991 | if (crtc_state->base.active) { |
| 15992 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15993 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15994 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15995 | 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] | 15996 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15997 | |
| 15998 | /* |
| 15999 | * The initial mode needs to be set in order to keep |
| 16000 | * the atomic core happy. It wants a valid mode if the |
| 16001 | * crtc's enabled, so we do the above call. |
| 16002 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 16003 | * But we don't set all the derived state fully, hence |
| 16004 | * set a flag to indicate that a full recalculation is |
| 16005 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16006 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 16007 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 16008 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 16009 | intel_crtc_compute_pixel_rate(crtc_state); |
| 16010 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 16011 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 16012 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 16013 | if (WARN_ON(min_cdclk < 0)) |
| 16014 | min_cdclk = 0; |
| 16015 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 16016 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 16017 | drm_calc_timestamping_constants(&crtc->base, |
| 16018 | &crtc_state->base.adjusted_mode); |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 16019 | update_scanline_offset(crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16020 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 16021 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 16022 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 16023 | dev_priv->min_voltage_level[crtc->pipe] = |
| 16024 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 16025 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 16026 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16027 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16028 | } |
| 16029 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 16030 | static void |
| 16031 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 16032 | { |
| 16033 | struct intel_encoder *encoder; |
| 16034 | |
| 16035 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 16036 | u64 get_domains; |
| 16037 | enum intel_display_power_domain domain; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16038 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 16039 | |
| 16040 | if (!encoder->get_power_domains) |
| 16041 | continue; |
| 16042 | |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16043 | /* |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 16044 | * MST-primary and inactive encoders don't have a crtc state |
| 16045 | * and neither of these require any power domain references. |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16046 | */ |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 16047 | if (!encoder->base.crtc) |
| 16048 | continue; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16049 | |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 16050 | crtc_state = to_intel_crtc_state(encoder->base.crtc->state); |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 16051 | get_domains = encoder->get_power_domains(encoder, crtc_state); |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 16052 | for_each_power_domain(domain, get_domains) |
| 16053 | intel_display_power_get(dev_priv, domain); |
| 16054 | } |
| 16055 | } |
| 16056 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 16057 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 16058 | { |
| 16059 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 16060 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 16061 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 16062 | DARBF_GATING_DIS); |
| 16063 | |
| 16064 | if (IS_HASWELL(dev_priv)) { |
| 16065 | /* |
| 16066 | * WaRsPkgCStateDisplayPMReq:hsw |
| 16067 | * System hang if this isn't done before disabling all planes! |
| 16068 | */ |
| 16069 | I915_WRITE(CHICKEN_PAR1_1, |
| 16070 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 16071 | } |
| 16072 | } |
| 16073 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 16074 | static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv, |
| 16075 | enum port port, i915_reg_t hdmi_reg) |
| 16076 | { |
| 16077 | u32 val = I915_READ(hdmi_reg); |
| 16078 | |
| 16079 | if (val & SDVO_ENABLE || |
| 16080 | (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A)) |
| 16081 | return; |
| 16082 | |
| 16083 | DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n", |
| 16084 | port_name(port)); |
| 16085 | |
| 16086 | val &= ~SDVO_PIPE_SEL_MASK; |
| 16087 | val |= SDVO_PIPE_SEL(PIPE_A); |
| 16088 | |
| 16089 | I915_WRITE(hdmi_reg, val); |
| 16090 | } |
| 16091 | |
| 16092 | static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv, |
| 16093 | enum port port, i915_reg_t dp_reg) |
| 16094 | { |
| 16095 | u32 val = I915_READ(dp_reg); |
| 16096 | |
| 16097 | if (val & DP_PORT_EN || |
| 16098 | (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A)) |
| 16099 | return; |
| 16100 | |
| 16101 | DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n", |
| 16102 | port_name(port)); |
| 16103 | |
| 16104 | val &= ~DP_PIPE_SEL_MASK; |
| 16105 | val |= DP_PIPE_SEL(PIPE_A); |
| 16106 | |
| 16107 | I915_WRITE(dp_reg, val); |
| 16108 | } |
| 16109 | |
| 16110 | static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv) |
| 16111 | { |
| 16112 | /* |
| 16113 | * The BIOS may select transcoder B on some of the PCH |
| 16114 | * ports even it doesn't enable the port. This would trip |
| 16115 | * assert_pch_dp_disabled() and assert_pch_hdmi_disabled(). |
| 16116 | * Sanitize the transcoder select bits to prevent that. We |
| 16117 | * assume that the BIOS never actually enabled the port, |
| 16118 | * because if it did we'd actually have to toggle the port |
| 16119 | * on and back off to make the transcoder A select stick |
| 16120 | * (see. intel_dp_link_down(), intel_disable_hdmi(), |
| 16121 | * intel_disable_sdvo()). |
| 16122 | */ |
| 16123 | ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B); |
| 16124 | ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C); |
| 16125 | ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D); |
| 16126 | |
| 16127 | /* PCH SDVOB multiplex with HDMIB */ |
| 16128 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB); |
| 16129 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC); |
| 16130 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID); |
| 16131 | } |
| 16132 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16133 | /* Scan out the current hw modeset state, |
| 16134 | * and sanitizes it to the current state |
| 16135 | */ |
| 16136 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 16137 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 16138 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16139 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16140 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16141 | struct intel_crtc_state *crtc_state; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16142 | struct intel_encoder *encoder; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 16143 | struct intel_crtc *crtc; |
| 16144 | intel_wakeref_t wakeref; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16145 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16146 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 16147 | wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 16148 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 16149 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16150 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16151 | |
| 16152 | /* 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] | 16153 | get_encoder_power_domains(dev_priv); |
| 16154 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 16155 | if (HAS_PCH_IBX(dev_priv)) |
| 16156 | ibx_sanitize_pch_ports(dev_priv); |
| 16157 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16158 | /* |
| 16159 | * intel_sanitize_plane_mapping() may need to do vblank |
| 16160 | * waits, so we need vblank interrupts restored beforehand. |
| 16161 | */ |
| 16162 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 16163 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 16164 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16165 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 16166 | |
Ville Syrjälä | 32db0b6 | 2018-11-27 22:05:50 +0200 | [diff] [blame] | 16167 | if (crtc_state->base.active) |
| 16168 | intel_crtc_vblank_on(crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16169 | } |
| 16170 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16171 | intel_sanitize_plane_mapping(dev_priv); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 16172 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 16173 | for_each_intel_encoder(dev, encoder) |
| 16174 | intel_sanitize_encoder(encoder); |
| 16175 | |
| 16176 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16177 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 16178 | intel_sanitize_crtc(crtc, ctx); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16179 | intel_dump_pipe_config(crtc, crtc_state, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 16180 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16181 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 16182 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 16183 | intel_modeset_update_connector_atomic_state(dev); |
| 16184 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16185 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 16186 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 16187 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 16188 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16189 | continue; |
| 16190 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 16191 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 16192 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16193 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 16194 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 16195 | pll->on = false; |
| 16196 | } |
| 16197 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 16198 | if (IS_G4X(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16199 | g4x_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 16200 | g4x_wm_sanitize(dev_priv); |
| 16201 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16202 | vlv_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 16203 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 16204 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16205 | skl_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 16206 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 16207 | ilk_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 16208 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16209 | |
| 16210 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 16211 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16212 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 16213 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 16214 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 16215 | if (WARN_ON(put_domains)) |
| 16216 | modeset_put_power_domains(dev_priv, put_domains); |
| 16217 | } |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 16218 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 16219 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 16220 | |
| 16221 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16222 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 16223 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16224 | void intel_display_resume(struct drm_device *dev) |
| 16225 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16226 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 16227 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 16228 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16229 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 16230 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16231 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16232 | if (state) |
| 16233 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16234 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16235 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16236 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16237 | while (1) { |
| 16238 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 16239 | if (ret != -EDEADLK) |
| 16240 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16241 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16242 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16243 | } |
| 16244 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16245 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 16246 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 16247 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 16248 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16249 | drm_modeset_drop_locks(&ctx); |
| 16250 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16251 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 16252 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 16253 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 16254 | if (state) |
| 16255 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 16256 | } |
| 16257 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16258 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 16259 | { |
| 16260 | struct intel_connector *connector; |
| 16261 | struct drm_connector_list_iter conn_iter; |
| 16262 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 16263 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16264 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 16265 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 16266 | if (connector->modeset_retry_work.func) |
| 16267 | cancel_work_sync(&connector->modeset_retry_work); |
Ramalingam C | d3dacc7 | 2018-10-29 15:15:46 +0530 | [diff] [blame] | 16268 | if (connector->hdcp.shim) { |
| 16269 | cancel_delayed_work_sync(&connector->hdcp.check_work); |
| 16270 | cancel_work_sync(&connector->hdcp.prop_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 16271 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16272 | } |
| 16273 | drm_connector_list_iter_end(&conn_iter); |
| 16274 | } |
| 16275 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16276 | void intel_modeset_cleanup(struct drm_device *dev) |
| 16277 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16278 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 16279 | |
Chris Wilson | 8bcf9f7 | 2018-07-10 10:44:20 +0100 | [diff] [blame] | 16280 | flush_workqueue(dev_priv->modeset_wq); |
| 16281 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 16282 | flush_work(&dev_priv->atomic_helper.free_work); |
| 16283 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 16284 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16285 | /* |
| 16286 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 16287 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16288 | * experience fancy races otherwise. |
| 16289 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 16290 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 16291 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16292 | /* |
| 16293 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 16294 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 16295 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16296 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16297 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 16298 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 16299 | intel_fbdev_fini(dev_priv); |
| 16300 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 16301 | intel_unregister_dsm_handler(); |
| 16302 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 16303 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 16304 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 16305 | /* flush any delayed tasks or pending work */ |
| 16306 | flush_scheduled_work(); |
| 16307 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16308 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 16309 | |
José Roberto de Souza | 58db08a7 | 2018-11-07 16:16:47 -0800 | [diff] [blame] | 16310 | intel_overlay_cleanup(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16311 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 16312 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 16313 | |
| 16314 | destroy_workqueue(dev_priv->modeset_wq); |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 16315 | |
| 16316 | intel_fbc_cleanup_cfb(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16317 | } |
| 16318 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16319 | /* |
| 16320 | * set vga decode state - true == enable VGA decode |
| 16321 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16322 | 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] | 16323 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16324 | 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] | 16325 | u16 gmch_ctrl; |
| 16326 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16327 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 16328 | DRM_ERROR("failed to read control word\n"); |
| 16329 | return -EIO; |
| 16330 | } |
| 16331 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 16332 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 16333 | return 0; |
| 16334 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16335 | if (state) |
| 16336 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 16337 | else |
| 16338 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16339 | |
| 16340 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 16341 | DRM_ERROR("failed to write control word\n"); |
| 16342 | return -EIO; |
| 16343 | } |
| 16344 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16345 | return 0; |
| 16346 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16347 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16348 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 16349 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16350 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16351 | |
| 16352 | u32 power_well_driver; |
| 16353 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16354 | int num_transcoders; |
| 16355 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16356 | struct intel_cursor_error_state { |
| 16357 | u32 control; |
| 16358 | u32 position; |
| 16359 | u32 base; |
| 16360 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16361 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16362 | |
| 16363 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16364 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16365 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16366 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16367 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16368 | |
| 16369 | struct intel_plane_error_state { |
| 16370 | u32 control; |
| 16371 | u32 stride; |
| 16372 | u32 size; |
| 16373 | u32 pos; |
| 16374 | u32 addr; |
| 16375 | u32 surface; |
| 16376 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16377 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16378 | |
| 16379 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16380 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16381 | enum transcoder cpu_transcoder; |
| 16382 | |
| 16383 | u32 conf; |
| 16384 | |
| 16385 | u32 htotal; |
| 16386 | u32 hblank; |
| 16387 | u32 hsync; |
| 16388 | u32 vtotal; |
| 16389 | u32 vblank; |
| 16390 | u32 vsync; |
| 16391 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16392 | }; |
| 16393 | |
| 16394 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16395 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16396 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16397 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16398 | int transcoders[] = { |
| 16399 | TRANSCODER_A, |
| 16400 | TRANSCODER_B, |
| 16401 | TRANSCODER_C, |
| 16402 | TRANSCODER_EDP, |
| 16403 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16404 | int i; |
| 16405 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 16406 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16407 | return NULL; |
| 16408 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16409 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16410 | if (error == NULL) |
| 16411 | return NULL; |
| 16412 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16413 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 16414 | error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16415 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16416 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16417 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16418 | __intel_display_power_is_enabled(dev_priv, |
| 16419 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16420 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16421 | continue; |
| 16422 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16423 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16424 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16425 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16426 | |
| 16427 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16428 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16429 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16430 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16431 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16432 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16433 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16434 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16435 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16436 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16437 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16438 | } |
| 16439 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16440 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16441 | |
Rodrigo Vivi | b2ae318 | 2019-02-04 14:25:38 -0800 | [diff] [blame] | 16442 | if (HAS_GMCH(dev_priv)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16443 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16444 | } |
| 16445 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16446 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16447 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 16448 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16449 | error->num_transcoders++; /* Account for eDP. */ |
| 16450 | |
| 16451 | for (i = 0; i < error->num_transcoders; i++) { |
| 16452 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16453 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16454 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16455 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16456 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16457 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16458 | continue; |
| 16459 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16460 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16461 | |
| 16462 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16463 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16464 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16465 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16466 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16467 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16468 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16469 | } |
| 16470 | |
| 16471 | return error; |
| 16472 | } |
| 16473 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16474 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16475 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16476 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16477 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16478 | struct intel_display_error_state *error) |
| 16479 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 16480 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16481 | int i; |
| 16482 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16483 | if (!error) |
| 16484 | return; |
| 16485 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16486 | 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] | 16487 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16488 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16489 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16490 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16491 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16492 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16493 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16494 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16495 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16496 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16497 | err_printf(m, "Plane [%d]:\n", i); |
| 16498 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16499 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16500 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16501 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16502 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16503 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 16504 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16505 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16506 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16507 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16508 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16509 | } |
| 16510 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16511 | err_printf(m, "Cursor [%d]:\n", i); |
| 16512 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16513 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16514 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16515 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16516 | |
| 16517 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16518 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16519 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16520 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16521 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16522 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16523 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16524 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16525 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16526 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16527 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16528 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16529 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16530 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16531 | |
| 16532 | #endif |