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 | 72fdb40 | 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ä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1761 | 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] | 1762 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1763 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
| 1764 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1765 | enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1766 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1767 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1768 | u32 val; |
| 1769 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1770 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1771 | |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1772 | assert_planes_disabled(crtc); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1773 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1774 | /* |
| 1775 | * A pipe without a PLL won't actually be able to drive bits from |
| 1776 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1777 | * need the check. |
| 1778 | */ |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1779 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1780 | if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1781 | assert_dsi_pll_enabled(dev_priv); |
| 1782 | else |
| 1783 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1784 | } else { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1785 | if (new_crtc_state->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1786 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1787 | assert_fdi_rx_pll_enabled(dev_priv, |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 1788 | intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1789 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1790 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1791 | } |
| 1792 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1793 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1794 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1795 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1796 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1797 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1798 | /* we keep both pipes enabled on 830 */ |
| 1799 | WARN_ON(!IS_I830(dev_priv)); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1800 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1801 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1802 | |
| 1803 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1804 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1805 | |
| 1806 | /* |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1807 | * Until the pipe starts PIPEDSL reads will return a stale value, |
| 1808 | * which causes an apparent vblank timestamp jump when PIPEDSL |
| 1809 | * resets to its proper value. That also messes up the frame count |
| 1810 | * when it's derived from the timestamps. So let's wait for the |
| 1811 | * pipe to start properly before we call drm_crtc_vblank_on() |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1812 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1813 | if (dev_priv->drm.max_vblank_count == 0) |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 1814 | intel_wait_for_pipe_scanline_moving(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1815 | } |
| 1816 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1817 | 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] | 1818 | { |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1819 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1820 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1821 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1822 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1823 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1824 | u32 val; |
| 1825 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1826 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 1827 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1828 | /* |
| 1829 | * Make sure planes won't keep trying to pump pixels to us, |
| 1830 | * or we might hang the display. |
| 1831 | */ |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 1832 | assert_planes_disabled(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1833 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1834 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1835 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1836 | if ((val & PIPECONF_ENABLE) == 0) |
| 1837 | return; |
| 1838 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1839 | /* |
| 1840 | * Double wide has implications for planes |
| 1841 | * so best keep it disabled when not needed. |
| 1842 | */ |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1843 | if (old_crtc_state->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1844 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 1845 | |
| 1846 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 1847 | if (!IS_I830(dev_priv)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 1848 | val &= ~PIPECONF_ENABLE; |
| 1849 | |
| 1850 | I915_WRITE(reg, val); |
| 1851 | if ((val & PIPECONF_ENABLE) == 0) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 1852 | intel_wait_for_pipe_off(old_crtc_state); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1853 | } |
| 1854 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1855 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 1856 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1857 | return IS_GEN(dev_priv, 2) ? 2048 : 4096; |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1860 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1861 | 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] | 1862 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1863 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1864 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1865 | |
| 1866 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1867 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1868 | return cpp; |
| 1869 | case I915_FORMAT_MOD_X_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1870 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1871 | return 128; |
| 1872 | else |
| 1873 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1874 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1875 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1876 | return 128; |
| 1877 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1878 | case I915_FORMAT_MOD_Y_TILED: |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1879 | 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] | 1880 | return 128; |
| 1881 | else |
| 1882 | return 512; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1883 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1884 | if (color_plane == 1) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 1885 | return 128; |
| 1886 | /* fall through */ |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1887 | case I915_FORMAT_MOD_Yf_TILED: |
| 1888 | switch (cpp) { |
| 1889 | case 1: |
| 1890 | return 64; |
| 1891 | case 2: |
| 1892 | case 4: |
| 1893 | return 128; |
| 1894 | case 8: |
| 1895 | case 16: |
| 1896 | return 256; |
| 1897 | default: |
| 1898 | MISSING_CASE(cpp); |
| 1899 | return cpp; |
| 1900 | } |
| 1901 | break; |
| 1902 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1903 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 1904 | return cpp; |
| 1905 | } |
| 1906 | } |
| 1907 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1908 | static unsigned int |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1909 | intel_tile_height(const struct drm_framebuffer *fb, int color_plane) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1910 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1911 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1912 | return 1; |
| 1913 | else |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1914 | return intel_tile_size(to_i915(fb->dev)) / |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1915 | intel_tile_width_bytes(fb, color_plane); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1918 | /* Return the tile dimensions in pixel units */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1919 | 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] | 1920 | unsigned int *tile_width, |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1921 | unsigned int *tile_height) |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1922 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1923 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane); |
| 1924 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 1925 | |
| 1926 | *tile_width = tile_width_bytes / cpp; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1927 | *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] | 1928 | } |
| 1929 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1930 | unsigned int |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1931 | intel_fb_align_height(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1932 | int color_plane, unsigned int height) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 1933 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1934 | unsigned int tile_height = intel_tile_height(fb, color_plane); |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 1935 | |
| 1936 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 1937 | } |
| 1938 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 1939 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 1940 | { |
| 1941 | unsigned int size = 0; |
| 1942 | int i; |
| 1943 | |
| 1944 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 1945 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 1946 | |
| 1947 | return size; |
| 1948 | } |
| 1949 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 1950 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 1951 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 1952 | const struct drm_framebuffer *fb, |
| 1953 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 1954 | { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1955 | view->type = I915_GGTT_VIEW_NORMAL; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 1956 | if (drm_rotation_90_or_270(rotation)) { |
Chris Wilson | 7b92c04 | 2017-01-14 00:28:26 +0000 | [diff] [blame] | 1957 | view->type = I915_GGTT_VIEW_ROTATED; |
Chris Wilson | 8bab1193 | 2017-01-14 00:28:25 +0000 | [diff] [blame] | 1958 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 1959 | } |
| 1960 | } |
| 1961 | |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1962 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
| 1963 | { |
| 1964 | if (IS_I830(dev_priv)) |
| 1965 | return 16 * 1024; |
| 1966 | else if (IS_I85X(dev_priv)) |
| 1967 | return 256; |
Ville Syrjälä | d9e1551 | 2017-03-27 21:55:45 +0300 | [diff] [blame] | 1968 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
| 1969 | return 32; |
Ville Syrjälä | fabac48 | 2017-03-27 21:55:43 +0300 | [diff] [blame] | 1970 | else |
| 1971 | return 4 * 1024; |
| 1972 | } |
| 1973 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1974 | 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] | 1975 | { |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1976 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1977 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 1978 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1979 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1980 | return 128 * 1024; |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 1981 | else if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1982 | return 4 * 1024; |
| 1983 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 1984 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 1985 | } |
| 1986 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1987 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1988 | int color_plane) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1989 | { |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1990 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 1991 | |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 1992 | /* AUX_DIST needs only 4K alignment */ |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 1993 | if (color_plane == 1) |
Ville Syrjälä | b90c1ee | 2017-03-07 21:42:07 +0200 | [diff] [blame] | 1994 | return 4096; |
| 1995 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 1996 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 1997 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 1998 | return intel_linear_alignment(dev_priv); |
| 1999 | case I915_FORMAT_MOD_X_TILED: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2000 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2001 | return 256 * 1024; |
| 2002 | return 0; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2003 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2004 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2005 | case I915_FORMAT_MOD_Y_TILED: |
| 2006 | case I915_FORMAT_MOD_Yf_TILED: |
| 2007 | return 1 * 1024 * 1024; |
| 2008 | default: |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2009 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2010 | return 0; |
| 2011 | } |
| 2012 | } |
| 2013 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2014 | static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) |
| 2015 | { |
| 2016 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2017 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 2018 | |
Ville Syrjälä | 32febd9 | 2018-02-21 18:02:33 +0200 | [diff] [blame] | 2019 | return INTEL_GEN(dev_priv) < 4 || plane->has_fbc; |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2020 | } |
| 2021 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2022 | struct i915_vma * |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2023 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2024 | const struct i915_ggtt_view *view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2025 | bool uses_fence, |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2026 | unsigned long *out_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2027 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2028 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2029 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2030 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2031 | intel_wakeref_t wakeref; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2032 | struct i915_vma *vma; |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2033 | unsigned int pinctl; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2034 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2035 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2036 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2037 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2038 | alignment = intel_surf_alignment(fb, 0); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2039 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2040 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2041 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2042 | * we should always have valid PTE following the scanout preventing |
| 2043 | * the VT-d warning. |
| 2044 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2045 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2046 | alignment = 256 * 1024; |
| 2047 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2048 | /* |
| 2049 | * Global gtt pte registers are special registers which actually forward |
| 2050 | * writes to a chunk of system memory. Which means that there is no risk |
| 2051 | * that the register values disappear as soon as we call |
| 2052 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2053 | * pin/unpin/fence and not more. |
| 2054 | */ |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2055 | wakeref = intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2056 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2057 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
| 2058 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2059 | pinctl = 0; |
| 2060 | |
| 2061 | /* Valleyview is definitely limited to scanning out the first |
| 2062 | * 512MiB. Lets presume this behaviour was inherited from the |
| 2063 | * g4x display engine and that all earlier gen are similarly |
| 2064 | * limited. Testing suggests that it is a little more |
| 2065 | * complicated than this. For example, Cherryview appears quite |
| 2066 | * happy to scanout from anywhere within its global aperture. |
| 2067 | */ |
| 2068 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 2069 | pinctl |= PIN_MAPPABLE; |
| 2070 | |
| 2071 | vma = i915_gem_object_pin_to_display_plane(obj, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2072 | alignment, view, pinctl); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2073 | if (IS_ERR(vma)) |
| 2074 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2075 | |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2076 | if (uses_fence && i915_vma_is_map_and_fenceable(vma)) { |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2077 | int ret; |
| 2078 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2079 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2080 | * fence, whereas 965+ only requires a fence if using |
| 2081 | * framebuffer compression. For simplicity, we always, when |
| 2082 | * possible, install a fence as the cost is not that onerous. |
| 2083 | * |
| 2084 | * If we fail to fence the tiled scanout, then either the |
| 2085 | * modeset will reject the change (which is highly unlikely as |
| 2086 | * the affected systems, all but one, do not have unmappable |
| 2087 | * space) or we will not be able to enable full powersaving |
| 2088 | * techniques (also likely not to apply due to various limits |
| 2089 | * FBC and the like impose on the size of the buffer, which |
| 2090 | * presumably we violated anyway with this unmappable buffer). |
| 2091 | * Anyway, it is presumably better to stumble onwards with |
| 2092 | * something and try to run the system in a "less than optimal" |
| 2093 | * mode that matches the user configuration. |
| 2094 | */ |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2095 | ret = i915_vma_pin_fence(vma); |
| 2096 | if (ret != 0 && INTEL_GEN(dev_priv) < 4) { |
Chris Wilson | 7509702 | 2018-03-05 10:33:12 +0000 | [diff] [blame] | 2097 | i915_gem_object_unpin_from_display_plane(vma); |
Ville Syrjälä | 85798ac | 2018-02-21 18:02:30 +0200 | [diff] [blame] | 2098 | vma = ERR_PTR(ret); |
| 2099 | goto err; |
| 2100 | } |
| 2101 | |
| 2102 | if (ret == 0 && vma->fence) |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2103 | *out_flags |= PLANE_HAS_FENCE; |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2104 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2105 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2106 | i915_vma_get(vma); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2107 | err: |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 2108 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
| 2109 | |
Chris Wilson | 1d264d9 | 2019-01-14 14:21:19 +0000 | [diff] [blame] | 2110 | intel_runtime_pm_put(dev_priv, wakeref); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2111 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2112 | } |
| 2113 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2114 | void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2115 | { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2116 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2117 | |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2118 | if (flags & PLANE_HAS_FENCE) |
| 2119 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2120 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2121 | i915_vma_put(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2122 | } |
| 2123 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2124 | 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] | 2125 | unsigned int rotation) |
| 2126 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2127 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2128 | return to_intel_framebuffer(fb)->rotated[color_plane].pitch; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2129 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2130 | return fb->pitches[color_plane]; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2131 | } |
| 2132 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2133 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2134 | * Convert the x/y offsets into a linear offset. |
| 2135 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2136 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2137 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2138 | */ |
| 2139 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2140 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2141 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2142 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2143 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2144 | unsigned int cpp = fb->format->cpp[color_plane]; |
| 2145 | unsigned int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2146 | |
| 2147 | return y * pitch + x * cpp; |
| 2148 | } |
| 2149 | |
| 2150 | /* |
| 2151 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2152 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2153 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2154 | */ |
| 2155 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2156 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2157 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2158 | |
| 2159 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2160 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2161 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2162 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2163 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2164 | *x += intel_fb->rotated[color_plane].x; |
| 2165 | *y += intel_fb->rotated[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2166 | } else { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2167 | *x += intel_fb->normal[color_plane].x; |
| 2168 | *y += intel_fb->normal[color_plane].y; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2169 | } |
| 2170 | } |
| 2171 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2172 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2173 | unsigned int tile_width, |
| 2174 | unsigned int tile_height, |
| 2175 | unsigned int tile_size, |
| 2176 | unsigned int pitch_tiles, |
| 2177 | u32 old_offset, |
| 2178 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2179 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2180 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2181 | unsigned int tiles; |
| 2182 | |
| 2183 | WARN_ON(old_offset & (tile_size - 1)); |
| 2184 | WARN_ON(new_offset & (tile_size - 1)); |
| 2185 | WARN_ON(new_offset > old_offset); |
| 2186 | |
| 2187 | tiles = (old_offset - new_offset) / tile_size; |
| 2188 | |
| 2189 | *y += tiles / pitch_tiles * tile_height; |
| 2190 | *x += tiles % pitch_tiles * tile_width; |
| 2191 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2192 | /* minimize x in case it got needlessly big */ |
| 2193 | *y += *x / pitch_pixels * tile_height; |
| 2194 | *x %= pitch_pixels; |
| 2195 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2196 | return new_offset; |
| 2197 | } |
| 2198 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2199 | static bool is_surface_linear(u64 modifier, int color_plane) |
| 2200 | { |
| 2201 | return modifier == DRM_FORMAT_MOD_LINEAR; |
| 2202 | } |
| 2203 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2204 | static u32 intel_adjust_aligned_offset(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2205 | const struct drm_framebuffer *fb, |
| 2206 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2207 | unsigned int rotation, |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2208 | unsigned int pitch, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2209 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2210 | { |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2211 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2212 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2213 | |
| 2214 | WARN_ON(new_offset > old_offset); |
| 2215 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2216 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2217 | unsigned int tile_size, tile_width, tile_height; |
| 2218 | unsigned int pitch_tiles; |
| 2219 | |
| 2220 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2221 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2222 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2223 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2224 | pitch_tiles = pitch / tile_height; |
| 2225 | swap(tile_width, tile_height); |
| 2226 | } else { |
| 2227 | pitch_tiles = pitch / (tile_width * cpp); |
| 2228 | } |
| 2229 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2230 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2231 | tile_size, pitch_tiles, |
| 2232 | old_offset, new_offset); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2233 | } else { |
| 2234 | old_offset += *y * pitch + *x * cpp; |
| 2235 | |
| 2236 | *y = (old_offset - new_offset) / pitch; |
| 2237 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2238 | } |
| 2239 | |
| 2240 | return new_offset; |
| 2241 | } |
| 2242 | |
| 2243 | /* |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2244 | * Adjust the tile offset by moving the difference into |
| 2245 | * the x/y offsets. |
| 2246 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2247 | static u32 intel_plane_adjust_aligned_offset(int *x, int *y, |
| 2248 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2249 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2250 | u32 old_offset, u32 new_offset) |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2251 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2252 | 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] | 2253 | state->base.rotation, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2254 | state->color_plane[color_plane].stride, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2255 | old_offset, new_offset); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /* |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2259 | * Computes the aligned offset to the base tile and adjusts |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2260 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2261 | * |
| 2262 | * In the 90/270 rotated case, x and y are assumed |
| 2263 | * to be already rotated to match the rotated GTT view, and |
| 2264 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2265 | * |
| 2266 | * This function is used when computing the derived information |
| 2267 | * under intel_framebuffer, so using any of that information |
| 2268 | * here is not allowed. Anything under drm_framebuffer can be |
| 2269 | * used. This is why the user has to pass in the pitch since it |
| 2270 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2271 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2272 | static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv, |
| 2273 | int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2274 | const struct drm_framebuffer *fb, |
| 2275 | int color_plane, |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2276 | unsigned int pitch, |
| 2277 | unsigned int rotation, |
| 2278 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2279 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2280 | unsigned int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2281 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2282 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2283 | if (alignment) |
| 2284 | alignment--; |
| 2285 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2286 | if (!is_surface_linear(fb->modifier, color_plane)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2287 | unsigned int tile_size, tile_width, tile_height; |
| 2288 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2289 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2290 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2291 | intel_tile_dims(fb, color_plane, &tile_width, &tile_height); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2292 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2293 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2294 | pitch_tiles = pitch / tile_height; |
| 2295 | swap(tile_width, tile_height); |
| 2296 | } else { |
| 2297 | pitch_tiles = pitch / (tile_width * cpp); |
| 2298 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2299 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2300 | tile_rows = *y / tile_height; |
| 2301 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2302 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2303 | tiles = *x / tile_width; |
| 2304 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2305 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2306 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2307 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2308 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2309 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2310 | tile_size, pitch_tiles, |
| 2311 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2312 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2313 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2314 | offset_aligned = offset & ~alignment; |
| 2315 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2316 | *y = (offset & alignment) / pitch; |
| 2317 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2318 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2319 | |
| 2320 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2321 | } |
| 2322 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2323 | static u32 intel_plane_compute_aligned_offset(int *x, int *y, |
| 2324 | const struct intel_plane_state *state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2325 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2326 | { |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2327 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
| 2328 | 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] | 2329 | const struct drm_framebuffer *fb = state->base.fb; |
| 2330 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2331 | int pitch = state->color_plane[color_plane].stride; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 2332 | u32 alignment; |
| 2333 | |
| 2334 | if (intel_plane->id == PLANE_CURSOR) |
| 2335 | alignment = intel_cursor_alignment(dev_priv); |
| 2336 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2337 | alignment = intel_surf_alignment(fb, color_plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2338 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2339 | 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] | 2340 | pitch, rotation, alignment); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2341 | } |
| 2342 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2343 | /* Convert the fb->offset[] into x/y offsets */ |
| 2344 | static int intel_fb_offset_to_xy(int *x, int *y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2345 | const struct drm_framebuffer *fb, |
| 2346 | int color_plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2347 | { |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2348 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2349 | unsigned int height; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2350 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2351 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2352 | fb->offsets[color_plane] % intel_tile_size(dev_priv)) { |
| 2353 | DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n", |
| 2354 | fb->offsets[color_plane], color_plane); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2355 | return -EINVAL; |
Ville Syrjälä | 70bbe53 | 2018-10-23 19:02:01 +0300 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | height = drm_framebuffer_plane_height(fb->height, fb, color_plane); |
| 2359 | height = ALIGN(height, intel_tile_height(fb, color_plane)); |
| 2360 | |
| 2361 | /* Catch potential overflows early */ |
| 2362 | if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]), |
| 2363 | fb->offsets[color_plane])) { |
| 2364 | DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n", |
| 2365 | fb->offsets[color_plane], fb->pitches[color_plane], |
| 2366 | color_plane); |
| 2367 | return -ERANGE; |
| 2368 | } |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2369 | |
| 2370 | *x = 0; |
| 2371 | *y = 0; |
| 2372 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2373 | intel_adjust_aligned_offset(x, y, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2374 | fb, color_plane, DRM_MODE_ROTATE_0, |
| 2375 | fb->pitches[color_plane], |
| 2376 | fb->offsets[color_plane], 0); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2377 | |
| 2378 | return 0; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2379 | } |
| 2380 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 2381 | static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier) |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2382 | { |
| 2383 | switch (fb_modifier) { |
| 2384 | case I915_FORMAT_MOD_X_TILED: |
| 2385 | return I915_TILING_X; |
| 2386 | case I915_FORMAT_MOD_Y_TILED: |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2387 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2388 | return I915_TILING_Y; |
| 2389 | default: |
| 2390 | return I915_TILING_NONE; |
| 2391 | } |
| 2392 | } |
| 2393 | |
Ville Syrjälä | 16af25f | 2018-01-19 16:41:52 +0200 | [diff] [blame] | 2394 | /* |
| 2395 | * From the Sky Lake PRM: |
| 2396 | * "The Color Control Surface (CCS) contains the compression status of |
| 2397 | * the cache-line pairs. The compression state of the cache-line pair |
| 2398 | * is specified by 2 bits in the CCS. Each CCS cache-line represents |
| 2399 | * an area on the main surface of 16 x16 sets of 128 byte Y-tiled |
| 2400 | * cache-line-pairs. CCS is always Y tiled." |
| 2401 | * |
| 2402 | * Since cache line pairs refers to horizontally adjacent cache lines, |
| 2403 | * each cache line in the CCS corresponds to an area of 32x16 cache |
| 2404 | * lines on the main surface. Since each pixel is 4 bytes, this gives |
| 2405 | * us a ratio of one byte in the CCS for each 8x16 pixels in the |
| 2406 | * main surface. |
| 2407 | */ |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 2408 | static const struct drm_format_info ccs_formats[] = { |
| 2409 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2410 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2411 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2412 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, |
| 2413 | }; |
| 2414 | |
| 2415 | static const struct drm_format_info * |
| 2416 | lookup_format_info(const struct drm_format_info formats[], |
| 2417 | int num_formats, u32 format) |
| 2418 | { |
| 2419 | int i; |
| 2420 | |
| 2421 | for (i = 0; i < num_formats; i++) { |
| 2422 | if (formats[i].format == format) |
| 2423 | return &formats[i]; |
| 2424 | } |
| 2425 | |
| 2426 | return NULL; |
| 2427 | } |
| 2428 | |
| 2429 | static const struct drm_format_info * |
| 2430 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) |
| 2431 | { |
| 2432 | switch (cmd->modifier[0]) { |
| 2433 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2434 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2435 | return lookup_format_info(ccs_formats, |
| 2436 | ARRAY_SIZE(ccs_formats), |
| 2437 | cmd->pixel_format); |
| 2438 | default: |
| 2439 | return NULL; |
| 2440 | } |
| 2441 | } |
| 2442 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2443 | bool is_ccs_modifier(u64 modifier) |
| 2444 | { |
| 2445 | return modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 2446 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 2447 | } |
| 2448 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2449 | static int |
| 2450 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2451 | struct drm_framebuffer *fb) |
| 2452 | { |
| 2453 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2454 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2455 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2456 | u32 gtt_offset_rotated = 0; |
| 2457 | unsigned int max_size = 0; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 2458 | int i, num_planes = fb->format->num_planes; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2459 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2460 | |
| 2461 | for (i = 0; i < num_planes; i++) { |
| 2462 | unsigned int width, height; |
| 2463 | unsigned int cpp, size; |
| 2464 | u32 offset; |
| 2465 | int x, y; |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2466 | int ret; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2467 | |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2468 | cpp = fb->format->cpp[i]; |
Ville Syrjälä | 145fcb1 | 2016-11-18 21:53:06 +0200 | [diff] [blame] | 2469 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
| 2470 | height = drm_framebuffer_plane_height(fb->height, fb, i); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2471 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2472 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2473 | if (ret) { |
| 2474 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2475 | i, fb->offsets[i]); |
| 2476 | return ret; |
| 2477 | } |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2478 | |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 2479 | if (is_ccs_modifier(fb->modifier) && i == 1) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2480 | int hsub = fb->format->hsub; |
| 2481 | int vsub = fb->format->vsub; |
| 2482 | int tile_width, tile_height; |
| 2483 | int main_x, main_y; |
| 2484 | int ccs_x, ccs_y; |
| 2485 | |
| 2486 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2487 | tile_width *= hsub; |
| 2488 | tile_height *= vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2489 | |
Ville Syrjälä | 303ba69 | 2017-08-24 22:10:49 +0300 | [diff] [blame] | 2490 | ccs_x = (x * hsub) % tile_width; |
| 2491 | ccs_y = (y * vsub) % tile_height; |
| 2492 | main_x = intel_fb->normal[0].x % tile_width; |
| 2493 | main_y = intel_fb->normal[0].y % tile_height; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2494 | |
| 2495 | /* |
| 2496 | * CCS doesn't have its own x/y offset register, so the intra CCS tile |
| 2497 | * x/y offsets must match between CCS and the main surface. |
| 2498 | */ |
| 2499 | if (main_x != ccs_x || main_y != ccs_y) { |
| 2500 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", |
| 2501 | main_x, main_y, |
| 2502 | ccs_x, ccs_y, |
| 2503 | intel_fb->normal[0].x, |
| 2504 | intel_fb->normal[0].y, |
| 2505 | x, y); |
| 2506 | return -EINVAL; |
| 2507 | } |
| 2508 | } |
| 2509 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2510 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2511 | * The fence (if used) is aligned to the start of the object |
| 2512 | * so having the framebuffer wrap around across the edge of the |
| 2513 | * fenced region doesn't really work. We have no API to configure |
| 2514 | * the fence start offset within the object (nor could we probably |
| 2515 | * on gen2/3). So it's just easier if we just require that the |
| 2516 | * fb layout agrees with the fence layout. We already check that the |
| 2517 | * fb stride matches the fence stride elsewhere. |
| 2518 | */ |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 2519 | if (i == 0 && i915_gem_object_is_tiled(obj) && |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2520 | (x + width) * cpp > fb->pitches[i]) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 2521 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
| 2522 | i, fb->offsets[i]); |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2523 | return -EINVAL; |
| 2524 | } |
| 2525 | |
| 2526 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2527 | * First pixel of the framebuffer from |
| 2528 | * the start of the normal gtt mapping. |
| 2529 | */ |
| 2530 | intel_fb->normal[i].x = x; |
| 2531 | intel_fb->normal[i].y = y; |
| 2532 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2533 | offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i, |
| 2534 | fb->pitches[i], |
| 2535 | DRM_MODE_ROTATE_0, |
| 2536 | tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2537 | offset /= tile_size; |
| 2538 | |
Dhinakaran Pandiyan | 2a11b1b | 2018-10-26 12:38:04 -0700 | [diff] [blame] | 2539 | if (!is_surface_linear(fb->modifier, i)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2540 | unsigned int tile_width, tile_height; |
| 2541 | unsigned int pitch_tiles; |
| 2542 | struct drm_rect r; |
| 2543 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 2544 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2545 | |
| 2546 | rot_info->plane[i].offset = offset; |
| 2547 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2548 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2549 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2550 | |
| 2551 | intel_fb->rotated[i].pitch = |
| 2552 | rot_info->plane[i].height * tile_height; |
| 2553 | |
| 2554 | /* how many tiles does this plane need */ |
| 2555 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2556 | /* |
| 2557 | * If the plane isn't horizontally tile aligned, |
| 2558 | * we need one more tile. |
| 2559 | */ |
| 2560 | if (x != 0) |
| 2561 | size++; |
| 2562 | |
| 2563 | /* rotate the x/y offsets to match the GTT view */ |
| 2564 | r.x1 = x; |
| 2565 | r.y1 = y; |
| 2566 | r.x2 = x + width; |
| 2567 | r.y2 = y + height; |
| 2568 | drm_rect_rotate(&r, |
| 2569 | rot_info->plane[i].width * tile_width, |
| 2570 | rot_info->plane[i].height * tile_height, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 2571 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2572 | x = r.x1; |
| 2573 | y = r.y1; |
| 2574 | |
| 2575 | /* rotate the tile dimensions to match the GTT view */ |
| 2576 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2577 | swap(tile_width, tile_height); |
| 2578 | |
| 2579 | /* |
| 2580 | * We only keep the x/y offsets, so push all of the |
| 2581 | * gtt offset into the x/y offsets. |
| 2582 | */ |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2583 | intel_adjust_tile_offset(&x, &y, |
| 2584 | tile_width, tile_height, |
| 2585 | tile_size, pitch_tiles, |
| 2586 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2587 | |
| 2588 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2589 | |
| 2590 | /* |
| 2591 | * First pixel of the framebuffer from |
| 2592 | * the start of the rotated gtt mapping. |
| 2593 | */ |
| 2594 | intel_fb->rotated[i].x = x; |
| 2595 | intel_fb->rotated[i].y = y; |
| 2596 | } else { |
| 2597 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2598 | x * cpp, tile_size); |
| 2599 | } |
| 2600 | |
| 2601 | /* how many tiles in total needed in the bo */ |
| 2602 | max_size = max(max_size, offset + size); |
| 2603 | } |
| 2604 | |
Ville Syrjälä | 4e05047 | 2018-09-12 21:04:43 +0300 | [diff] [blame] | 2605 | if (mul_u32_u32(max_size, tile_size) > obj->base.size) { |
| 2606 | DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n", |
| 2607 | mul_u32_u32(max_size, tile_size), obj->base.size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2608 | return -EINVAL; |
| 2609 | } |
| 2610 | |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2614 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2615 | { |
| 2616 | switch (format) { |
| 2617 | case DISPPLANE_8BPP: |
| 2618 | return DRM_FORMAT_C8; |
| 2619 | case DISPPLANE_BGRX555: |
| 2620 | return DRM_FORMAT_XRGB1555; |
| 2621 | case DISPPLANE_BGRX565: |
| 2622 | return DRM_FORMAT_RGB565; |
| 2623 | default: |
| 2624 | case DISPPLANE_BGRX888: |
| 2625 | return DRM_FORMAT_XRGB8888; |
| 2626 | case DISPPLANE_RGBX888: |
| 2627 | return DRM_FORMAT_XBGR8888; |
| 2628 | case DISPPLANE_BGRX101010: |
| 2629 | return DRM_FORMAT_XRGB2101010; |
| 2630 | case DISPPLANE_RGBX101010: |
| 2631 | return DRM_FORMAT_XBGR2101010; |
| 2632 | } |
| 2633 | } |
| 2634 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 2635 | int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2636 | { |
| 2637 | switch (format) { |
| 2638 | case PLANE_CTL_FORMAT_RGB_565: |
| 2639 | return DRM_FORMAT_RGB565; |
Mahesh Kumar | f34a291 | 2018-04-09 09:11:02 +0530 | [diff] [blame] | 2640 | case PLANE_CTL_FORMAT_NV12: |
| 2641 | return DRM_FORMAT_NV12; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2642 | default: |
| 2643 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2644 | if (rgb_order) { |
| 2645 | if (alpha) |
| 2646 | return DRM_FORMAT_ABGR8888; |
| 2647 | else |
| 2648 | return DRM_FORMAT_XBGR8888; |
| 2649 | } else { |
| 2650 | if (alpha) |
| 2651 | return DRM_FORMAT_ARGB8888; |
| 2652 | else |
| 2653 | return DRM_FORMAT_XRGB8888; |
| 2654 | } |
| 2655 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2656 | if (rgb_order) |
| 2657 | return DRM_FORMAT_XBGR2101010; |
| 2658 | else |
| 2659 | return DRM_FORMAT_XRGB2101010; |
| 2660 | } |
| 2661 | } |
| 2662 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2663 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2664 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2665 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2666 | { |
| 2667 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2668 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2669 | struct drm_i915_gem_object *obj = NULL; |
| 2670 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2671 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2672 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2673 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2674 | PAGE_SIZE); |
| 2675 | |
| 2676 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2677 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2678 | if (plane_config->size == 0) |
| 2679 | return false; |
| 2680 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2681 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2682 | * important and we should probably use that space with FBC or other |
| 2683 | * features. */ |
Matthew Auld | b1ace60 | 2017-12-11 15:18:21 +0000 | [diff] [blame] | 2684 | if (size_aligned * 2 > dev_priv->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2685 | return false; |
| 2686 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2687 | switch (fb->modifier) { |
| 2688 | case DRM_FORMAT_MOD_LINEAR: |
| 2689 | case I915_FORMAT_MOD_X_TILED: |
| 2690 | case I915_FORMAT_MOD_Y_TILED: |
| 2691 | break; |
| 2692 | default: |
| 2693 | DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n", |
| 2694 | fb->modifier); |
| 2695 | return false; |
| 2696 | } |
| 2697 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2698 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2699 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2700 | base_aligned, |
| 2701 | base_aligned, |
| 2702 | size_aligned); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2703 | mutex_unlock(&dev->struct_mutex); |
| 2704 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2705 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2706 | |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 2707 | switch (plane_config->tiling) { |
| 2708 | case I915_TILING_NONE: |
| 2709 | break; |
| 2710 | case I915_TILING_X: |
| 2711 | case I915_TILING_Y: |
| 2712 | obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling; |
| 2713 | break; |
| 2714 | default: |
| 2715 | MISSING_CASE(plane_config->tiling); |
| 2716 | return false; |
| 2717 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2718 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 2719 | mode_cmd.pixel_format = fb->format->format; |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2720 | mode_cmd.width = fb->width; |
| 2721 | mode_cmd.height = fb->height; |
| 2722 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2723 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2724 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2725 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 2726 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2727 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2728 | goto out_unref_obj; |
| 2729 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2730 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2731 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2732 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2733 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2734 | |
| 2735 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2736 | i915_gem_object_put(obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2737 | return false; |
| 2738 | } |
| 2739 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2740 | static void |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2741 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, |
| 2742 | struct intel_plane_state *plane_state, |
| 2743 | bool visible) |
| 2744 | { |
| 2745 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 2746 | |
| 2747 | plane_state->base.visible = visible; |
| 2748 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2749 | if (visible) |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2750 | crtc_state->base.plane_mask |= drm_plane_mask(&plane->base); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2751 | else |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 2752 | crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2753 | } |
| 2754 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2755 | static void fixup_active_planes(struct intel_crtc_state *crtc_state) |
| 2756 | { |
| 2757 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 2758 | struct drm_plane *plane; |
| 2759 | |
| 2760 | /* |
| 2761 | * Active_planes aliases if multiple "primary" or cursor planes |
| 2762 | * have been used on the same (or wrong) pipe. plane_mask uses |
| 2763 | * unique ids, hence we can use that to reconstruct active_planes. |
| 2764 | */ |
| 2765 | crtc_state->active_planes = 0; |
| 2766 | |
| 2767 | drm_for_each_plane_mask(plane, &dev_priv->drm, |
| 2768 | crtc_state->base.plane_mask) |
| 2769 | crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); |
| 2770 | } |
| 2771 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2772 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
| 2773 | struct intel_plane *plane) |
| 2774 | { |
| 2775 | struct intel_crtc_state *crtc_state = |
| 2776 | to_intel_crtc_state(crtc->base.state); |
| 2777 | struct intel_plane_state *plane_state = |
| 2778 | to_intel_plane_state(plane->base.state); |
| 2779 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 2780 | DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", |
| 2781 | plane->base.base.id, plane->base.name, |
| 2782 | crtc->base.base.id, crtc->base.name); |
| 2783 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2784 | intel_set_plane_visible(crtc_state, plane_state, false); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 2785 | fixup_active_planes(crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2786 | |
| 2787 | if (plane->id == PLANE_PRIMARY) |
| 2788 | intel_pre_disable_primary_noatomic(&crtc->base); |
| 2789 | |
| 2790 | trace_intel_disable_plane(&plane->base, crtc); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 2791 | plane->disable_plane(plane, crtc_state); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2792 | } |
| 2793 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2794 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2795 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2796 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2797 | { |
| 2798 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2799 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2800 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2801 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2802 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2803 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2804 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2805 | struct intel_plane_state *intel_state = |
| 2806 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2807 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2808 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2809 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2810 | return; |
| 2811 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2812 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2813 | fb = &plane_config->fb->base; |
| 2814 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2815 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2816 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2817 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2818 | |
| 2819 | /* |
| 2820 | * Failed to alloc the obj, check to see if we should share |
| 2821 | * an fb with another CRTC instead |
| 2822 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2823 | for_each_crtc(dev, c) { |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2824 | struct intel_plane_state *state; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2825 | |
| 2826 | if (c == &intel_crtc->base) |
| 2827 | continue; |
| 2828 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2829 | if (!to_intel_crtc(c)->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2830 | continue; |
| 2831 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2832 | state = to_intel_plane_state(c->primary->state); |
| 2833 | if (!state->vma) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2834 | continue; |
| 2835 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2836 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
Ville Syrjälä | 8bc20f6 | 2018-03-22 17:22:59 +0200 | [diff] [blame] | 2837 | fb = state->base.fb; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2838 | drm_framebuffer_get(fb); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2839 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2840 | } |
| 2841 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2842 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2843 | /* |
| 2844 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2845 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2846 | * which will lead to problems later if we don't fix it up. The |
| 2847 | * simplest solution is to just disable the primary plane now and |
| 2848 | * pretend the BIOS never had it enabled. |
| 2849 | */ |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 2850 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2851 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2852 | return; |
| 2853 | |
| 2854 | valid_fb: |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 2855 | intel_state->base.rotation = plane_config->rotation; |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2856 | intel_fill_fb_ggtt_view(&intel_state->view, fb, |
| 2857 | intel_state->base.rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 2858 | intel_state->color_plane[0].stride = |
| 2859 | intel_fb_pitch(fb, 0, intel_state->base.rotation); |
| 2860 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2861 | mutex_lock(&dev->struct_mutex); |
| 2862 | intel_state->vma = |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2863 | intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 2864 | &intel_state->view, |
Ville Syrjälä | f7a02ad | 2018-02-21 20:48:07 +0200 | [diff] [blame] | 2865 | intel_plane_uses_fence(intel_state), |
Chris Wilson | 5935485 | 2018-02-20 13:42:06 +0000 | [diff] [blame] | 2866 | &intel_state->flags); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2867 | mutex_unlock(&dev->struct_mutex); |
| 2868 | if (IS_ERR(intel_state->vma)) { |
| 2869 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", |
| 2870 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); |
| 2871 | |
| 2872 | intel_state->vma = NULL; |
Harsha Sharma | c3ed110 | 2017-10-09 17:36:43 +0530 | [diff] [blame] | 2873 | drm_framebuffer_put(fb); |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 2874 | return; |
| 2875 | } |
| 2876 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 2877 | obj = intel_fb_obj(fb); |
| 2878 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 2879 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2880 | plane_state->src_x = 0; |
| 2881 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2882 | plane_state->src_w = fb->width << 16; |
| 2883 | plane_state->src_h = fb->height << 16; |
| 2884 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2885 | plane_state->crtc_x = 0; |
| 2886 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2887 | plane_state->crtc_w = fb->width; |
| 2888 | plane_state->crtc_h = fb->height; |
| 2889 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2890 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2891 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2892 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2893 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2894 | dev_priv->preserve_bios_swizzle = true; |
| 2895 | |
Ville Syrjälä | cd30fbc | 2018-05-25 21:50:40 +0300 | [diff] [blame] | 2896 | plane_state->fb = fb; |
| 2897 | plane_state->crtc = &intel_crtc->base; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 2898 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2899 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2900 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2901 | } |
| 2902 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2903 | static int skl_max_plane_width(const struct drm_framebuffer *fb, |
| 2904 | int color_plane, |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2905 | unsigned int rotation) |
| 2906 | { |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 2907 | int cpp = fb->format->cpp[color_plane]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2908 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2909 | switch (fb->modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 2910 | case DRM_FORMAT_MOD_LINEAR: |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2911 | case I915_FORMAT_MOD_X_TILED: |
| 2912 | switch (cpp) { |
| 2913 | case 8: |
| 2914 | return 4096; |
| 2915 | case 4: |
| 2916 | case 2: |
| 2917 | case 1: |
| 2918 | return 8192; |
| 2919 | default: |
| 2920 | MISSING_CASE(cpp); |
| 2921 | break; |
| 2922 | } |
| 2923 | break; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2924 | case I915_FORMAT_MOD_Y_TILED_CCS: |
| 2925 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
| 2926 | /* FIXME AUX plane? */ |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2927 | case I915_FORMAT_MOD_Y_TILED: |
| 2928 | case I915_FORMAT_MOD_Yf_TILED: |
| 2929 | switch (cpp) { |
| 2930 | case 8: |
| 2931 | return 2048; |
| 2932 | case 4: |
| 2933 | return 4096; |
| 2934 | case 2: |
| 2935 | case 1: |
| 2936 | return 8192; |
| 2937 | default: |
| 2938 | MISSING_CASE(cpp); |
| 2939 | break; |
| 2940 | } |
| 2941 | break; |
| 2942 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2943 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | return 2048; |
| 2947 | } |
| 2948 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2949 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
| 2950 | int main_x, int main_y, u32 main_offset) |
| 2951 | { |
| 2952 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2953 | int hsub = fb->format->hsub; |
| 2954 | int vsub = fb->format->vsub; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2955 | int aux_x = plane_state->color_plane[1].x; |
| 2956 | int aux_y = plane_state->color_plane[1].y; |
| 2957 | u32 aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2958 | u32 alignment = intel_surf_alignment(fb, 1); |
| 2959 | |
| 2960 | while (aux_offset >= main_offset && aux_y <= main_y) { |
| 2961 | int x, y; |
| 2962 | |
| 2963 | if (aux_x == main_x && aux_y == main_y) |
| 2964 | break; |
| 2965 | |
| 2966 | if (aux_offset == 0) |
| 2967 | break; |
| 2968 | |
| 2969 | x = aux_x / hsub; |
| 2970 | y = aux_y / vsub; |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 2971 | aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1, |
| 2972 | aux_offset, aux_offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2973 | aux_x = x * hsub + aux_x % hsub; |
| 2974 | aux_y = y * vsub + aux_y % vsub; |
| 2975 | } |
| 2976 | |
| 2977 | if (aux_x != main_x || aux_y != main_y) |
| 2978 | return false; |
| 2979 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2980 | plane_state->color_plane[1].offset = aux_offset; |
| 2981 | plane_state->color_plane[1].x = aux_x; |
| 2982 | plane_state->color_plane[1].y = aux_y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 2983 | |
| 2984 | return true; |
| 2985 | } |
| 2986 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 2987 | 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] | 2988 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2989 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2990 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2991 | int x = plane_state->base.src.x1 >> 16; |
| 2992 | int y = plane_state->base.src.y1 >> 16; |
| 2993 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 2994 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2995 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 2996 | int max_height = 4096; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 2997 | u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2998 | |
| 2999 | if (w > max_width || h > max_height) { |
| 3000 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 3001 | w, h, max_width, max_height); |
| 3002 | return -EINVAL; |
| 3003 | } |
| 3004 | |
| 3005 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3006 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3007 | alignment = intel_surf_alignment(fb, 0); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3008 | |
| 3009 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3010 | * AUX surface offset is specified as the distance from the |
| 3011 | * main surface offset, and it must be non-negative. Make |
| 3012 | * sure that is what we will get. |
| 3013 | */ |
| 3014 | if (offset > aux_offset) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3015 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3016 | offset, aux_offset & ~(alignment - 1)); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3017 | |
| 3018 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3019 | * When using an X-tiled surface, the plane blows up |
| 3020 | * if the x offset + width exceed the stride. |
| 3021 | * |
| 3022 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 3023 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3024 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 3025 | int cpp = fb->format->cpp[0]; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3026 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3027 | while ((x + w) * cpp > plane_state->color_plane[0].stride) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3028 | if (offset == 0) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3029 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n"); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3030 | return -EINVAL; |
| 3031 | } |
| 3032 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3033 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3034 | offset, offset - alignment); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3038 | /* |
| 3039 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure |
| 3040 | * they match with the main surface x/y offsets. |
| 3041 | */ |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3042 | if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3043 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { |
| 3044 | if (offset == 0) |
| 3045 | break; |
| 3046 | |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3047 | offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, |
| 3048 | offset, offset - alignment); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3051 | 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] | 3052 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); |
| 3053 | return -EINVAL; |
| 3054 | } |
| 3055 | } |
| 3056 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3057 | plane_state->color_plane[0].offset = offset; |
| 3058 | plane_state->color_plane[0].x = x; |
| 3059 | plane_state->color_plane[0].y = y; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3060 | |
| 3061 | return 0; |
| 3062 | } |
| 3063 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3064 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 3065 | { |
| 3066 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3067 | unsigned int rotation = plane_state->base.rotation; |
| 3068 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 3069 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3070 | int x = plane_state->base.src.x1 >> 17; |
| 3071 | int y = plane_state->base.src.y1 >> 17; |
| 3072 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 3073 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3074 | u32 offset; |
| 3075 | |
| 3076 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3077 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3078 | |
| 3079 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 3080 | if (w > max_width || h > max_height) { |
| 3081 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 3082 | w, h, max_width, max_height); |
| 3083 | return -EINVAL; |
| 3084 | } |
| 3085 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3086 | plane_state->color_plane[1].offset = offset; |
| 3087 | plane_state->color_plane[1].x = x; |
| 3088 | plane_state->color_plane[1].y = y; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3089 | |
| 3090 | return 0; |
| 3091 | } |
| 3092 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3093 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
| 3094 | { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3095 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3096 | int src_x = plane_state->base.src.x1 >> 16; |
| 3097 | int src_y = plane_state->base.src.y1 >> 16; |
| 3098 | int hsub = fb->format->hsub; |
| 3099 | int vsub = fb->format->vsub; |
| 3100 | int x = src_x / hsub; |
| 3101 | int y = src_y / vsub; |
| 3102 | u32 offset; |
| 3103 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3104 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3105 | offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3106 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3107 | plane_state->color_plane[1].offset = offset; |
| 3108 | plane_state->color_plane[1].x = x * hsub + src_x % hsub; |
| 3109 | plane_state->color_plane[1].y = y * vsub + src_y % vsub; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3110 | |
| 3111 | return 0; |
| 3112 | } |
| 3113 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3114 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3115 | { |
| 3116 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3117 | unsigned int rotation = plane_state->base.rotation; |
| 3118 | int ret; |
| 3119 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3120 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3121 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3122 | plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation); |
| 3123 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3124 | ret = intel_plane_check_stride(plane_state); |
| 3125 | if (ret) |
| 3126 | return ret; |
| 3127 | |
Ville Syrjälä | a5e4c7d | 2016-11-07 22:20:54 +0200 | [diff] [blame] | 3128 | if (!plane_state->base.visible) |
| 3129 | return 0; |
| 3130 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3131 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3132 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 3133 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 3134 | fb->width << 16, fb->height << 16, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3135 | DRM_MODE_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3136 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3137 | /* |
| 3138 | * Handle the AUX surface first since |
| 3139 | * the main surface setup depends on it. |
| 3140 | */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3141 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3142 | ret = skl_check_nv12_aux_surface(plane_state); |
| 3143 | if (ret) |
| 3144 | return ret; |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 3145 | } else if (is_ccs_modifier(fb->modifier)) { |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3146 | ret = skl_check_ccs_aux_surface(plane_state); |
| 3147 | if (ret) |
| 3148 | return ret; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3149 | } else { |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3150 | plane_state->color_plane[1].offset = ~0xfff; |
| 3151 | plane_state->color_plane[1].x = 0; |
| 3152 | plane_state->color_plane[1].y = 0; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 3153 | } |
| 3154 | |
Ville Syrjälä | 7326659 | 2018-09-07 18:24:11 +0300 | [diff] [blame] | 3155 | ret = skl_check_main_surface(plane_state); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3156 | if (ret) |
| 3157 | return ret; |
| 3158 | |
| 3159 | return 0; |
| 3160 | } |
| 3161 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 3162 | unsigned int |
| 3163 | i9xx_plane_max_stride(struct intel_plane *plane, |
| 3164 | u32 pixel_format, u64 modifier, |
| 3165 | unsigned int rotation) |
| 3166 | { |
| 3167 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3168 | |
| 3169 | if (!HAS_GMCH_DISPLAY(dev_priv)) { |
| 3170 | return 32*1024; |
| 3171 | } else if (INTEL_GEN(dev_priv) >= 4) { |
| 3172 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3173 | return 16*1024; |
| 3174 | else |
| 3175 | return 32*1024; |
| 3176 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 3177 | if (modifier == I915_FORMAT_MOD_X_TILED) |
| 3178 | return 8*1024; |
| 3179 | else |
| 3180 | return 16*1024; |
| 3181 | } else { |
| 3182 | if (plane->i9xx_plane == PLANE_C) |
| 3183 | return 4*1024; |
| 3184 | else |
| 3185 | return 8*1024; |
| 3186 | } |
| 3187 | } |
| 3188 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3189 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3190 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3191 | { |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3192 | struct drm_i915_private *dev_priv = |
| 3193 | to_i915(plane_state->base.plane->dev); |
| 3194 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3195 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3196 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3197 | u32 dspcntr; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3198 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3199 | dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3200 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 3201 | if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) || |
| 3202 | IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3203 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3204 | |
Ville Syrjälä | 6a4407a | 2017-03-23 21:27:08 +0200 | [diff] [blame] | 3205 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 3206 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3207 | |
Ville Syrjälä | c154d1e | 2018-01-30 22:38:02 +0200 | [diff] [blame] | 3208 | if (INTEL_GEN(dev_priv) < 5) |
Ville Syrjälä | d509e28 | 2017-03-27 21:55:32 +0300 | [diff] [blame] | 3209 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3210 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3211 | switch (fb->format->format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3212 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3213 | dspcntr |= DISPPLANE_8BPP; |
| 3214 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3215 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3216 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3217 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3218 | case DRM_FORMAT_RGB565: |
| 3219 | dspcntr |= DISPPLANE_BGRX565; |
| 3220 | break; |
| 3221 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3222 | dspcntr |= DISPPLANE_BGRX888; |
| 3223 | break; |
| 3224 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3225 | dspcntr |= DISPPLANE_RGBX888; |
| 3226 | break; |
| 3227 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3228 | dspcntr |= DISPPLANE_BGRX101010; |
| 3229 | break; |
| 3230 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3231 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3232 | break; |
| 3233 | default: |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3234 | MISSING_CASE(fb->format->format); |
| 3235 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3236 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3237 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3238 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3239 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3240 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3241 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3242 | if (rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3243 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3244 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3245 | if (rotation & DRM_MODE_REFLECT_X) |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3246 | dspcntr |= DISPPLANE_MIRROR; |
| 3247 | |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3248 | return dspcntr; |
| 3249 | } |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3250 | |
Ville Syrjälä | f9407ae | 2017-03-23 21:27:12 +0200 | [diff] [blame] | 3251 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3252 | { |
| 3253 | struct drm_i915_private *dev_priv = |
| 3254 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3255 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3256 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3257 | int src_x = plane_state->base.src.x1 >> 16; |
| 3258 | int src_y = plane_state->base.src.y1 >> 16; |
| 3259 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3260 | int ret; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3261 | |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 3262 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3263 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 3264 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 3265 | ret = intel_plane_check_stride(plane_state); |
| 3266 | if (ret) |
| 3267 | return ret; |
| 3268 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3269 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3270 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3271 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 6d19a44 | 2018-09-07 18:24:01 +0300 | [diff] [blame] | 3272 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 3273 | plane_state, 0); |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3274 | else |
| 3275 | offset = 0; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3276 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3277 | /* HSW/BDW do this automagically in hardware */ |
| 3278 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3279 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3280 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3281 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3282 | if (rotation & DRM_MODE_ROTATE_180) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3283 | src_x += src_w - 1; |
| 3284 | src_y += src_h - 1; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3285 | } else if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3286 | src_x += src_w - 1; |
| 3287 | } |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3288 | } |
| 3289 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3290 | plane_state->color_plane[0].offset = offset; |
| 3291 | plane_state->color_plane[0].x = src_x; |
| 3292 | plane_state->color_plane[0].y = src_y; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3293 | |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3297 | static int |
| 3298 | i9xx_plane_check(struct intel_crtc_state *crtc_state, |
| 3299 | struct intel_plane_state *plane_state) |
| 3300 | { |
| 3301 | int ret; |
| 3302 | |
Ville Syrjälä | 25721f8 | 2018-09-07 18:24:12 +0300 | [diff] [blame] | 3303 | ret = chv_plane_check_rotation(plane_state); |
| 3304 | if (ret) |
| 3305 | return ret; |
| 3306 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 3307 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 3308 | &crtc_state->base, |
| 3309 | DRM_PLANE_HELPER_NO_SCALING, |
| 3310 | DRM_PLANE_HELPER_NO_SCALING, |
| 3311 | false, true); |
| 3312 | if (ret) |
| 3313 | return ret; |
| 3314 | |
| 3315 | if (!plane_state->base.visible) |
| 3316 | return 0; |
| 3317 | |
| 3318 | ret = intel_plane_check_src_coordinates(plane_state); |
| 3319 | if (ret) |
| 3320 | return ret; |
| 3321 | |
| 3322 | ret = i9xx_check_plane_surface(plane_state); |
| 3323 | if (ret) |
| 3324 | return ret; |
| 3325 | |
| 3326 | plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state); |
| 3327 | |
| 3328 | return 0; |
| 3329 | } |
| 3330 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3331 | static void i9xx_update_plane(struct intel_plane *plane, |
| 3332 | const struct intel_crtc_state *crtc_state, |
| 3333 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3334 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3335 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3336 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3337 | u32 linear_offset; |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 3338 | u32 dspcntr = plane_state->ctl; |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3339 | int x = plane_state->color_plane[0].x; |
| 3340 | int y = plane_state->color_plane[0].y; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3341 | unsigned long irqflags; |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3342 | u32 dspaddr_offset; |
Ville Syrjälä | 7145f60 | 2017-03-23 21:27:07 +0200 | [diff] [blame] | 3343 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3344 | 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] | 3345 | |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3346 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 3347 | dspaddr_offset = plane_state->color_plane[0].offset; |
Ville Syrjälä | 5b7fcc4 | 2017-03-23 21:27:10 +0200 | [diff] [blame] | 3348 | else |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3349 | dspaddr_offset = linear_offset; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3350 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3351 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3352 | |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3353 | I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride); |
| 3354 | |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3355 | if (INTEL_GEN(dev_priv) < 4) { |
| 3356 | /* pipesrc and dspsize control the size that is scaled from, |
| 3357 | * which should always be the user's requested size. |
| 3358 | */ |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3359 | I915_WRITE_FW(DSPPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3360 | I915_WRITE_FW(DSPSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3361 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3362 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3363 | } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3364 | I915_WRITE_FW(PRIMPOS(i9xx_plane), 0); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3365 | I915_WRITE_FW(PRIMSIZE(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3366 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3367 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3368 | I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0); |
Ville Syrjälä | 78587de | 2017-03-09 17:44:32 +0200 | [diff] [blame] | 3369 | } |
| 3370 | |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3371 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3372 | I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x); |
Ville Syrjälä | 3ba35e5 | 2017-03-23 21:27:11 +0200 | [diff] [blame] | 3373 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3374 | I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset); |
| 3375 | I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x); |
| 3376 | } |
| 3377 | |
| 3378 | /* |
| 3379 | * The control register self-arms if the plane was previously |
| 3380 | * disabled. Try to make the plane enable atomic by writing |
| 3381 | * the control register just before the surface register. |
| 3382 | */ |
| 3383 | I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr); |
| 3384 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3385 | I915_WRITE_FW(DSPSURF(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3386 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3387 | dspaddr_offset); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 3388 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3389 | I915_WRITE_FW(DSPADDR(i9xx_plane), |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3390 | intel_plane_ggtt_offset(plane_state) + |
Juha-Pekka Heikkila | e288881 | 2017-10-17 23:08:08 +0300 | [diff] [blame] | 3391 | dspaddr_offset); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3392 | |
| 3393 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3396 | static void i9xx_disable_plane(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 3397 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3398 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3399 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 3400 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3401 | unsigned long irqflags; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3402 | |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3403 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 3404 | |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3405 | I915_WRITE_FW(DSPCNTR(i9xx_plane), 0); |
| 3406 | if (INTEL_GEN(dev_priv) >= 4) |
| 3407 | I915_WRITE_FW(DSPSURF(i9xx_plane), 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3408 | else |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3409 | I915_WRITE_FW(DSPADDR(i9xx_plane), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 3410 | |
| 3411 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3412 | } |
| 3413 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3414 | static bool i9xx_plane_get_hw_state(struct intel_plane *plane, |
| 3415 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3416 | { |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3417 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3418 | enum intel_display_power_domain power_domain; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 3419 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3420 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3421 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3422 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3423 | |
| 3424 | /* |
| 3425 | * Not 100% correct for planes that can move between pipes, |
| 3426 | * but that's only the case for gen2-4 which don't have any |
| 3427 | * display power wells. |
| 3428 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3429 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3430 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 3431 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3432 | return false; |
| 3433 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 3434 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 3435 | |
| 3436 | ret = val & DISPLAY_PLANE_ENABLE; |
| 3437 | |
| 3438 | if (INTEL_GEN(dev_priv) >= 5) |
| 3439 | *pipe = plane->pipe; |
| 3440 | else |
| 3441 | *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 3442 | DISPPLANE_SEL_PIPE_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3443 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 3444 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 3445 | |
| 3446 | return ret; |
| 3447 | } |
| 3448 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3449 | static u32 |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3450 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3451 | { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3452 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3453 | return 64; |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 3454 | else |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3455 | return intel_tile_width_bytes(fb, color_plane); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3458 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3459 | { |
| 3460 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3461 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3462 | |
| 3463 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3464 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3465 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3466 | } |
| 3467 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3468 | /* |
| 3469 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3470 | */ |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3471 | static void skl_detach_scalers(const struct intel_crtc_state *crtc_state) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3472 | { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3473 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3474 | const struct intel_crtc_scaler_state *scaler_state = |
| 3475 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3476 | int i; |
| 3477 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3478 | /* loop through and disable scalers that aren't in use */ |
| 3479 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3480 | if (!scaler_state->scalers[i].in_use) |
| 3481 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3482 | } |
| 3483 | } |
| 3484 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3485 | static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb, |
| 3486 | int color_plane, unsigned int rotation) |
| 3487 | { |
| 3488 | /* |
| 3489 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3490 | * linear buffers or in number of tiles for tiled buffers. |
| 3491 | */ |
| 3492 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
| 3493 | return 64; |
| 3494 | else if (drm_rotation_90_or_270(rotation)) |
| 3495 | return intel_tile_height(fb, color_plane); |
| 3496 | else |
| 3497 | return intel_tile_width_bytes(fb, color_plane); |
| 3498 | } |
| 3499 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3500 | u32 skl_plane_stride(const struct intel_plane_state *plane_state, |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3501 | int color_plane) |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3502 | { |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 3503 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 3504 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3505 | u32 stride = plane_state->color_plane[color_plane].stride; |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3506 | |
Ville Syrjälä | 5d2a195 | 2018-09-07 18:24:07 +0300 | [diff] [blame] | 3507 | if (color_plane >= fb->format->num_planes) |
Ville Syrjälä | 1b50053 | 2017-03-07 21:42:08 +0200 | [diff] [blame] | 3508 | return 0; |
| 3509 | |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 3510 | return stride / skl_plane_stride_mult(fb, color_plane, rotation); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3511 | } |
| 3512 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 3513 | static u32 skl_plane_ctl_format(u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3514 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3515 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3516 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3517 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3518 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3519 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3520 | case DRM_FORMAT_XBGR8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3521 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3522 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3523 | case DRM_FORMAT_XRGB8888: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3524 | case DRM_FORMAT_ARGB8888: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3525 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3526 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3527 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3528 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3529 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3530 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3531 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3532 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3533 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3534 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3535 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3536 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3537 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 3538 | case DRM_FORMAT_NV12: |
| 3539 | return PLANE_CTL_FORMAT_NV12; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3540 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3541 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3542 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3543 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3544 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3547 | 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] | 3548 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3549 | if (!plane_state->base.fb->format->has_alpha) |
| 3550 | return PLANE_CTL_ALPHA_DISABLE; |
| 3551 | |
| 3552 | switch (plane_state->base.pixel_blend_mode) { |
| 3553 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3554 | return PLANE_CTL_ALPHA_DISABLE; |
| 3555 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3556 | return PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3557 | case DRM_MODE_BLEND_COVERAGE: |
| 3558 | return PLANE_CTL_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3559 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3560 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3561 | return PLANE_CTL_ALPHA_DISABLE; |
| 3562 | } |
| 3563 | } |
| 3564 | |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3565 | 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] | 3566 | { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3567 | if (!plane_state->base.fb->format->has_alpha) |
| 3568 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3569 | |
| 3570 | switch (plane_state->base.pixel_blend_mode) { |
| 3571 | case DRM_MODE_BLEND_PIXEL_NONE: |
| 3572 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3573 | case DRM_MODE_BLEND_PREMULTI: |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3574 | return PLANE_COLOR_ALPHA_SW_PREMULTIPLY; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3575 | case DRM_MODE_BLEND_COVERAGE: |
| 3576 | return PLANE_COLOR_ALPHA_HW_PREMULTIPLY; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3577 | default: |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3578 | MISSING_CASE(plane_state->base.pixel_blend_mode); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3579 | return PLANE_COLOR_ALPHA_DISABLE; |
| 3580 | } |
| 3581 | } |
| 3582 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 3583 | static u32 skl_plane_ctl_tiling(u64 fb_modifier) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3584 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3585 | switch (fb_modifier) { |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 3586 | case DRM_FORMAT_MOD_LINEAR: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3587 | break; |
| 3588 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3589 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3590 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3591 | return PLANE_CTL_TILED_Y; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3592 | case I915_FORMAT_MOD_Y_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3593 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3594 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3595 | return PLANE_CTL_TILED_YF; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 3596 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 3597 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3598 | default: |
| 3599 | MISSING_CASE(fb_modifier); |
| 3600 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3601 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3602 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3605 | static u32 skl_plane_ctl_rotate(unsigned int rotate) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3606 | { |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3607 | switch (rotate) { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3608 | case DRM_MODE_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3609 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3610 | /* |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3611 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3612 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3613 | */ |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3614 | case DRM_MODE_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3615 | return PLANE_CTL_ROTATE_270; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3616 | case DRM_MODE_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3617 | return PLANE_CTL_ROTATE_180; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 3618 | case DRM_MODE_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3619 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3620 | default: |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3621 | MISSING_CASE(rotate); |
| 3622 | } |
| 3623 | |
| 3624 | return 0; |
| 3625 | } |
| 3626 | |
| 3627 | static u32 cnl_plane_ctl_flip(unsigned int reflect) |
| 3628 | { |
| 3629 | switch (reflect) { |
| 3630 | case 0: |
| 3631 | break; |
| 3632 | case DRM_MODE_REFLECT_X: |
| 3633 | return PLANE_CTL_FLIP_HORIZONTAL; |
| 3634 | case DRM_MODE_REFLECT_Y: |
| 3635 | default: |
| 3636 | MISSING_CASE(reflect); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3639 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3642 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
| 3643 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3644 | { |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3645 | struct drm_i915_private *dev_priv = |
| 3646 | to_i915(plane_state->base.plane->dev); |
| 3647 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3648 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3649 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3650 | u32 plane_ctl; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3651 | |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3652 | plane_ctl = PLANE_CTL_ENABLE; |
| 3653 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3654 | if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3655 | plane_ctl |= skl_plane_ctl_alpha(plane_state); |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3656 | plane_ctl |= |
| 3657 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3658 | PLANE_CTL_PIPE_CSC_ENABLE | |
| 3659 | PLANE_CTL_PLANE_GAMMA_DISABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3660 | |
| 3661 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3662 | plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3663 | |
| 3664 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3665 | plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE; |
Ander Conselvan de Oliveira | 47f9ea8 | 2017-01-26 13:24:22 +0200 | [diff] [blame] | 3666 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3667 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 3668 | plane_ctl |= skl_plane_ctl_format(fb->format->format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3669 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Joonas Lahtinen | 5f8e3f5 | 2017-12-15 13:38:00 -0800 | [diff] [blame] | 3670 | plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK); |
| 3671 | |
| 3672 | if (INTEL_GEN(dev_priv) >= 10) |
| 3673 | plane_ctl |= cnl_plane_ctl_flip(rotation & |
| 3674 | DRM_MODE_REFLECT_MASK); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3675 | |
Ville Syrjälä | 2e88126 | 2017-03-17 23:17:56 +0200 | [diff] [blame] | 3676 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 3677 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 3678 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 3679 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 3680 | |
Ville Syrjälä | 46f788b | 2017-03-17 23:17:55 +0200 | [diff] [blame] | 3681 | return plane_ctl; |
| 3682 | } |
| 3683 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3684 | u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state, |
| 3685 | const struct intel_plane_state *plane_state) |
| 3686 | { |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3687 | struct drm_i915_private *dev_priv = |
| 3688 | to_i915(plane_state->base.plane->dev); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3689 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3690 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3691 | u32 plane_color_ctl = 0; |
| 3692 | |
James Ausmus | 077ef1f | 2018-03-28 14:57:56 -0700 | [diff] [blame] | 3693 | if (INTEL_GEN(dev_priv) < 11) { |
| 3694 | plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE; |
| 3695 | plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE; |
| 3696 | } |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3697 | plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE; |
Maarten Lankhorst | b208152 | 2018-08-15 12:34:05 +0200 | [diff] [blame] | 3698 | plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3699 | |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3700 | if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) { |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3701 | if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709) |
| 3702 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709; |
| 3703 | else |
| 3704 | plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709; |
Ville Syrjälä | c8624ed | 2018-02-14 21:23:27 +0200 | [diff] [blame] | 3705 | |
| 3706 | if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE) |
| 3707 | plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE; |
Uma Shankar | bfe60a0 | 2018-11-02 00:40:20 +0530 | [diff] [blame] | 3708 | } else if (fb->format->is_yuv) { |
| 3709 | plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE; |
Ville Syrjälä | b0f5c0b | 2018-02-14 21:23:25 +0200 | [diff] [blame] | 3710 | } |
Ville Syrjälä | 012d79e | 2018-05-21 21:56:12 +0300 | [diff] [blame] | 3711 | |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 3712 | return plane_color_ctl; |
| 3713 | } |
| 3714 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3715 | static int |
| 3716 | __intel_display_resume(struct drm_device *dev, |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3717 | struct drm_atomic_state *state, |
| 3718 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3719 | { |
| 3720 | struct drm_crtc_state *crtc_state; |
| 3721 | struct drm_crtc *crtc; |
| 3722 | int i, ret; |
| 3723 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 3724 | intel_modeset_setup_hw_state(dev, ctx); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3725 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3726 | |
| 3727 | if (!state) |
| 3728 | return 0; |
| 3729 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 3730 | /* |
| 3731 | * We've duplicated the state, pointers to the old state are invalid. |
| 3732 | * |
| 3733 | * Don't attempt to use the old state until we commit the duplicated state. |
| 3734 | */ |
| 3735 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3736 | /* |
| 3737 | * Force recalculation even if we restore |
| 3738 | * current state. With fast modeset this may not result |
| 3739 | * in a modeset when the state is compatible. |
| 3740 | */ |
| 3741 | crtc_state->mode_changed = true; |
| 3742 | } |
| 3743 | |
| 3744 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 3745 | if (!HAS_GMCH_DISPLAY(to_i915(dev))) |
| 3746 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3747 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3748 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3749 | |
| 3750 | WARN_ON(ret == -EDEADLK); |
| 3751 | return ret; |
| 3752 | } |
| 3753 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3754 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3755 | { |
Chris Wilson | 55277e1 | 2019-01-03 11:21:04 +0000 | [diff] [blame] | 3756 | return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display && |
| 3757 | intel_has_gpu_reset(dev_priv)); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3758 | } |
| 3759 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3760 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3761 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3762 | struct drm_device *dev = &dev_priv->drm; |
| 3763 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3764 | struct drm_atomic_state *state; |
| 3765 | int ret; |
| 3766 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3767 | /* reset doesn't touch the display */ |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 3768 | if (!i915_modparams.force_reset_modeset_test && |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3769 | !gpu_reset_clobbers_display(dev_priv)) |
| 3770 | return; |
| 3771 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3772 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
| 3773 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
| 3774 | wake_up_all(&dev_priv->gpu_error.wait_queue); |
| 3775 | |
| 3776 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { |
| 3777 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); |
| 3778 | i915_gem_set_wedged(dev_priv); |
| 3779 | } |
Daniel Vetter | 97154ec | 2017-08-08 10:08:26 +0200 | [diff] [blame] | 3780 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3781 | /* |
| 3782 | * Need mode_config.mutex so that we don't |
| 3783 | * trample ongoing ->detect() and whatnot. |
| 3784 | */ |
| 3785 | mutex_lock(&dev->mode_config.mutex); |
| 3786 | drm_modeset_acquire_init(ctx, 0); |
| 3787 | while (1) { |
| 3788 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3789 | if (ret != -EDEADLK) |
| 3790 | break; |
| 3791 | |
| 3792 | drm_modeset_backoff(ctx); |
| 3793 | } |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3794 | /* |
| 3795 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3796 | * g33 docs say we should at least disable all the planes. |
| 3797 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3798 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3799 | if (IS_ERR(state)) { |
| 3800 | ret = PTR_ERR(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3801 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3802 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3806 | if (ret) { |
| 3807 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Ander Conselvan de Oliveira | 1e5a15d | 2017-01-18 14:34:28 +0200 | [diff] [blame] | 3808 | drm_atomic_state_put(state); |
| 3809 | return; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | dev_priv->modeset_restore_state = state; |
| 3813 | state->acquire_ctx = ctx; |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3814 | } |
| 3815 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3816 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3817 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3818 | struct drm_device *dev = &dev_priv->drm; |
| 3819 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3820 | struct drm_atomic_state *state; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3821 | int ret; |
| 3822 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3823 | /* reset doesn't touch the display */ |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3824 | if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3825 | return; |
| 3826 | |
Chris Wilson | 40da1d3 | 2018-04-05 13:37:14 +0100 | [diff] [blame] | 3827 | state = fetch_and_zero(&dev_priv->modeset_restore_state); |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3828 | if (!state) |
| 3829 | goto unlock; |
| 3830 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3831 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3832 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3833 | /* for testing only restore the display */ |
| 3834 | ret = __intel_display_resume(dev, state, ctx); |
Chris Wilson | 942d5d0 | 2017-08-28 11:46:04 +0100 | [diff] [blame] | 3835 | if (ret) |
| 3836 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3837 | } else { |
| 3838 | /* |
| 3839 | * The display has been reset as well, |
| 3840 | * so need a full re-initialization. |
| 3841 | */ |
| 3842 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3843 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3844 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3845 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3846 | intel_modeset_init_hw(dev); |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 3847 | intel_init_clock_gating(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3848 | |
| 3849 | spin_lock_irq(&dev_priv->irq_lock); |
| 3850 | if (dev_priv->display.hpd_irq_setup) |
| 3851 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3852 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3853 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3854 | ret = __intel_display_resume(dev, state, ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3855 | if (ret) |
| 3856 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3857 | |
| 3858 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3859 | } |
| 3860 | |
Daniel Vetter | ce87ea1 | 2017-07-19 14:54:55 +0200 | [diff] [blame] | 3861 | drm_atomic_state_put(state); |
| 3862 | unlock: |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3863 | drm_modeset_drop_locks(ctx); |
| 3864 | drm_modeset_acquire_fini(ctx); |
| 3865 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 3866 | |
| 3867 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3868 | } |
| 3869 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3870 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
| 3871 | const struct intel_crtc_state *new_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3872 | { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3873 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3874 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3875 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3876 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3877 | crtc->base.mode = new_crtc_state->base.mode; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3878 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3879 | /* |
| 3880 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3881 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3882 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3883 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3884 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3885 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3886 | */ |
| 3887 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3888 | I915_WRITE(PIPESRC(crtc->pipe), |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3889 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
| 3890 | (new_crtc_state->pipe_src_h - 1)); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3891 | |
| 3892 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3893 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 3894 | skl_detach_scalers(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3895 | |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3896 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3897 | skylake_pfit_enable(new_crtc_state); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3898 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 3899 | if (new_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3900 | ironlake_pfit_enable(new_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3901 | else if (old_crtc_state->pch_pfit.enabled) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 3902 | ironlake_pfit_disable(old_crtc_state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3903 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3904 | } |
| 3905 | |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3906 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3907 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3908 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3909 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3910 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3911 | i915_reg_t reg; |
| 3912 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3913 | |
| 3914 | /* enable normal train */ |
| 3915 | reg = FDI_TX_CTL(pipe); |
| 3916 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3917 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3918 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3919 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3920 | } else { |
| 3921 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3922 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3923 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3924 | I915_WRITE(reg, temp); |
| 3925 | |
| 3926 | reg = FDI_RX_CTL(pipe); |
| 3927 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3928 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3929 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3930 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3931 | } else { |
| 3932 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3933 | temp |= FDI_LINK_TRAIN_NONE; |
| 3934 | } |
| 3935 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3936 | |
| 3937 | /* wait one idle pattern time */ |
| 3938 | POSTING_READ(reg); |
| 3939 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3940 | |
| 3941 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3942 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3943 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3944 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3945 | } |
| 3946 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3947 | /* The FDI link training functions for ILK/Ibexpeak. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3948 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
| 3949 | const struct intel_crtc_state *crtc_state) |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3950 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3951 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3952 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 3953 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3954 | i915_reg_t reg; |
| 3955 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3956 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3957 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3958 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3959 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3960 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3961 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3962 | reg = FDI_RX_IMR(pipe); |
| 3963 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3964 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3965 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3966 | I915_WRITE(reg, temp); |
| 3967 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3968 | udelay(150); |
| 3969 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3970 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3971 | reg = FDI_TX_CTL(pipe); |
| 3972 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3973 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 3974 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3975 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3976 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3977 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3978 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3979 | reg = FDI_RX_CTL(pipe); |
| 3980 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3981 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3982 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3983 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3984 | |
| 3985 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3986 | udelay(150); |
| 3987 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3988 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3989 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3990 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3991 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3992 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3993 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3994 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3995 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3996 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3997 | |
| 3998 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3999 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4000 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4001 | break; |
| 4002 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4003 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4004 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4005 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4006 | |
| 4007 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4008 | reg = FDI_TX_CTL(pipe); |
| 4009 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4010 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4011 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4012 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4013 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4014 | reg = FDI_RX_CTL(pipe); |
| 4015 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4016 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4017 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4018 | I915_WRITE(reg, temp); |
| 4019 | |
| 4020 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4021 | udelay(150); |
| 4022 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4023 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4024 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4025 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4026 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4027 | |
| 4028 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4029 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4030 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4031 | break; |
| 4032 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4033 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4034 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4035 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4036 | |
| 4037 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 4038 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4039 | } |
| 4040 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4041 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4042 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 4043 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 4044 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 4045 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 4046 | }; |
| 4047 | |
| 4048 | /* The FDI link training functions for SNB/Cougarpoint. */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4049 | static void gen6_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, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4057 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4058 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4059 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4060 | reg = FDI_RX_IMR(pipe); |
| 4061 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4062 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4063 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4064 | I915_WRITE(reg, temp); |
| 4065 | |
| 4066 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 4067 | udelay(150); |
| 4068 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4069 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4070 | reg = FDI_TX_CTL(pipe); |
| 4071 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4072 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4073 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4074 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4075 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4076 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4077 | /* SNB-B */ |
| 4078 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4079 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4080 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 4081 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4082 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4083 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4084 | reg = FDI_RX_CTL(pipe); |
| 4085 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4086 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4087 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4088 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4089 | } else { |
| 4090 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4091 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4092 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4093 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4094 | |
| 4095 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4096 | udelay(150); |
| 4097 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4098 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4099 | reg = FDI_TX_CTL(pipe); |
| 4100 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4101 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4102 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4103 | I915_WRITE(reg, temp); |
| 4104 | |
| 4105 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4106 | udelay(500); |
| 4107 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4108 | for (retry = 0; retry < 5; retry++) { |
| 4109 | reg = FDI_RX_IIR(pipe); |
| 4110 | temp = I915_READ(reg); |
| 4111 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4112 | if (temp & FDI_RX_BIT_LOCK) { |
| 4113 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4114 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 4115 | break; |
| 4116 | } |
| 4117 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4118 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4119 | if (retry < 5) |
| 4120 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4121 | } |
| 4122 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4123 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4124 | |
| 4125 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4126 | reg = FDI_TX_CTL(pipe); |
| 4127 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4128 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4129 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 4130 | if (IS_GEN(dev_priv, 6)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4131 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4132 | /* SNB-B */ |
| 4133 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 4134 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4135 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4136 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4137 | reg = FDI_RX_CTL(pipe); |
| 4138 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4139 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4140 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4141 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 4142 | } else { |
| 4143 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4144 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 4145 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4146 | I915_WRITE(reg, temp); |
| 4147 | |
| 4148 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4149 | udelay(150); |
| 4150 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 4151 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4152 | reg = FDI_TX_CTL(pipe); |
| 4153 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4154 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 4155 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4156 | I915_WRITE(reg, temp); |
| 4157 | |
| 4158 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4159 | udelay(500); |
| 4160 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4161 | for (retry = 0; retry < 5; retry++) { |
| 4162 | reg = FDI_RX_IIR(pipe); |
| 4163 | temp = I915_READ(reg); |
| 4164 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4165 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 4166 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4167 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 4168 | break; |
| 4169 | } |
| 4170 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4171 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 4172 | if (retry < 5) |
| 4173 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4174 | } |
| 4175 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4176 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 4177 | |
| 4178 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4179 | } |
| 4180 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4181 | /* Manual link training for Ivy Bridge A0 parts */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4182 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
| 4183 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4184 | { |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4185 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4186 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4187 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4188 | i915_reg_t reg; |
| 4189 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4190 | |
| 4191 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4192 | for train result */ |
| 4193 | reg = FDI_RX_IMR(pipe); |
| 4194 | temp = I915_READ(reg); |
| 4195 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4196 | temp &= ~FDI_RX_BIT_LOCK; |
| 4197 | I915_WRITE(reg, temp); |
| 4198 | |
| 4199 | POSTING_READ(reg); |
| 4200 | udelay(150); |
| 4201 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4202 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4203 | I915_READ(FDI_RX_IIR(pipe))); |
| 4204 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4205 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4206 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4207 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4208 | reg = FDI_TX_CTL(pipe); |
| 4209 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4210 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4211 | temp &= ~FDI_TX_ENABLE; |
| 4212 | I915_WRITE(reg, temp); |
| 4213 | |
| 4214 | reg = FDI_RX_CTL(pipe); |
| 4215 | temp = I915_READ(reg); |
| 4216 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4217 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4218 | temp &= ~FDI_RX_ENABLE; |
| 4219 | I915_WRITE(reg, temp); |
| 4220 | |
| 4221 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4222 | reg = FDI_TX_CTL(pipe); |
| 4223 | temp = I915_READ(reg); |
| 4224 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4225 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4226 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4227 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4228 | temp |= snb_b_fdi_train_param[j/2]; |
| 4229 | temp |= FDI_COMPOSITE_SYNC; |
| 4230 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4231 | |
| 4232 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4233 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4234 | |
| 4235 | reg = FDI_RX_CTL(pipe); |
| 4236 | temp = I915_READ(reg); |
| 4237 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4238 | temp |= FDI_COMPOSITE_SYNC; |
| 4239 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4240 | |
| 4241 | POSTING_READ(reg); |
| 4242 | udelay(1); /* should be 0.5us */ |
| 4243 | |
| 4244 | for (i = 0; i < 4; i++) { |
| 4245 | reg = FDI_RX_IIR(pipe); |
| 4246 | temp = I915_READ(reg); |
| 4247 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4248 | |
| 4249 | if (temp & FDI_RX_BIT_LOCK || |
| 4250 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4251 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4252 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4253 | i); |
| 4254 | break; |
| 4255 | } |
| 4256 | udelay(1); /* should be 0.5us */ |
| 4257 | } |
| 4258 | if (i == 4) { |
| 4259 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4260 | continue; |
| 4261 | } |
| 4262 | |
| 4263 | /* Train 2 */ |
| 4264 | reg = FDI_TX_CTL(pipe); |
| 4265 | temp = I915_READ(reg); |
| 4266 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4267 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4268 | I915_WRITE(reg, temp); |
| 4269 | |
| 4270 | reg = FDI_RX_CTL(pipe); |
| 4271 | temp = I915_READ(reg); |
| 4272 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4273 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4274 | I915_WRITE(reg, temp); |
| 4275 | |
| 4276 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4277 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4278 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4279 | for (i = 0; i < 4; i++) { |
| 4280 | reg = FDI_RX_IIR(pipe); |
| 4281 | temp = I915_READ(reg); |
| 4282 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4283 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4284 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4285 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4286 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4287 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4288 | i); |
| 4289 | goto train_done; |
| 4290 | } |
| 4291 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4292 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4293 | if (i == 4) |
| 4294 | 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] | 4295 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4296 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4297 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4298 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4299 | } |
| 4300 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4301 | 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] | 4302 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4303 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4304 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4305 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4306 | i915_reg_t reg; |
| 4307 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4308 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4309 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4310 | reg = FDI_RX_CTL(pipe); |
| 4311 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4312 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 4313 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4314 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4315 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4316 | |
| 4317 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4318 | udelay(200); |
| 4319 | |
| 4320 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4321 | temp = I915_READ(reg); |
| 4322 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4323 | |
| 4324 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4325 | udelay(200); |
| 4326 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4327 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4328 | reg = FDI_TX_CTL(pipe); |
| 4329 | temp = I915_READ(reg); |
| 4330 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4331 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4332 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4333 | POSTING_READ(reg); |
| 4334 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4335 | } |
| 4336 | } |
| 4337 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4338 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4339 | { |
| 4340 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4341 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4342 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4343 | i915_reg_t reg; |
| 4344 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4345 | |
| 4346 | /* Switch from PCDclk to Rawclk */ |
| 4347 | reg = FDI_RX_CTL(pipe); |
| 4348 | temp = I915_READ(reg); |
| 4349 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4350 | |
| 4351 | /* Disable CPU FDI TX PLL */ |
| 4352 | reg = FDI_TX_CTL(pipe); |
| 4353 | temp = I915_READ(reg); |
| 4354 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4355 | |
| 4356 | POSTING_READ(reg); |
| 4357 | udelay(100); |
| 4358 | |
| 4359 | reg = FDI_RX_CTL(pipe); |
| 4360 | temp = I915_READ(reg); |
| 4361 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4362 | |
| 4363 | /* Wait for the clocks to turn off. */ |
| 4364 | POSTING_READ(reg); |
| 4365 | udelay(100); |
| 4366 | } |
| 4367 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4368 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4369 | { |
| 4370 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4371 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4372 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4373 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4374 | i915_reg_t reg; |
| 4375 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4376 | |
| 4377 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4378 | reg = FDI_TX_CTL(pipe); |
| 4379 | temp = I915_READ(reg); |
| 4380 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4381 | POSTING_READ(reg); |
| 4382 | |
| 4383 | reg = FDI_RX_CTL(pipe); |
| 4384 | temp = I915_READ(reg); |
| 4385 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4386 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4387 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4388 | |
| 4389 | POSTING_READ(reg); |
| 4390 | udelay(100); |
| 4391 | |
| 4392 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4393 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4394 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4395 | |
| 4396 | /* still set train pattern 1 */ |
| 4397 | reg = FDI_TX_CTL(pipe); |
| 4398 | temp = I915_READ(reg); |
| 4399 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4400 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4401 | I915_WRITE(reg, temp); |
| 4402 | |
| 4403 | reg = FDI_RX_CTL(pipe); |
| 4404 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4405 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4406 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4407 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4408 | } else { |
| 4409 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4410 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4411 | } |
| 4412 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4413 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4414 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4415 | I915_WRITE(reg, temp); |
| 4416 | |
| 4417 | POSTING_READ(reg); |
| 4418 | udelay(100); |
| 4419 | } |
| 4420 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4421 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4422 | { |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4423 | struct drm_crtc *crtc; |
| 4424 | bool cleanup_done; |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4425 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4426 | drm_for_each_crtc(crtc, &dev_priv->drm) { |
| 4427 | struct drm_crtc_commit *commit; |
| 4428 | spin_lock(&crtc->commit_lock); |
| 4429 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 4430 | struct drm_crtc_commit, commit_entry); |
| 4431 | cleanup_done = commit ? |
| 4432 | try_wait_for_completion(&commit->cleanup_done) : true; |
| 4433 | spin_unlock(&crtc->commit_lock); |
| 4434 | |
| 4435 | if (cleanup_done) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4436 | continue; |
| 4437 | |
Daniel Vetter | fa05887 | 2017-07-20 19:57:52 +0200 | [diff] [blame] | 4438 | drm_crtc_wait_one_vblank(crtc); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4439 | |
| 4440 | return true; |
| 4441 | } |
| 4442 | |
| 4443 | return false; |
| 4444 | } |
| 4445 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4446 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4447 | { |
| 4448 | u32 temp; |
| 4449 | |
| 4450 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4451 | |
| 4452 | mutex_lock(&dev_priv->sb_lock); |
| 4453 | |
| 4454 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4455 | temp |= SBI_SSCCTL_DISABLE; |
| 4456 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4457 | |
| 4458 | mutex_unlock(&dev_priv->sb_lock); |
| 4459 | } |
| 4460 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4461 | /* Program iCLKIP clock to the desired frequency */ |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4462 | static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state) |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4463 | { |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4464 | 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] | 4465 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4466 | int clock = crtc_state->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4467 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4468 | u32 temp; |
| 4469 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4470 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4471 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4472 | /* The iCLK virtual clock root frequency is in MHz, |
| 4473 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4474 | * divisors, it is necessary to divide one by another, so we |
| 4475 | * convert the virtual clock precision to KHz here for higher |
| 4476 | * precision. |
| 4477 | */ |
| 4478 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4479 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4480 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4481 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4482 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4483 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4484 | clock << auxdiv); |
| 4485 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4486 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4487 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4488 | /* |
| 4489 | * Near 20MHz is a corner case which is |
| 4490 | * out of range for the 7-bit divisor |
| 4491 | */ |
| 4492 | if (divsel <= 0x7f) |
| 4493 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /* This should not happen with any sane values */ |
| 4497 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4498 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4499 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4500 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4501 | |
| 4502 | 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] | 4503 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4504 | auxdiv, |
| 4505 | divsel, |
| 4506 | phasedir, |
| 4507 | phaseinc); |
| 4508 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4509 | mutex_lock(&dev_priv->sb_lock); |
| 4510 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4511 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4512 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4513 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4514 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4515 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4516 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4517 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4518 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4519 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4520 | |
| 4521 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4522 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4523 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4524 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4525 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4526 | |
| 4527 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4528 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4529 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4530 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4531 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4532 | mutex_unlock(&dev_priv->sb_lock); |
| 4533 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4534 | /* Wait for initialization time */ |
| 4535 | udelay(24); |
| 4536 | |
| 4537 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4538 | } |
| 4539 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4540 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4541 | { |
| 4542 | u32 divsel, phaseinc, auxdiv; |
| 4543 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4544 | u32 iclk_pi_range = 64; |
| 4545 | u32 desired_divisor; |
| 4546 | u32 temp; |
| 4547 | |
| 4548 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4549 | return 0; |
| 4550 | |
| 4551 | mutex_lock(&dev_priv->sb_lock); |
| 4552 | |
| 4553 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4554 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4555 | mutex_unlock(&dev_priv->sb_lock); |
| 4556 | return 0; |
| 4557 | } |
| 4558 | |
| 4559 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4560 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4561 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4562 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4563 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4564 | |
| 4565 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4566 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4567 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4568 | |
| 4569 | mutex_unlock(&dev_priv->sb_lock); |
| 4570 | |
| 4571 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4572 | |
| 4573 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4574 | desired_divisor << auxdiv); |
| 4575 | } |
| 4576 | |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4577 | 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] | 4578 | enum pipe pch_transcoder) |
| 4579 | { |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4580 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4581 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4582 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4583 | |
| 4584 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4585 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4586 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4587 | I915_READ(HBLANK(cpu_transcoder))); |
| 4588 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4589 | I915_READ(HSYNC(cpu_transcoder))); |
| 4590 | |
| 4591 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4592 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4593 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4594 | I915_READ(VBLANK(cpu_transcoder))); |
| 4595 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4596 | I915_READ(VSYNC(cpu_transcoder))); |
| 4597 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4598 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4599 | } |
| 4600 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4601 | 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] | 4602 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 4603 | u32 temp; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4604 | |
| 4605 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4606 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4607 | return; |
| 4608 | |
| 4609 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4610 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4611 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4612 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4613 | if (enable) |
| 4614 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4615 | |
| 4616 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4617 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4618 | POSTING_READ(SOUTH_CHICKEN1); |
| 4619 | } |
| 4620 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4621 | 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] | 4622 | { |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4623 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 4624 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4625 | |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4626 | switch (crtc->pipe) { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4627 | case PIPE_A: |
| 4628 | break; |
| 4629 | case PIPE_B: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4630 | if (crtc_state->fdi_lanes > 2) |
| 4631 | cpt_set_fdi_bc_bifurcation(dev_priv, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4632 | else |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4633 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4634 | |
| 4635 | break; |
| 4636 | case PIPE_C: |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4637 | cpt_set_fdi_bc_bifurcation(dev_priv, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4638 | |
| 4639 | break; |
| 4640 | default: |
| 4641 | BUG(); |
| 4642 | } |
| 4643 | } |
| 4644 | |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4645 | /* |
| 4646 | * Finds the encoder associated with the given CRTC. This can only be |
| 4647 | * used when we know that the CRTC isn't feeding multiple encoders! |
| 4648 | */ |
| 4649 | static struct intel_encoder * |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4650 | intel_get_crtc_new_encoder(const struct intel_atomic_state *state, |
| 4651 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4652 | { |
| 4653 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | f606bc6 | 2018-05-18 18:29:25 +0300 | [diff] [blame] | 4654 | const struct drm_connector_state *connector_state; |
| 4655 | const struct drm_connector *connector; |
| 4656 | struct intel_encoder *encoder = NULL; |
| 4657 | int num_encoders = 0; |
| 4658 | int i; |
| 4659 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4660 | 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] | 4661 | if (connector_state->crtc != &crtc->base) |
| 4662 | continue; |
| 4663 | |
| 4664 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 4665 | num_encoders++; |
| 4666 | } |
| 4667 | |
| 4668 | WARN(num_encoders != 1, "%d encoders for pipe %c\n", |
| 4669 | num_encoders, pipe_name(crtc->pipe)); |
| 4670 | |
| 4671 | return encoder; |
| 4672 | } |
| 4673 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4674 | /* |
| 4675 | * Enable PCH resources required for PCH ports: |
| 4676 | * - PCH PLLs |
| 4677 | * - FDI training & RX/TX |
| 4678 | * - update transcoder timings |
| 4679 | * - DP transcoding bits |
| 4680 | * - transcoder |
| 4681 | */ |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4682 | static void ironlake_pch_enable(const struct intel_atomic_state *state, |
| 4683 | const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4684 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4685 | 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] | 4686 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4687 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 4cbe4b2 | 2017-03-02 14:58:51 +0200 | [diff] [blame] | 4688 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4689 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4690 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4691 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4692 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4693 | if (IS_IVYBRIDGE(dev_priv)) |
Maarten Lankhorst | b0b62d8 | 2018-10-11 12:04:56 +0200 | [diff] [blame] | 4694 | ivybridge_update_fdi_bc_bifurcation(crtc_state); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4695 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4696 | /* Write the TU size bits before fdi link training, so that error |
| 4697 | * detection works. */ |
| 4698 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4699 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4700 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4701 | /* For PCH output, training FDI link */ |
Ander Conselvan de Oliveira | dc4a109 | 2017-03-02 14:58:54 +0200 | [diff] [blame] | 4702 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4703 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4704 | /* We need to program the right clock selection before writing the pixel |
| 4705 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4706 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4707 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4708 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4709 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4710 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4711 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4712 | if (crtc_state->shared_dpll == |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4713 | 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] | 4714 | temp |= sel; |
| 4715 | else |
| 4716 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4717 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4718 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4719 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4720 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4721 | * transcoder, and we actually should do this to not upset any PCH |
| 4722 | * transcoder that already use the clock when we share it. |
| 4723 | * |
| 4724 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4725 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4726 | * the right LVDS enable sequence. */ |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 4727 | intel_enable_shared_dpll(crtc_state); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4728 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4729 | /* set transcoder timing, panel must allow it */ |
| 4730 | assert_panel_unlocked(dev_priv, pipe); |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4731 | ironlake_pch_transcoder_set_timings(crtc_state, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4732 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4733 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4734 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4735 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4736 | if (HAS_PCH_CPT(dev_priv) && |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4737 | intel_crtc_has_dp_encoder(crtc_state)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4738 | const struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4739 | &crtc_state->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4740 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4741 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4742 | enum port port; |
| 4743 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4744 | temp = I915_READ(reg); |
| 4745 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4746 | TRANS_DP_SYNC_MASK | |
| 4747 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4748 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4749 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4750 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4751 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4752 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4753 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4754 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4755 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4756 | port = intel_get_crtc_new_encoder(state, crtc_state)->port; |
Ville Syrjälä | f67dc6d | 2018-05-18 18:29:26 +0300 | [diff] [blame] | 4757 | WARN_ON(port < PORT_B || port > PORT_D); |
| 4758 | temp |= TRANS_DP_PORT_SEL(port); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4759 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4760 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
Maarten Lankhorst | 7efd90f | 2018-10-04 11:45:55 +0200 | [diff] [blame] | 4763 | ironlake_enable_pch_transcoder(crtc_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4764 | } |
| 4765 | |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 4766 | static void lpt_pch_enable(const struct intel_atomic_state *state, |
| 4767 | const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4768 | { |
Ander Conselvan de Oliveira | 2ce4227 | 2017-03-02 14:58:53 +0200 | [diff] [blame] | 4769 | 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] | 4770 | 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] | 4771 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4772 | |
Matthias Kaehlcke | a219603 | 2017-07-17 11:14:03 -0700 | [diff] [blame] | 4773 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4774 | |
Maarten Lankhorst | c5b36fa | 2018-10-11 12:04:55 +0200 | [diff] [blame] | 4775 | lpt_program_iclkip(crtc_state); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4776 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4777 | /* Set transcoder timing. */ |
Maarten Lankhorst | 5e1cdf5 | 2018-10-04 11:45:58 +0200 | [diff] [blame] | 4778 | ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4779 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4780 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4781 | } |
| 4782 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4783 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4784 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4785 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4786 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4787 | u32 temp; |
| 4788 | |
| 4789 | temp = I915_READ(dslreg); |
| 4790 | udelay(500); |
| 4791 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4792 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4793 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4794 | } |
| 4795 | } |
| 4796 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4797 | /* |
| 4798 | * The hardware phase 0.0 refers to the center of the pixel. |
| 4799 | * We want to start from the top/left edge which is phase |
| 4800 | * -0.5. That matches how the hardware calculates the scaling |
| 4801 | * factors (from top-left of the first pixel to bottom-right |
| 4802 | * of the last pixel, as opposed to the pixel centers). |
| 4803 | * |
| 4804 | * For 4:2:0 subsampled chroma planes we obviously have to |
| 4805 | * adjust that so that the chroma sample position lands in |
| 4806 | * the right spot. |
| 4807 | * |
| 4808 | * Note that for packed YCbCr 4:2:2 formats there is no way to |
| 4809 | * control chroma siting. The hardware simply replicates the |
| 4810 | * chroma samples for both of the luma samples, and thus we don't |
| 4811 | * actually get the expected MPEG2 chroma siting convention :( |
| 4812 | * The same behaviour is observed on pre-SKL platforms as well. |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4813 | * |
| 4814 | * Theory behind the formula (note that we ignore sub-pixel |
| 4815 | * source coordinates): |
| 4816 | * s = source sample position |
| 4817 | * d = destination sample position |
| 4818 | * |
| 4819 | * Downscaling 4:1: |
| 4820 | * -0.5 |
| 4821 | * | 0.0 |
| 4822 | * | | 1.5 (initial phase) |
| 4823 | * | | | |
| 4824 | * v v v |
| 4825 | * | s | s | s | s | |
| 4826 | * | d | |
| 4827 | * |
| 4828 | * Upscaling 1:4: |
| 4829 | * -0.5 |
| 4830 | * | -0.375 (initial phase) |
| 4831 | * | | 0.0 |
| 4832 | * | | | |
| 4833 | * v v v |
| 4834 | * | s | |
| 4835 | * | d | d | d | d | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4836 | */ |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4837 | 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] | 4838 | { |
| 4839 | int phase = -0x8000; |
| 4840 | u16 trip = 0; |
| 4841 | |
| 4842 | if (chroma_cosited) |
| 4843 | phase += (sub - 1) * 0x8000 / sub; |
| 4844 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 4845 | phase += scale / (2 * sub); |
| 4846 | |
| 4847 | /* |
| 4848 | * Hardware initial phase limited to [-0.5:1.5]. |
| 4849 | * Since the max hardware scale factor is 3.0, we |
| 4850 | * should never actually excdeed 1.0 here. |
| 4851 | */ |
| 4852 | WARN_ON(phase < -0x8000 || phase > 0x18000); |
| 4853 | |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 4854 | if (phase < 0) |
| 4855 | phase = 0x10000 + phase; |
| 4856 | else |
| 4857 | trip = PS_PHASE_TRIP; |
| 4858 | |
| 4859 | return ((phase >> 2) & PS_PHASE_MASK) | trip; |
| 4860 | } |
| 4861 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4862 | static int |
| 4863 | 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] | 4864 | unsigned int scaler_user, int *scaler_id, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4865 | int src_w, int src_h, int dst_w, int dst_h, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4866 | const struct drm_format_info *format, bool need_scaler) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4867 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4868 | struct intel_crtc_scaler_state *scaler_state = |
| 4869 | &crtc_state->scaler_state; |
| 4870 | struct intel_crtc *intel_crtc = |
| 4871 | to_intel_crtc(crtc_state->base.crtc); |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4872 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 4873 | const struct drm_display_mode *adjusted_mode = |
| 4874 | &crtc_state->base.adjusted_mode; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4875 | |
Ville Syrjälä | d96a7d2 | 2017-03-31 21:00:54 +0300 | [diff] [blame] | 4876 | /* |
| 4877 | * Src coordinates are already rotated by 270 degrees for |
| 4878 | * the 90/270 degree plane rotation cases (to match the |
| 4879 | * GTT mapping), hence no need to account for rotation here. |
| 4880 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4881 | if (src_w != dst_w || src_h != dst_h) |
| 4882 | need_scaler = true; |
Shashank Sharma | e5c0593 | 2017-07-21 20:55:05 +0530 | [diff] [blame] | 4883 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4884 | /* |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4885 | * Scaling/fitting not supported in IF-ID mode in GEN9+ |
| 4886 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. |
| 4887 | * Once NV12 is enabled, handle it here while allocating scaler |
| 4888 | * for NV12. |
| 4889 | */ |
| 4890 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4891 | need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Mahesh Kumar | 7f58cbb | 2017-06-30 17:41:00 +0530 | [diff] [blame] | 4892 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); |
| 4893 | return -EINVAL; |
| 4894 | } |
| 4895 | |
| 4896 | /* |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4897 | * if plane is being disabled or scaler is no more required or force detach |
| 4898 | * - free scaler binded to this plane/crtc |
| 4899 | * - in order to do this, update crtc->scaler_usage |
| 4900 | * |
| 4901 | * Here scaler state in crtc_state is set free so that |
| 4902 | * scaler can be assigned to other user. Actual register |
| 4903 | * update to free the scaler is done in plane/panel-fit programming. |
| 4904 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4905 | */ |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4906 | if (force_detach || !need_scaler) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4907 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4908 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4909 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4910 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4911 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4912 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4913 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4914 | scaler_state->scaler_users); |
| 4915 | *scaler_id = -1; |
| 4916 | } |
| 4917 | return 0; |
| 4918 | } |
| 4919 | |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4920 | if (format && format->format == DRM_FORMAT_NV12 && |
Maarten Lankhorst | 5d79428 | 2018-05-12 03:03:14 +0530 | [diff] [blame] | 4921 | (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] | 4922 | DRM_DEBUG_KMS("NV12: src dimensions not met\n"); |
| 4923 | return -EINVAL; |
| 4924 | } |
| 4925 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4926 | /* range checks */ |
| 4927 | 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] | 4928 | 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] | 4929 | (IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 4930 | (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H || |
| 4931 | 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] | 4932 | (!IS_GEN(dev_priv, 11) && |
Nabendu Maiti | 323301a | 2018-03-23 10:24:18 -0700 | [diff] [blame] | 4933 | (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4934 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4935 | 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] | 4936 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4937 | 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] | 4938 | return -EINVAL; |
| 4939 | } |
| 4940 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4941 | /* mark this plane as a scaler user in crtc_state */ |
| 4942 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4943 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4944 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4945 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4946 | scaler_state->scaler_users); |
| 4947 | |
| 4948 | return 0; |
| 4949 | } |
| 4950 | |
| 4951 | /** |
| 4952 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4953 | * |
| 4954 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4955 | * |
| 4956 | * Return |
| 4957 | * 0 - scaler_usage updated successfully |
| 4958 | * error - requested scaling cannot be supported or other error condition |
| 4959 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4960 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4961 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4962 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4963 | bool need_scaler = false; |
| 4964 | |
| 4965 | if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
| 4966 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4967 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4968 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 4969 | &state->scaler_state.scaler_id, |
| 4970 | state->pipe_src_w, state->pipe_src_h, |
| 4971 | adjusted_mode->crtc_hdisplay, |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4972 | adjusted_mode->crtc_vdisplay, NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | /** |
| 4976 | * 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] | 4977 | * @crtc_state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4978 | * @plane_state: atomic plane state to update |
| 4979 | * |
| 4980 | * Return |
| 4981 | * 0 - scaler_usage updated successfully |
| 4982 | * error - requested scaling cannot be supported or other error condition |
| 4983 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4984 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4985 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4986 | { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4987 | struct intel_plane *intel_plane = |
| 4988 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4989 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4990 | int ret; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4991 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 4992 | bool need_scaler = false; |
| 4993 | |
| 4994 | /* Pre-gen11 and SDR planes always need a scaler for planar formats. */ |
| 4995 | if (!icl_is_hdr_plane(intel_plane) && |
| 4996 | fb && fb->format->format == DRM_FORMAT_NV12) |
| 4997 | need_scaler = true; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4998 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4999 | ret = skl_update_scaler(crtc_state, force_detach, |
| 5000 | drm_plane_index(&intel_plane->base), |
| 5001 | &plane_state->scaler_id, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5002 | drm_rect_width(&plane_state->base.src) >> 16, |
| 5003 | drm_rect_height(&plane_state->base.src) >> 16, |
| 5004 | drm_rect_width(&plane_state->base.dst), |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5005 | drm_rect_height(&plane_state->base.dst), |
Maarten Lankhorst | b1554e2 | 2018-10-18 13:51:31 +0200 | [diff] [blame] | 5006 | fb ? fb->format : NULL, need_scaler); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5007 | |
| 5008 | if (ret || plane_state->scaler_id < 0) |
| 5009 | return ret; |
| 5010 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5011 | /* check colorkey */ |
Ville Syrjälä | 6ec5bd3 | 2018-02-02 22:42:31 +0200 | [diff] [blame] | 5012 | if (plane_state->ckey.flags) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5013 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 5014 | intel_plane->base.base.id, |
| 5015 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5016 | return -EINVAL; |
| 5017 | } |
| 5018 | |
| 5019 | /* Check src format */ |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5020 | switch (fb->format->format) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5021 | case DRM_FORMAT_RGB565: |
| 5022 | case DRM_FORMAT_XBGR8888: |
| 5023 | case DRM_FORMAT_XRGB8888: |
| 5024 | case DRM_FORMAT_ABGR8888: |
| 5025 | case DRM_FORMAT_ARGB8888: |
| 5026 | case DRM_FORMAT_XRGB2101010: |
| 5027 | case DRM_FORMAT_XBGR2101010: |
| 5028 | case DRM_FORMAT_YUYV: |
| 5029 | case DRM_FORMAT_YVYU: |
| 5030 | case DRM_FORMAT_UYVY: |
| 5031 | case DRM_FORMAT_VYUY: |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 5032 | case DRM_FORMAT_NV12: |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5033 | break; |
| 5034 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 5035 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 5036 | intel_plane->base.base.id, intel_plane->base.name, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 5037 | fb->base.id, fb->format->format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 5038 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5039 | } |
| 5040 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5041 | return 0; |
| 5042 | } |
| 5043 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5044 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 5045 | { |
| 5046 | int i; |
| 5047 | |
| 5048 | for (i = 0; i < crtc->num_scalers; i++) |
| 5049 | skl_detach_scaler(crtc, i); |
| 5050 | } |
| 5051 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5052 | static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 5053 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5054 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5055 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5056 | enum pipe pipe = crtc->pipe; |
| 5057 | const struct intel_crtc_scaler_state *scaler_state = |
| 5058 | &crtc_state->scaler_state; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5059 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5060 | if (crtc_state->pch_pfit.enabled) { |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5061 | u16 uv_rgb_hphase, uv_rgb_vphase; |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5062 | int pfit_w, pfit_h, hscale, vscale; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5063 | int id; |
| 5064 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5065 | if (WARN_ON(crtc_state->scaler_state.scaler_id < 0)) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5066 | return; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5067 | |
Ville Syrjälä | e7a278a | 2018-10-29 20:18:20 +0200 | [diff] [blame] | 5068 | pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF; |
| 5069 | pfit_h = crtc_state->pch_pfit.size & 0xFFFF; |
| 5070 | |
| 5071 | hscale = (crtc_state->pipe_src_w << 16) / pfit_w; |
| 5072 | vscale = (crtc_state->pipe_src_h << 16) / pfit_h; |
| 5073 | |
| 5074 | uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false); |
| 5075 | uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5076 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 5077 | id = scaler_state->scaler_id; |
| 5078 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 5079 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
Ville Syrjälä | 0a59952 | 2018-05-21 21:56:13 +0300 | [diff] [blame] | 5080 | I915_WRITE_FW(SKL_PS_VPHASE(pipe, id), |
| 5081 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase)); |
| 5082 | I915_WRITE_FW(SKL_PS_HPHASE(pipe, id), |
| 5083 | PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase)); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5084 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos); |
| 5085 | 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] | 5086 | } |
| 5087 | } |
| 5088 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5089 | static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5090 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5091 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5092 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5093 | int pipe = crtc->pipe; |
| 5094 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5095 | if (crtc_state->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5096 | /* Force use of hard-coded filter coefficients |
| 5097 | * as some pre-programmed values are broken, |
| 5098 | * e.g. x201. |
| 5099 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 5100 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5101 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 5102 | PF_PIPE_SEL_IVB(pipe)); |
| 5103 | else |
| 5104 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5105 | I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos); |
| 5106 | I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 5107 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5108 | } |
| 5109 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5110 | void hsw_enable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5111 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5112 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 5113 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5114 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5115 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5116 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5117 | return; |
| 5118 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 5119 | /* |
| 5120 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 5121 | * This function is called from post_plane_update, which is run after |
| 5122 | * a vblank wait. |
| 5123 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5124 | WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 5125 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5126 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5127 | mutex_lock(&dev_priv->pcu_lock); |
Ville Syrjälä | 61843f0 | 2017-09-12 18:34:11 +0300 | [diff] [blame] | 5128 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
| 5129 | IPS_ENABLE | IPS_PCODE_CONTROL)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5130 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5131 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 5132 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5133 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 5134 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5135 | */ |
| 5136 | } else { |
| 5137 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 5138 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 5139 | * is essentially intel_wait_for_vblank. If we don't have this |
| 5140 | * and don't wait for vblanks until the end of crtc_enable, then |
| 5141 | * the HW state readout code will complain that the expected |
| 5142 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 5143 | if (intel_wait_for_register(dev_priv, |
| 5144 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 5145 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5146 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 5147 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5148 | } |
| 5149 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5150 | void hsw_disable_ips(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5151 | { |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5152 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5153 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5154 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5155 | |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5156 | if (!crtc_state->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5157 | return; |
| 5158 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5159 | if (IS_BROADWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5160 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5161 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 5162 | mutex_unlock(&dev_priv->pcu_lock); |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5163 | /* |
| 5164 | * Wait for PCODE to finish disabling IPS. The BSpec specified |
| 5165 | * 42ms timeout value leads to occasional timeouts so use 100ms |
| 5166 | * instead. |
| 5167 | */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 5168 | if (intel_wait_for_register(dev_priv, |
| 5169 | IPS_CTL, IPS_ENABLE, 0, |
Imre Deak | acb3ef0 | 2018-09-05 13:00:05 +0300 | [diff] [blame] | 5170 | 100)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 5171 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5172 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 5173 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 5174 | POSTING_READ(IPS_CTL); |
| 5175 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5176 | |
| 5177 | /* 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] | 5178 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 5179 | } |
| 5180 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5181 | 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] | 5182 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5183 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5184 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5185 | |
| 5186 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5187 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 5188 | mutex_unlock(&dev->struct_mutex); |
| 5189 | } |
| 5190 | |
| 5191 | /* Let userspace switch the overlay on again. In most cases userspace |
| 5192 | * has to recompute where to put it anyway. |
| 5193 | */ |
| 5194 | } |
| 5195 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5196 | /** |
| 5197 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 5198 | * @crtc: the CRTC whose primary plane was just enabled |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 5199 | * @new_crtc_state: the enabling state |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5200 | * |
| 5201 | * Performs potentially sleeping operations that must be done after the primary |
| 5202 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 5203 | * called due to an explicit primary plane update, or due to an implicit |
| 5204 | * re-enable that is caused when a sprite plane is updated to no longer |
| 5205 | * completely hide the primary plane. |
| 5206 | */ |
| 5207 | static void |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5208 | intel_post_enable_primary(struct drm_crtc *crtc, |
| 5209 | const struct intel_crtc_state *new_crtc_state) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5210 | { |
| 5211 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5212 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5213 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5214 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5215 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5216 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5217 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5218 | * So don't enable underrun reporting before at least some planes |
| 5219 | * are enabled. |
| 5220 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5221 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5222 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5223 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5224 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5225 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 5226 | /* Underruns don't always raise interrupts, so check manually. */ |
| 5227 | intel_check_cpu_fifo_underruns(dev_priv); |
| 5228 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5229 | } |
| 5230 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5231 | /* FIXME get rid of this and use pre_plane_update */ |
| 5232 | static void |
| 5233 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5234 | { |
| 5235 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5236 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5237 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5238 | int pipe = intel_crtc->pipe; |
| 5239 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5240 | /* |
| 5241 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5242 | * So disable underrun reporting before all the planes get disabled. |
| 5243 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5244 | if (IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5245 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5246 | |
| 5247 | hsw_disable_ips(to_intel_crtc_state(crtc->state)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5248 | |
| 5249 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5250 | * Vblank time updates from the shadow to live plane control register |
| 5251 | * are blocked if the memory self-refresh mode is active at that |
| 5252 | * moment. So to make sure the plane gets truly disabled, disable |
| 5253 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5254 | * will be checked/applied by the HW only at the next frame start |
| 5255 | * event which is after the vblank start event, so we need to have a |
| 5256 | * wait-for-vblank between disabling the plane and the pipe. |
| 5257 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5258 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 5259 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5260 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5261 | } |
| 5262 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5263 | static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5264 | const struct intel_crtc_state *new_crtc_state) |
| 5265 | { |
| 5266 | if (!old_crtc_state->ips_enabled) |
| 5267 | return false; |
| 5268 | |
| 5269 | if (needs_modeset(&new_crtc_state->base)) |
| 5270 | return true; |
| 5271 | |
| 5272 | return !new_crtc_state->ips_enabled; |
| 5273 | } |
| 5274 | |
| 5275 | static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state, |
| 5276 | const struct intel_crtc_state *new_crtc_state) |
| 5277 | { |
| 5278 | if (!new_crtc_state->ips_enabled) |
| 5279 | return false; |
| 5280 | |
| 5281 | if (needs_modeset(&new_crtc_state->base)) |
| 5282 | return true; |
| 5283 | |
| 5284 | /* |
| 5285 | * We can't read out IPS on broadwell, assume the worst and |
| 5286 | * forcibly enable IPS on the first fastset. |
| 5287 | */ |
| 5288 | if (new_crtc_state->update_pipe && |
| 5289 | old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 5290 | return true; |
| 5291 | |
| 5292 | return !old_crtc_state->ips_enabled; |
| 5293 | } |
| 5294 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5295 | static bool needs_nv12_wa(struct drm_i915_private *dev_priv, |
| 5296 | const struct intel_crtc_state *crtc_state) |
| 5297 | { |
| 5298 | if (!crtc_state->nv12_planes) |
| 5299 | return false; |
| 5300 | |
Rodrigo Vivi | 1347d3c | 2018-10-31 09:28:45 -0700 | [diff] [blame] | 5301 | /* WA Display #0827: Gen9:all */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5302 | if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv)) |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5303 | return true; |
| 5304 | |
| 5305 | return false; |
| 5306 | } |
| 5307 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5308 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5309 | { |
| 5310 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Vidya Srinivas | c4a4efa | 2018-04-09 09:11:09 +0530 | [diff] [blame] | 5311 | struct drm_device *dev = crtc->base.dev; |
| 5312 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5313 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5314 | struct intel_crtc_state *pipe_config = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5315 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
| 5316 | crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5317 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5318 | struct drm_plane_state *old_primary_state = |
| 5319 | drm_atomic_get_old_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5320 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5321 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5322 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5323 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5324 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5325 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5326 | if (hsw_post_update_enable_ips(old_crtc_state, pipe_config)) |
| 5327 | hsw_enable_ips(pipe_config); |
| 5328 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5329 | if (old_primary_state) { |
| 5330 | struct drm_plane_state *new_primary_state = |
| 5331 | drm_atomic_get_new_plane_state(old_state, primary); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5332 | |
| 5333 | intel_fbc_post_update(crtc); |
| 5334 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5335 | if (new_primary_state->visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5336 | (needs_modeset(&pipe_config->base) || |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5337 | !old_primary_state->visible)) |
Maarten Lankhorst | 199ea38 | 2017-11-10 12:35:00 +0100 | [diff] [blame] | 5338 | intel_post_enable_primary(&crtc->base, pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5339 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5340 | |
| 5341 | /* Display WA 827 */ |
| 5342 | if (needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5343 | !needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5344 | skl_wa_clkgate(dev_priv, crtc->pipe, false); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5345 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5346 | } |
| 5347 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5348 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
| 5349 | struct intel_crtc_state *pipe_config) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5350 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5351 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5352 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5353 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5354 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5355 | struct drm_plane *primary = crtc->base.primary; |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5356 | struct drm_plane_state *old_primary_state = |
| 5357 | drm_atomic_get_old_plane_state(old_state, primary); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5358 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5359 | struct intel_atomic_state *old_intel_state = |
| 5360 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5361 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5362 | if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config)) |
| 5363 | hsw_disable_ips(old_crtc_state); |
| 5364 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5365 | if (old_primary_state) { |
| 5366 | struct intel_plane_state *new_primary_state = |
Ville Syrjälä | f9a8c14 | 2017-08-23 18:22:24 +0300 | [diff] [blame] | 5367 | intel_atomic_get_new_plane_state(old_intel_state, |
| 5368 | to_intel_plane(primary)); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5369 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5370 | intel_fbc_pre_update(crtc, pipe_config, new_primary_state); |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5371 | /* |
| 5372 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5373 | * So disable underrun reporting before all the planes get disabled. |
| 5374 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 5375 | if (IS_GEN(dev_priv, 2) && old_primary_state->visible && |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 5376 | (modeset || !new_primary_state->base.visible)) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 5377 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5378 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5379 | |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5380 | /* Display WA 827 */ |
| 5381 | if (!needs_nv12_wa(dev_priv, old_crtc_state) && |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5382 | needs_nv12_wa(dev_priv, pipe_config)) { |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5383 | skl_wa_clkgate(dev_priv, crtc->pipe, true); |
Vidya Srinivas | 6deef9b | 2018-05-12 03:03:13 +0530 | [diff] [blame] | 5384 | } |
Maarten Lankhorst | 8e02115 | 2018-05-12 03:03:12 +0530 | [diff] [blame] | 5385 | |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 5386 | /* |
| 5387 | * Vblank time updates from the shadow to live plane control register |
| 5388 | * are blocked if the memory self-refresh mode is active at that |
| 5389 | * moment. So to make sure the plane gets truly disabled, disable |
| 5390 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5391 | * will be checked/applied by the HW only at the next frame start |
| 5392 | * event which is after the vblank start event, so we need to have a |
| 5393 | * wait-for-vblank between disabling the plane and the pipe. |
| 5394 | */ |
| 5395 | if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active && |
| 5396 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) |
| 5397 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5398 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5399 | /* |
| 5400 | * IVB workaround: must disable low power watermarks for at least |
| 5401 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5402 | * when scaling is disabled. |
| 5403 | * |
| 5404 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5405 | */ |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 5406 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) && |
| 5407 | old_crtc_state->base.active) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5408 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5409 | |
| 5410 | /* |
| 5411 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5412 | * watermark programming here. |
| 5413 | */ |
| 5414 | if (needs_modeset(&pipe_config->base)) |
| 5415 | return; |
| 5416 | |
| 5417 | /* |
| 5418 | * For platforms that support atomic watermarks, program the |
| 5419 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5420 | * will be the intermediate values that are safe for both pre- and |
| 5421 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5422 | * to the final 'target' values and we'll do this again to get the |
| 5423 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5424 | * will be the final target values which will get automatically latched |
| 5425 | * at vblank time; no further programming will be necessary. |
| 5426 | * |
| 5427 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5428 | * we'll continue to update watermarks the old way, if flags tell |
| 5429 | * us to. |
| 5430 | */ |
| 5431 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5432 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5433 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5434 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5435 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5436 | } |
| 5437 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5438 | static void intel_crtc_disable_planes(struct intel_atomic_state *state, |
| 5439 | struct intel_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5440 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5441 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5442 | const struct intel_crtc_state *new_crtc_state = |
| 5443 | intel_atomic_get_new_crtc_state(state, crtc); |
| 5444 | unsigned int update_mask = new_crtc_state->update_planes; |
| 5445 | const struct intel_plane_state *old_plane_state; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5446 | struct intel_plane *plane; |
| 5447 | unsigned fb_bits = 0; |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5448 | int i; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5449 | |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5450 | intel_crtc_dpms_overlay_disable(crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5451 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5452 | for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { |
| 5453 | if (crtc->pipe != plane->pipe || |
| 5454 | !(update_mask & BIT(plane->id))) |
| 5455 | continue; |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5456 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5457 | plane->disable_plane(plane, new_crtc_state); |
| 5458 | |
| 5459 | if (old_plane_state->base.visible) |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5460 | fb_bits |= plane->frontbuffer_bit; |
Maarten Lankhorst | f59e970 | 2018-09-20 12:27:07 +0200 | [diff] [blame] | 5461 | } |
| 5462 | |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 5463 | intel_frontbuffer_flip(dev_priv, fb_bits); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5464 | } |
| 5465 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5466 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5467 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5468 | struct drm_atomic_state *old_state) |
| 5469 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5470 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5471 | struct drm_connector *conn; |
| 5472 | int i; |
| 5473 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5474 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5475 | struct intel_encoder *encoder = |
| 5476 | to_intel_encoder(conn_state->best_encoder); |
| 5477 | |
| 5478 | if (conn_state->crtc != crtc) |
| 5479 | continue; |
| 5480 | |
| 5481 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5482 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5483 | } |
| 5484 | } |
| 5485 | |
| 5486 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5487 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5488 | struct drm_atomic_state *old_state) |
| 5489 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5490 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5491 | struct drm_connector *conn; |
| 5492 | int i; |
| 5493 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5494 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5495 | struct intel_encoder *encoder = |
| 5496 | to_intel_encoder(conn_state->best_encoder); |
| 5497 | |
| 5498 | if (conn_state->crtc != crtc) |
| 5499 | continue; |
| 5500 | |
| 5501 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5502 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5507 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5508 | struct drm_atomic_state *old_state) |
| 5509 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5510 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5511 | struct drm_connector *conn; |
| 5512 | int i; |
| 5513 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5514 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5515 | struct intel_encoder *encoder = |
| 5516 | to_intel_encoder(conn_state->best_encoder); |
| 5517 | |
| 5518 | if (conn_state->crtc != crtc) |
| 5519 | continue; |
| 5520 | |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5521 | if (encoder->enable) |
| 5522 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5523 | intel_opregion_notify_encoder(encoder, true); |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5528 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5529 | struct drm_atomic_state *old_state) |
| 5530 | { |
| 5531 | struct drm_connector_state *old_conn_state; |
| 5532 | struct drm_connector *conn; |
| 5533 | int i; |
| 5534 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5535 | 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] | 5536 | struct intel_encoder *encoder = |
| 5537 | to_intel_encoder(old_conn_state->best_encoder); |
| 5538 | |
| 5539 | if (old_conn_state->crtc != crtc) |
| 5540 | continue; |
| 5541 | |
| 5542 | intel_opregion_notify_encoder(encoder, false); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 5543 | if (encoder->disable) |
| 5544 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5545 | } |
| 5546 | } |
| 5547 | |
| 5548 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5549 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5550 | struct drm_atomic_state *old_state) |
| 5551 | { |
| 5552 | struct drm_connector_state *old_conn_state; |
| 5553 | struct drm_connector *conn; |
| 5554 | int i; |
| 5555 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5556 | 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] | 5557 | struct intel_encoder *encoder = |
| 5558 | to_intel_encoder(old_conn_state->best_encoder); |
| 5559 | |
| 5560 | if (old_conn_state->crtc != crtc) |
| 5561 | continue; |
| 5562 | |
| 5563 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5564 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5569 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5570 | struct drm_atomic_state *old_state) |
| 5571 | { |
| 5572 | struct drm_connector_state *old_conn_state; |
| 5573 | struct drm_connector *conn; |
| 5574 | int i; |
| 5575 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 5576 | 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] | 5577 | struct intel_encoder *encoder = |
| 5578 | to_intel_encoder(old_conn_state->best_encoder); |
| 5579 | |
| 5580 | if (old_conn_state->crtc != crtc) |
| 5581 | continue; |
| 5582 | |
| 5583 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5584 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 5588 | static void intel_encoders_update_pipe(struct drm_crtc *crtc, |
| 5589 | struct intel_crtc_state *crtc_state, |
| 5590 | struct drm_atomic_state *old_state) |
| 5591 | { |
| 5592 | struct drm_connector_state *conn_state; |
| 5593 | struct drm_connector *conn; |
| 5594 | int i; |
| 5595 | |
| 5596 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
| 5597 | struct intel_encoder *encoder = |
| 5598 | to_intel_encoder(conn_state->best_encoder); |
| 5599 | |
| 5600 | if (conn_state->crtc != crtc) |
| 5601 | continue; |
| 5602 | |
| 5603 | if (encoder->update_pipe) |
| 5604 | encoder->update_pipe(encoder, crtc_state, conn_state); |
| 5605 | } |
| 5606 | } |
| 5607 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5608 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5609 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5610 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5611 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5612 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5613 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5614 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5615 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5616 | struct intel_atomic_state *old_intel_state = |
| 5617 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5618 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5619 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5620 | return; |
| 5621 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5622 | /* |
| 5623 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5624 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5625 | * |
| 5626 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5627 | * between eDP port A enable and vdd enable. Also PCH port |
| 5628 | * enable seems to result in the occasional CPU pipe underrun. |
| 5629 | * |
| 5630 | * Spurious PCH underruns also occur during PCH enabling. |
| 5631 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5632 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5633 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5634 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5635 | if (pipe_config->has_pch_encoder) |
| 5636 | intel_prepare_shared_dpll(pipe_config); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5637 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5638 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5639 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5640 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5641 | intel_set_pipe_timings(pipe_config); |
| 5642 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5643 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5644 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5645 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5646 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5647 | } |
| 5648 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5649 | ironlake_set_pipeconf(pipe_config); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5650 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5651 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5652 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5653 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5654 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5655 | if (pipe_config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5656 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5657 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5658 | * enabling. */ |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 5659 | ironlake_fdi_pll_enable(pipe_config); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5660 | } else { |
| 5661 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5662 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5663 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5664 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5665 | ironlake_pfit_enable(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5666 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5667 | /* |
| 5668 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5669 | * clocks enabled |
| 5670 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5671 | intel_color_load_luts(pipe_config); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5672 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5673 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5674 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5675 | intel_enable_pipe(pipe_config); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5676 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5677 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5678 | ironlake_pch_enable(old_intel_state, pipe_config); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5679 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5680 | assert_vblank_disabled(crtc); |
| 5681 | drm_crtc_vblank_on(crtc); |
| 5682 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5683 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5684 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5685 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5686 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5687 | |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5688 | /* |
| 5689 | * Must wait for vblank to avoid spurious PCH FIFO underruns. |
| 5690 | * And a second vblank wait is needed at least on ILK with |
| 5691 | * some interlaced HDMI modes. Let's do the double wait always |
| 5692 | * in case there are more corner cases we don't know about. |
| 5693 | */ |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5694 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5695 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | ea80a66 | 2018-05-24 22:04:05 +0300 | [diff] [blame] | 5696 | intel_wait_for_vblank(dev_priv, pipe); |
| 5697 | } |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5698 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5699 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5700 | } |
| 5701 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5702 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5703 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5704 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5705 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5706 | } |
| 5707 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5708 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
| 5709 | enum pipe pipe, bool apply) |
| 5710 | { |
| 5711 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); |
| 5712 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; |
| 5713 | |
| 5714 | if (apply) |
| 5715 | val |= mask; |
| 5716 | else |
| 5717 | val &= ~mask; |
| 5718 | |
| 5719 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); |
| 5720 | } |
| 5721 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5722 | static void icl_pipe_mbus_enable(struct intel_crtc *crtc) |
| 5723 | { |
| 5724 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5725 | enum pipe pipe = crtc->pipe; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 5726 | u32 val; |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5727 | |
Rodrigo Vivi | 443d5e3 | 2018-10-04 08:18:14 -0700 | [diff] [blame] | 5728 | val = MBUS_DBOX_A_CREDIT(2); |
| 5729 | val |= MBUS_DBOX_BW_CREDIT(1); |
| 5730 | val |= MBUS_DBOX_B_CREDIT(8); |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5731 | |
| 5732 | I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val); |
| 5733 | } |
| 5734 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5735 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5736 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5737 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5738 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5739 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5740 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5741 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5742 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5743 | struct intel_atomic_state *old_intel_state = |
| 5744 | to_intel_atomic_state(old_state); |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5745 | bool psl_clkgate_wa; |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5746 | u32 pipe_chicken; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5747 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5748 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5749 | return; |
| 5750 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5751 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5752 | |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 5753 | if (pipe_config->shared_dpll) |
| 5754 | intel_enable_shared_dpll(pipe_config); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5755 | |
Paulo Zanoni | c8af527 | 2018-05-02 14:58:51 -0700 | [diff] [blame] | 5756 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
| 5757 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5758 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5759 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5760 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5761 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5762 | intel_set_pipe_timings(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5763 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 5764 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5765 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5766 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5767 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5768 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5769 | pipe_config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5772 | if (pipe_config->has_pch_encoder) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 5773 | intel_cpu_transcoder_set_m_n(pipe_config, |
| 5774 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5775 | } |
| 5776 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5777 | if (!transcoder_is_dsi(cpu_transcoder)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5778 | haswell_set_pipeconf(pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5779 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 5780 | haswell_set_pipemisc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5781 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5782 | intel_color_set_csc(pipe_config); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5783 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5784 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5785 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5786 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
| 5787 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5788 | pipe_config->pch_pfit.enabled; |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5789 | if (psl_clkgate_wa) |
| 5790 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); |
| 5791 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5792 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5793 | skylake_pfit_enable(pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5794 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5795 | ironlake_pfit_enable(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5796 | |
| 5797 | /* |
| 5798 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5799 | * clocks enabled |
| 5800 | */ |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 5801 | intel_color_load_luts(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5802 | |
Vandita Kulkarni | e16a375 | 2018-06-21 20:43:56 +0530 | [diff] [blame] | 5803 | /* |
| 5804 | * Display WA #1153: enable hardware to bypass the alpha math |
| 5805 | * and rounding for per-pixel values 00 and 0xff |
| 5806 | */ |
| 5807 | if (INTEL_GEN(dev_priv) >= 11) { |
| 5808 | pipe_chicken = I915_READ(PIPE_CHICKEN(pipe)); |
| 5809 | if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN)) |
| 5810 | I915_WRITE_FW(PIPE_CHICKEN(pipe), |
| 5811 | pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN); |
| 5812 | } |
| 5813 | |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5814 | intel_ddi_set_pipe_settings(pipe_config); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5815 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ander Conselvan de Oliveira | 3dc38ee | 2017-03-02 14:58:56 +0200 | [diff] [blame] | 5816 | intel_ddi_enable_transcoder_func(pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5817 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5818 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5819 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5820 | |
Mahesh Kumar | c3cc39c | 2018-02-05 15:21:31 -0200 | [diff] [blame] | 5821 | if (INTEL_GEN(dev_priv) >= 11) |
| 5822 | icl_pipe_mbus_enable(intel_crtc); |
| 5823 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5824 | /* 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] | 5825 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5826 | intel_enable_pipe(pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5827 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5828 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 5829 | lpt_pch_enable(old_intel_state, pipe_config); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5830 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5831 | 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] | 5832 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5833 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5834 | assert_vblank_disabled(crtc); |
| 5835 | drm_crtc_vblank_on(crtc); |
| 5836 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5837 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5838 | |
Imre Deak | ed69cd4 | 2017-10-02 10:55:57 +0300 | [diff] [blame] | 5839 | if (psl_clkgate_wa) { |
| 5840 | intel_wait_for_vblank(dev_priv, pipe); |
| 5841 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
| 5842 | } |
| 5843 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5844 | /* If we change the relative order between pipe/planes enabling, we need |
| 5845 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5846 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5847 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5848 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5849 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5850 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5851 | } |
| 5852 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5853 | 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] | 5854 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5855 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5856 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5857 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5858 | |
| 5859 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5860 | * 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] | 5861 | if (old_crtc_state->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5862 | I915_WRITE(PF_CTL(pipe), 0); |
| 5863 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5864 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5865 | } |
| 5866 | } |
| 5867 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5868 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5869 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5870 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5871 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5872 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5873 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5874 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5875 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5876 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5877 | /* |
| 5878 | * Sometimes spurious CPU pipe underruns happen when the |
| 5879 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 5880 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 5881 | */ |
Ville Syrjälä | 2b5b631 | 2018-05-24 22:04:06 +0300 | [diff] [blame] | 5882 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5883 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5884 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5885 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5886 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5887 | drm_crtc_vblank_off(crtc); |
| 5888 | assert_vblank_disabled(crtc); |
| 5889 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5890 | intel_disable_pipe(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5891 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5892 | ironlake_pfit_disable(old_crtc_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5893 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5894 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 5895 | ironlake_fdi_disable(crtc); |
| 5896 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5897 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5898 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 5899 | if (old_crtc_state->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5900 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5901 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5902 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5903 | i915_reg_t reg; |
| 5904 | u32 temp; |
| 5905 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5906 | /* disable TRANS_DP_CTL */ |
| 5907 | reg = TRANS_DP_CTL(pipe); |
| 5908 | temp = I915_READ(reg); |
| 5909 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5910 | TRANS_DP_PORT_SEL_MASK); |
| 5911 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5912 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5913 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5914 | /* disable DPLL_SEL */ |
| 5915 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5916 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5917 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5918 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5919 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5920 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5921 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5922 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5923 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5924 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5925 | } |
| 5926 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5927 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5928 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5929 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5930 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5931 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5932 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5933 | enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5934 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5935 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5936 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5937 | drm_crtc_vblank_off(crtc); |
| 5938 | assert_vblank_disabled(crtc); |
| 5939 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5940 | /* 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] | 5941 | if (!transcoder_is_dsi(cpu_transcoder)) |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 5942 | intel_disable_pipe(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5943 | |
Imre Deak | 24a2817 | 2018-06-13 20:07:06 +0300 | [diff] [blame] | 5944 | if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) |
| 5945 | intel_ddi_set_vc_payload_alloc(old_crtc_state, false); |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5946 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5947 | if (!transcoder_is_dsi(cpu_transcoder)) |
Clint Taylor | 90c3e21 | 2018-07-10 13:02:05 -0700 | [diff] [blame] | 5948 | intel_ddi_disable_transcoder_func(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5949 | |
Manasi Navare | a600622 | 2018-11-28 12:26:23 -0800 | [diff] [blame] | 5950 | intel_dsc_disable(old_crtc_state); |
| 5951 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5952 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5953 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5954 | else |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5955 | ironlake_pfit_disable(old_crtc_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5956 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5957 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 5958 | |
Imre Deak | bdaa29b | 2018-11-01 16:04:24 +0200 | [diff] [blame] | 5959 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5960 | } |
| 5961 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5962 | static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5963 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5964 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 5965 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5966 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5967 | if (!crtc_state->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5968 | return; |
| 5969 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5970 | /* |
| 5971 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5972 | * according to register description and PRM. |
| 5973 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5974 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5975 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5976 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 5977 | I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios); |
| 5978 | I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5979 | |
| 5980 | /* Border color in case we don't scale up to the full screen. Black by |
| 5981 | * default, change to something else for debugging. */ |
| 5982 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5983 | } |
| 5984 | |
Mahesh Kumar | 176597a | 2018-10-04 14:20:43 +0530 | [diff] [blame] | 5985 | bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port) |
| 5986 | { |
| 5987 | if (port == PORT_NONE) |
| 5988 | return false; |
| 5989 | |
| 5990 | if (IS_ICELAKE(dev_priv)) |
| 5991 | return port <= PORT_B; |
| 5992 | |
| 5993 | return false; |
| 5994 | } |
| 5995 | |
Paulo Zanoni | ac213c1 | 2018-05-21 17:25:37 -0700 | [diff] [blame] | 5996 | bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port) |
| 5997 | { |
| 5998 | if (IS_ICELAKE(dev_priv)) |
| 5999 | return port >= PORT_C && port <= PORT_F; |
| 6000 | |
| 6001 | return false; |
| 6002 | } |
| 6003 | |
| 6004 | enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) |
| 6005 | { |
| 6006 | if (!intel_port_is_tc(dev_priv, port)) |
| 6007 | return PORT_TC_NONE; |
| 6008 | |
| 6009 | return port - PORT_C; |
| 6010 | } |
| 6011 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6012 | 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] | 6013 | { |
| 6014 | switch (port) { |
| 6015 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6016 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6017 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6018 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6019 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6020 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6021 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6022 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 6023 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 6024 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 6025 | case PORT_F: |
| 6026 | return POWER_DOMAIN_PORT_DDI_F_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6027 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 6028 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 6029 | return POWER_DOMAIN_PORT_OTHER; |
| 6030 | } |
| 6031 | } |
| 6032 | |
Imre Deak | 337837a | 2018-11-01 16:04:23 +0200 | [diff] [blame] | 6033 | enum intel_display_power_domain |
| 6034 | intel_aux_power_domain(struct intel_digital_port *dig_port) |
| 6035 | { |
| 6036 | switch (dig_port->aux_ch) { |
| 6037 | case AUX_CH_A: |
| 6038 | return POWER_DOMAIN_AUX_A; |
| 6039 | case AUX_CH_B: |
| 6040 | return POWER_DOMAIN_AUX_B; |
| 6041 | case AUX_CH_C: |
| 6042 | return POWER_DOMAIN_AUX_C; |
| 6043 | case AUX_CH_D: |
| 6044 | return POWER_DOMAIN_AUX_D; |
| 6045 | case AUX_CH_E: |
| 6046 | return POWER_DOMAIN_AUX_E; |
| 6047 | case AUX_CH_F: |
| 6048 | return POWER_DOMAIN_AUX_F; |
| 6049 | default: |
| 6050 | MISSING_CASE(dig_port->aux_ch); |
| 6051 | return POWER_DOMAIN_AUX_A; |
| 6052 | } |
| 6053 | } |
| 6054 | |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6055 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
| 6056 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6057 | { |
| 6058 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6059 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6060 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6061 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6062 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6063 | u64 mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6064 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6065 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6066 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6067 | return 0; |
| 6068 | |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6069 | mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe)); |
| 6070 | mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6071 | if (crtc_state->pch_pfit.enabled || |
| 6072 | crtc_state->pch_pfit.force_thru) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6073 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6074 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6075 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 6076 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 6077 | |
Ander Conselvan de Oliveira | 79f255a | 2017-02-22 08:34:27 +0200 | [diff] [blame] | 6078 | mask |= BIT_ULL(intel_encoder->power_domain); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6079 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 6080 | |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6081 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
Imre Deak | 17bd6e6 | 2018-01-09 14:20:40 +0200 | [diff] [blame] | 6082 | mask |= BIT_ULL(POWER_DOMAIN_AUDIO); |
Maarten Lankhorst | 37255d8 | 2016-12-15 15:29:43 +0100 | [diff] [blame] | 6083 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6084 | if (crtc_state->shared_dpll) |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6085 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 6086 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 6087 | return mask; |
| 6088 | } |
| 6089 | |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6090 | static u64 |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6091 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 6092 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6093 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6094 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6095 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6096 | enum intel_display_power_domain domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 6097 | u64 domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6098 | |
| 6099 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 6100 | intel_crtc->enabled_power_domains = new_domains = |
| 6101 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6102 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6103 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6104 | |
| 6105 | for_each_power_domain(domain, domains) |
| 6106 | intel_display_power_get(dev_priv, domain); |
| 6107 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6108 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | 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] | 6112 | u64 domains) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6113 | { |
| 6114 | enum intel_display_power_domain domain; |
| 6115 | |
| 6116 | for_each_power_domain(domain, domains) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 6117 | intel_display_power_put_unchecked(dev_priv, domain); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 6118 | } |
| 6119 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6120 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6121 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6122 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6123 | struct intel_atomic_state *old_intel_state = |
| 6124 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6125 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6126 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6127 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6128 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6129 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6130 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6131 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6132 | return; |
| 6133 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6134 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6135 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6136 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6137 | intel_set_pipe_timings(pipe_config); |
| 6138 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6139 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6140 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6141 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6142 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6143 | } |
| 6144 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6145 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6146 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6147 | intel_color_set_csc(pipe_config); |
P Raviraj Sitaram | c59d2da | 2018-09-10 19:57:14 +0530 | [diff] [blame] | 6148 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6149 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6150 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6151 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6152 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6153 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6154 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6155 | if (IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6156 | chv_prepare_pll(intel_crtc, pipe_config); |
| 6157 | chv_enable_pll(intel_crtc, pipe_config); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6158 | } else { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6159 | vlv_prepare_pll(intel_crtc, pipe_config); |
| 6160 | vlv_enable_pll(intel_crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6161 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6162 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6163 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6164 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6165 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6166 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6167 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6168 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6169 | dev_priv->display.initial_watermarks(old_intel_state, |
| 6170 | pipe_config); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6171 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6172 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6173 | assert_vblank_disabled(crtc); |
| 6174 | drm_crtc_vblank_on(crtc); |
| 6175 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6176 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6177 | } |
| 6178 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6179 | 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] | 6180 | { |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6181 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6182 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6183 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6184 | I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0); |
| 6185 | I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6186 | } |
| 6187 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6188 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6189 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6190 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6191 | struct intel_atomic_state *old_intel_state = |
| 6192 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6193 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6194 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6195 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6196 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6197 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6198 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6199 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6200 | return; |
| 6201 | |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6202 | i9xx_set_pll_dividers(pipe_config); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6203 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6204 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6205 | intel_dp_set_m_n(pipe_config, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6206 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 6207 | intel_set_pipe_timings(pipe_config); |
| 6208 | intel_set_pipe_src_size(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6209 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 6210 | i9xx_set_pipeconf(pipe_config); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6211 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6212 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6213 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6214 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6215 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6216 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6217 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6218 | |
Ville Syrjälä | 939994d | 2017-09-13 17:08:56 +0300 | [diff] [blame] | 6219 | i9xx_enable_pll(intel_crtc, pipe_config); |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6220 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6221 | i9xx_pfit_enable(pipe_config); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6222 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 6223 | intel_color_load_luts(pipe_config); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6224 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6225 | if (dev_priv->display.initial_watermarks != NULL) |
| 6226 | dev_priv->display.initial_watermarks(old_intel_state, |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6227 | pipe_config); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6228 | else |
| 6229 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6230 | intel_enable_pipe(pipe_config); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6231 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6232 | assert_vblank_disabled(crtc); |
| 6233 | drm_crtc_vblank_on(crtc); |
| 6234 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6235 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6236 | } |
| 6237 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6238 | 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] | 6239 | { |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6240 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 6241 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6242 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6243 | if (!old_crtc_state->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6244 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6245 | |
| 6246 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6247 | |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 6248 | DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n", |
| 6249 | I915_READ(PFIT_CONTROL)); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6250 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6251 | } |
| 6252 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6253 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6254 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6255 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6256 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6257 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6258 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6259 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6260 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6261 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6262 | /* |
| 6263 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6264 | * wait for planes to fully turn off before disabling the pipe. |
| 6265 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6266 | if (IS_GEN(dev_priv, 2)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6267 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6268 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6269 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6270 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6271 | drm_crtc_vblank_off(crtc); |
| 6272 | assert_vblank_disabled(crtc); |
| 6273 | |
Ville Syrjälä | 4972f70 | 2017-11-29 17:37:32 +0200 | [diff] [blame] | 6274 | intel_disable_pipe(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6275 | |
Maarten Lankhorst | b256271 | 2018-10-04 11:45:53 +0200 | [diff] [blame] | 6276 | i9xx_pfit_disable(old_crtc_state); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6277 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6278 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6279 | |
Maarten Lankhorst | 6f40563 | 2018-10-04 11:46:04 +0200 | [diff] [blame] | 6280 | if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6281 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6282 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6283 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6284 | vlv_disable_pll(dev_priv, pipe); |
| 6285 | else |
Maarten Lankhorst | b2354c7 | 2018-10-04 11:45:57 +0200 | [diff] [blame] | 6286 | i9xx_disable_pll(old_crtc_state); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6287 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6288 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6289 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6290 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6291 | if (!IS_GEN(dev_priv, 2)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6292 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 6293 | |
| 6294 | if (!dev_priv->display.initial_watermarks) |
| 6295 | intel_update_watermarks(intel_crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 6296 | |
| 6297 | /* clock the pipe down to 640x480@60 to potentially save power */ |
| 6298 | if (IS_I830(dev_priv)) |
| 6299 | i830_enable_pipe(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6302 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
| 6303 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6304 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6305 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6306 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6307 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6308 | enum intel_display_power_domain domain; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6309 | struct intel_plane *plane; |
Ander Conselvan de Oliveira | d2d1501 | 2017-02-13 16:57:33 +0200 | [diff] [blame] | 6310 | u64 domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6311 | struct drm_atomic_state *state; |
| 6312 | struct intel_crtc_state *crtc_state; |
| 6313 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6314 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6315 | if (!intel_crtc->active) |
| 6316 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6317 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6318 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
| 6319 | const struct intel_plane_state *plane_state = |
| 6320 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6321 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 6322 | if (plane_state->base.visible) |
| 6323 | intel_plane_disable_noatomic(intel_crtc, plane); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6324 | } |
| 6325 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6326 | state = drm_atomic_state_alloc(crtc->dev); |
Ander Conselvan de Oliveira | 31bb2ef | 2017-01-20 16:28:45 +0200 | [diff] [blame] | 6327 | if (!state) { |
| 6328 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", |
| 6329 | crtc->base.id, crtc->name); |
| 6330 | return; |
| 6331 | } |
| 6332 | |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 6333 | state->acquire_ctx = ctx; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6334 | |
| 6335 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6336 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6337 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6338 | |
| 6339 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6340 | |
| 6341 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6342 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6343 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6344 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6345 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6346 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6347 | |
| 6348 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6349 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6350 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6351 | crtc->enabled = false; |
| 6352 | crtc->state->connector_mask = 0; |
| 6353 | crtc->state->encoder_mask = 0; |
| 6354 | |
| 6355 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6356 | encoder->base.crtc = NULL; |
| 6357 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6358 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6359 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 6360 | intel_disable_shared_dpll(to_intel_crtc_state(crtc->state)); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6361 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6362 | domains = intel_crtc->enabled_power_domains; |
| 6363 | for_each_power_domain(domain, domains) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 6364 | intel_display_power_put_unchecked(dev_priv, domain); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6365 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6366 | |
| 6367 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 6368 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 6369 | dev_priv->min_voltage_level[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6370 | } |
| 6371 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6372 | /* |
| 6373 | * turn all crtc's off, but do not adjust state |
| 6374 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6375 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6376 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6377 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6378 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6379 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6380 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6381 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6382 | state = drm_atomic_helper_suspend(dev); |
| 6383 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6384 | if (ret) |
| 6385 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6386 | else |
| 6387 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6388 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6389 | } |
| 6390 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6391 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6392 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6393 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6394 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6395 | drm_encoder_cleanup(encoder); |
| 6396 | kfree(intel_encoder); |
| 6397 | } |
| 6398 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6399 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6400 | * internal consistency). */ |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6401 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
| 6402 | struct drm_connector_state *conn_state) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6403 | { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6404 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6405 | |
| 6406 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6407 | connector->base.base.id, |
| 6408 | connector->base.name); |
| 6409 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6410 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6411 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6412 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6413 | I915_STATE_WARN(!crtc_state, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6414 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6415 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6416 | if (!crtc_state) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6417 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6418 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6419 | I915_STATE_WARN(!crtc_state->active, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6420 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6421 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6422 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6423 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6424 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6425 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6426 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6427 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6428 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6429 | "attached encoder crtc differs from connector crtc\n"); |
| 6430 | } else { |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6431 | I915_STATE_WARN(crtc_state && crtc_state->active, |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6432 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 6433 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6434 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6435 | } |
| 6436 | } |
| 6437 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6438 | 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] | 6439 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6440 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6441 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6442 | |
| 6443 | return 0; |
| 6444 | } |
| 6445 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6446 | 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] | 6447 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6448 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6449 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6450 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6451 | struct intel_crtc *other_crtc; |
| 6452 | struct intel_crtc_state *other_crtc_state; |
| 6453 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6454 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6455 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6456 | if (pipe_config->fdi_lanes > 4) { |
| 6457 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6458 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6459 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6460 | } |
| 6461 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 6462 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6463 | if (pipe_config->fdi_lanes > 2) { |
| 6464 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6465 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6466 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6467 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6468 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6469 | } |
| 6470 | } |
| 6471 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 6472 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6473 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6474 | |
| 6475 | /* Ivybridge 3 pipe is really complicated */ |
| 6476 | switch (pipe) { |
| 6477 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6478 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6479 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6480 | if (pipe_config->fdi_lanes <= 2) |
| 6481 | return 0; |
| 6482 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6483 | 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] | 6484 | other_crtc_state = |
| 6485 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6486 | if (IS_ERR(other_crtc_state)) |
| 6487 | return PTR_ERR(other_crtc_state); |
| 6488 | |
| 6489 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6490 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6491 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6492 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6493 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6494 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6495 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6496 | if (pipe_config->fdi_lanes > 2) { |
| 6497 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6498 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6499 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6500 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6501 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 6502 | 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] | 6503 | other_crtc_state = |
| 6504 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6505 | if (IS_ERR(other_crtc_state)) |
| 6506 | return PTR_ERR(other_crtc_state); |
| 6507 | |
| 6508 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6509 | 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] | 6510 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6511 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6512 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6513 | default: |
| 6514 | BUG(); |
| 6515 | } |
| 6516 | } |
| 6517 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6518 | #define RETRY 1 |
| 6519 | 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] | 6520 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6521 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6522 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6523 | 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] | 6524 | int lane, link_bw, fdi_dotclock, ret; |
| 6525 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6526 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6527 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6528 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6529 | * each output octet as 10 bits. The actual frequency |
| 6530 | * is stored as a divider into a 100MHz clock, and the |
| 6531 | * mode pixel clock is stored in units of 1KHz. |
| 6532 | * Hence the bw of each lane in terms of the mode signal |
| 6533 | * is: |
| 6534 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6535 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6536 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6537 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6538 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6539 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6540 | pipe_config->pipe_bpp); |
| 6541 | |
| 6542 | pipe_config->fdi_lanes = lane; |
| 6543 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6544 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6545 | link_bw, &pipe_config->fdi_m_n, false); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6546 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6547 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 6548 | if (ret == -EDEADLK) |
| 6549 | return ret; |
| 6550 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6551 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6552 | pipe_config->pipe_bpp -= 2*3; |
| 6553 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6554 | pipe_config->pipe_bpp); |
| 6555 | needs_recompute = true; |
| 6556 | pipe_config->bw_constrained = true; |
| 6557 | |
| 6558 | goto retry; |
| 6559 | } |
| 6560 | |
| 6561 | if (needs_recompute) |
| 6562 | return RETRY; |
| 6563 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6564 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6565 | } |
| 6566 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6567 | 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] | 6568 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6569 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6570 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6571 | |
| 6572 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 6573 | if (!hsw_crtc_supports_ips(crtc)) |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 6574 | return false; |
| 6575 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6576 | if (!i915_modparams.enable_ips) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6577 | return false; |
| 6578 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6579 | if (crtc_state->pipe_bpp > 24) |
| 6580 | return false; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6581 | |
| 6582 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6583 | * We compare against max which means we must take |
| 6584 | * the increased cdclk requirement into account when |
| 6585 | * calculating the new cdclk. |
| 6586 | * |
| 6587 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6588 | */ |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6589 | if (IS_BROADWELL(dev_priv) && |
| 6590 | crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100) |
| 6591 | return false; |
| 6592 | |
| 6593 | return true; |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6594 | } |
| 6595 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6596 | static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6597 | { |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6598 | struct drm_i915_private *dev_priv = |
| 6599 | to_i915(crtc_state->base.crtc->dev); |
| 6600 | struct intel_atomic_state *intel_state = |
| 6601 | to_intel_atomic_state(crtc_state->base.state); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6602 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6603 | if (!hsw_crtc_state_ips_capable(crtc_state)) |
| 6604 | return false; |
| 6605 | |
| 6606 | if (crtc_state->ips_force_disable) |
| 6607 | return false; |
| 6608 | |
Maarten Lankhorst | adbe5c5 | 2017-11-22 19:39:06 +0100 | [diff] [blame] | 6609 | /* IPS should be fine as long as at least one plane is enabled. */ |
| 6610 | if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR))) |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 6611 | return false; |
| 6612 | |
| 6613 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 6614 | if (IS_BROADWELL(dev_priv) && |
| 6615 | crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100) |
| 6616 | return false; |
| 6617 | |
| 6618 | return true; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6619 | } |
| 6620 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6621 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6622 | { |
| 6623 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6624 | |
| 6625 | /* GDG double wide on either pipe, otherwise pipe A only */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 6626 | return INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6627 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6628 | } |
| 6629 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6630 | 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] | 6631 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6632 | u32 pixel_rate; |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6633 | |
| 6634 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; |
| 6635 | |
| 6636 | /* |
| 6637 | * We only use IF-ID interlacing. If we ever use |
| 6638 | * PF-ID we'll need to adjust the pixel_rate here. |
| 6639 | */ |
| 6640 | |
| 6641 | if (pipe_config->pch_pfit.enabled) { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6642 | u64 pipe_w, pipe_h, pfit_w, pfit_h; |
| 6643 | u32 pfit_size = pipe_config->pch_pfit.size; |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6644 | |
| 6645 | pipe_w = pipe_config->pipe_src_w; |
| 6646 | pipe_h = pipe_config->pipe_src_h; |
| 6647 | |
| 6648 | pfit_w = (pfit_size >> 16) & 0xFFFF; |
| 6649 | pfit_h = pfit_size & 0xFFFF; |
| 6650 | if (pipe_w < pfit_w) |
| 6651 | pipe_w = pfit_w; |
| 6652 | if (pipe_h < pfit_h) |
| 6653 | pipe_h = pfit_h; |
| 6654 | |
| 6655 | if (WARN_ON(!pfit_w || !pfit_h)) |
| 6656 | return pixel_rate; |
| 6657 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6658 | pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h, |
Ville Syrjälä | ceb9932 | 2017-01-20 20:22:05 +0200 | [diff] [blame] | 6659 | pfit_w * pfit_h); |
| 6660 | } |
| 6661 | |
| 6662 | return pixel_rate; |
| 6663 | } |
| 6664 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6665 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
| 6666 | { |
| 6667 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 6668 | |
| 6669 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 6670 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ |
| 6671 | crtc_state->pixel_rate = |
| 6672 | crtc_state->base.adjusted_mode.crtc_clock; |
| 6673 | else |
| 6674 | crtc_state->pixel_rate = |
| 6675 | ilk_pipe_pixel_rate(crtc_state); |
| 6676 | } |
| 6677 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6678 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6679 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6680 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6681 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6682 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6683 | 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] | 6684 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6685 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6686 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6687 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6688 | |
| 6689 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6690 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6691 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6692 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6693 | if (intel_crtc_supports_double_wide(crtc) && |
| 6694 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6695 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6696 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6697 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6698 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6699 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 6700 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6701 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6702 | adjusted_mode->crtc_clock, clock_limit, |
| 6703 | yesno(pipe_config->double_wide)); |
| 6704 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6705 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6706 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 6707 | if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 6708 | pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) && |
| 6709 | pipe_config->base.ctm) { |
Shashank Sharma | 25edf91 | 2017-07-21 20:55:07 +0530 | [diff] [blame] | 6710 | /* |
| 6711 | * There is only one pipe CSC unit per pipe, and we need that |
| 6712 | * for output conversion from RGB->YCBCR. So if CTM is already |
| 6713 | * applied we can't support YCBCR420 output. |
| 6714 | */ |
| 6715 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); |
| 6716 | return -EINVAL; |
| 6717 | } |
| 6718 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6719 | /* |
| 6720 | * Pipe horizontal size must be even in: |
| 6721 | * - DVO ganged mode |
| 6722 | * - LVDS dual channel mode |
| 6723 | * - Double wide pipe |
| 6724 | */ |
Ville Syrjälä | 0574bd8 | 2017-11-23 21:04:48 +0200 | [diff] [blame] | 6725 | if (pipe_config->pipe_src_w & 1) { |
| 6726 | if (pipe_config->double_wide) { |
| 6727 | DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n"); |
| 6728 | return -EINVAL; |
| 6729 | } |
| 6730 | |
| 6731 | if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
| 6732 | intel_is_dual_link_lvds(dev)) { |
| 6733 | DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n"); |
| 6734 | return -EINVAL; |
| 6735 | } |
| 6736 | } |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6737 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6738 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6739 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6740 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 6741 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6742 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6743 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6744 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 6745 | intel_crtc_compute_pixel_rate(pipe_config); |
| 6746 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6747 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6748 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6749 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6750 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6751 | } |
| 6752 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6753 | static void |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6754 | intel_reduce_m_n_ratio(u32 *num, u32 *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6755 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6756 | while (*num > DATA_LINK_M_N_MASK || |
| 6757 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6758 | *num >>= 1; |
| 6759 | *den >>= 1; |
| 6760 | } |
| 6761 | } |
| 6762 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6763 | static void compute_m_n(unsigned int m, unsigned int n, |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6764 | u32 *ret_m, u32 *ret_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6765 | bool constant_n) |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6766 | { |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6767 | /* |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6768 | * Several DP dongles in particular seem to be fussy about |
| 6769 | * too large link M/N values. Give N value as 0x8000 that |
| 6770 | * should be acceptable by specific devices. 0x8000 is the |
| 6771 | * specified fixed N value for asynchronous clock mode, |
| 6772 | * which the devices expect also in synchronous clock mode. |
Jani Nikula | 9a86cda | 2017-03-27 14:33:25 +0300 | [diff] [blame] | 6773 | */ |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6774 | if (constant_n) |
| 6775 | *ret_n = 0x8000; |
| 6776 | else |
| 6777 | *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] | 6778 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6779 | *ret_m = div_u64((u64)m * *ret_n, n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6780 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6781 | } |
| 6782 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6783 | void |
Manasi Navare | a4a1577 | 2018-11-28 13:36:21 -0800 | [diff] [blame] | 6784 | intel_link_compute_m_n(u16 bits_per_pixel, int nlanes, |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6785 | int pixel_clock, int link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6786 | struct intel_link_m_n *m_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6787 | bool constant_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6788 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6789 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6790 | |
| 6791 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6792 | link_clock * nlanes * 8, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6793 | &m_n->gmch_m, &m_n->gmch_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6794 | constant_n); |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6795 | |
| 6796 | compute_m_n(pixel_clock, link_clock, |
Jani Nikula | b31e85e | 2017-05-18 14:10:25 +0300 | [diff] [blame] | 6797 | &m_n->link_m, &m_n->link_n, |
Lee, Shawn C | 53ca2ed | 2018-09-11 23:22:50 -0700 | [diff] [blame] | 6798 | constant_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6799 | } |
| 6800 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6801 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6802 | { |
Michal Wajdeczko | 4f044a8 | 2017-09-19 19:38:44 +0000 | [diff] [blame] | 6803 | if (i915_modparams.panel_use_ssc >= 0) |
| 6804 | return i915_modparams.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6805 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6806 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6807 | } |
| 6808 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6809 | static u32 pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6810 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6811 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6812 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6813 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 6814 | static u32 i9xx_dpll_compute_fp(struct dpll *dpll) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6815 | { |
| 6816 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6819 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6820 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 6821 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6822 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6823 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6824 | u32 fp, fp2 = 0; |
| 6825 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 6826 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6827 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6828 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6829 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6830 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6831 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6832 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6833 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6834 | } |
| 6835 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6836 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6837 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 6838 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6839 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6840 | crtc_state->dpll_hw_state.fp1 = fp2; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6841 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6842 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6843 | } |
| 6844 | } |
| 6845 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6846 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6847 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6848 | { |
| 6849 | u32 reg_val; |
| 6850 | |
| 6851 | /* |
| 6852 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6853 | * and set it to a reasonable value instead. |
| 6854 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6855 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6856 | reg_val &= 0xffffff00; |
| 6857 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6858 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6859 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6860 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Imre Deak | ed58570 | 2017-05-10 12:21:47 +0300 | [diff] [blame] | 6861 | reg_val &= 0x00ffffff; |
| 6862 | reg_val |= 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6863 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6864 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6865 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6866 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6867 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6868 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6869 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6870 | reg_val &= 0x00ffffff; |
| 6871 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6872 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6873 | } |
| 6874 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6875 | static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 6876 | const struct intel_link_m_n *m_n) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6877 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6878 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 6879 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6880 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6881 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6882 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6883 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6884 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6885 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6886 | } |
| 6887 | |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6888 | static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv, |
| 6889 | enum transcoder transcoder) |
| 6890 | { |
| 6891 | if (IS_HASWELL(dev_priv)) |
| 6892 | return transcoder == TRANSCODER_EDP; |
| 6893 | |
| 6894 | /* |
| 6895 | * Strictly speaking some registers are available before |
| 6896 | * gen7, but we only support DRRS on gen7+ |
| 6897 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 6898 | return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6899 | } |
| 6900 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6901 | static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state, |
| 6902 | const struct intel_link_m_n *m_n, |
| 6903 | const struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6904 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6905 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6906 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6907 | enum pipe pipe = crtc->pipe; |
| 6908 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6909 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 6910 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6911 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6912 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6913 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6914 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6915 | /* |
| 6916 | * M2_N2 registers are set only if DRRS is supported |
| 6917 | * (to make sure the registers are not unnecessarily accessed). |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6918 | */ |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 6919 | if (m2_n2 && crtc_state->has_drrs && |
| 6920 | transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6921 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6922 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6923 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6924 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6925 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6926 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6927 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6928 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6929 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6930 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6931 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6932 | } |
| 6933 | } |
| 6934 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6935 | 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] | 6936 | { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6937 | 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] | 6938 | |
| 6939 | if (m_n == M1_N1) { |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6940 | dp_m_n = &crtc_state->dp_m_n; |
| 6941 | dp_m2_n2 = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6942 | } else if (m_n == M2_N2) { |
| 6943 | |
| 6944 | /* |
| 6945 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6946 | * needs to be programmed into M1_N1. |
| 6947 | */ |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6948 | dp_m_n = &crtc_state->dp_m2_n2; |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6949 | } else { |
| 6950 | DRM_ERROR("Unsupported divider value\n"); |
| 6951 | return; |
| 6952 | } |
| 6953 | |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6954 | if (crtc_state->has_pch_encoder) |
| 6955 | 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] | 6956 | else |
Maarten Lankhorst | 4c35475 | 2018-10-11 12:04:49 +0200 | [diff] [blame] | 6957 | 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] | 6958 | } |
| 6959 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 6960 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 6961 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6962 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6963 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6964 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6965 | if (crtc->pipe != PIPE_A) |
| 6966 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6967 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6968 | /* 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] | 6969 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6970 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 6971 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 6972 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6973 | pipe_config->dpll_hw_state.dpll_md = |
| 6974 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 6975 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6976 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6977 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 6978 | struct intel_crtc_state *pipe_config) |
| 6979 | { |
| 6980 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6981 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6982 | if (crtc->pipe != PIPE_A) |
| 6983 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6984 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6985 | /* 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] | 6986 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6987 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 6988 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 6989 | pipe_config->dpll_hw_state.dpll_md = |
| 6990 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6991 | } |
| 6992 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6993 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6994 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6995 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6996 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6997 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6998 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6999 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7000 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7001 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7002 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7003 | /* Enable Refclk */ |
| 7004 | I915_WRITE(DPLL(pipe), |
| 7005 | pipe_config->dpll_hw_state.dpll & |
| 7006 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 7007 | |
| 7008 | /* No need to actually set up the DPLL with DSI */ |
| 7009 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7010 | return; |
| 7011 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7012 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7013 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7014 | bestn = pipe_config->dpll.n; |
| 7015 | bestm1 = pipe_config->dpll.m1; |
| 7016 | bestm2 = pipe_config->dpll.m2; |
| 7017 | bestp1 = pipe_config->dpll.p1; |
| 7018 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7019 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7020 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7021 | |
| 7022 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7023 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7024 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7025 | |
| 7026 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7027 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7028 | |
| 7029 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7030 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7031 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7032 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7033 | |
| 7034 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7035 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7036 | |
| 7037 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7038 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7039 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7040 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7041 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7042 | |
| 7043 | /* |
| 7044 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7045 | * but we don't support that). |
| 7046 | * Note: don't use the DAC post divider as it seems unstable. |
| 7047 | */ |
| 7048 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7049 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7050 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7051 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7052 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7053 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7054 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7055 | if (pipe_config->port_clock == 162000 || |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7056 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) || |
| 7057 | intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7058 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7059 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7060 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7061 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7062 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7063 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7064 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7065 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7066 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7067 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7068 | 0x0df40000); |
| 7069 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7070 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7071 | 0x0df70000); |
| 7072 | } else { /* HDMI or VGA */ |
| 7073 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7074 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7075 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7076 | 0x0df70000); |
| 7077 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7078 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7079 | 0x0df40000); |
| 7080 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7081 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7082 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7083 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Maarten Lankhorst | 92d54b0 | 2018-10-11 12:04:50 +0200 | [diff] [blame] | 7084 | if (intel_crtc_has_dp_encoder(pipe_config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7085 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7086 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7087 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7088 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7089 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7090 | } |
| 7091 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7092 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7093 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7094 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7095 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7096 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7097 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7098 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7099 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7100 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7101 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7102 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7103 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7104 | /* Enable Refclk and SSC */ |
| 7105 | I915_WRITE(DPLL(pipe), |
| 7106 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 7107 | |
| 7108 | /* No need to actually set up the DPLL with DSI */ |
| 7109 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7110 | return; |
| 7111 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7112 | bestn = pipe_config->dpll.n; |
| 7113 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7114 | bestm1 = pipe_config->dpll.m1; |
| 7115 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7116 | bestp1 = pipe_config->dpll.p1; |
| 7117 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7118 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7119 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7120 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7121 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7122 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7123 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7124 | /* p1 and p2 divider */ |
| 7125 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7126 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7127 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7128 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7129 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7130 | |
| 7131 | /* Feedback post-divider - m2 */ |
| 7132 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7133 | |
| 7134 | /* Feedback refclk divider - n and m1 */ |
| 7135 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7136 | DPIO_CHV_M1_DIV_BY_2 | |
| 7137 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7138 | |
| 7139 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7140 | 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] | 7141 | |
| 7142 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7143 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7144 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7145 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7146 | if (bestm2_frac) |
| 7147 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7148 | 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] | 7149 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7150 | /* Program digital lock detect threshold */ |
| 7151 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7152 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7153 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7154 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7155 | if (!bestm2_frac) |
| 7156 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7157 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7158 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7159 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7160 | if (vco == 5400000) { |
| 7161 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7162 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7163 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7164 | tribuf_calcntr = 0x9; |
| 7165 | } else if (vco <= 6200000) { |
| 7166 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7167 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7168 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7169 | tribuf_calcntr = 0x9; |
| 7170 | } else if (vco <= 6480000) { |
| 7171 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7172 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7173 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7174 | tribuf_calcntr = 0x8; |
| 7175 | } else { |
| 7176 | /* Not supported. Apply the same limits as in the max case */ |
| 7177 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7178 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7179 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7180 | tribuf_calcntr = 0; |
| 7181 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7182 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7183 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7184 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7185 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7186 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7187 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7188 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7189 | /* AFC Recal */ |
| 7190 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7191 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7192 | DPIO_AFC_RECAL); |
| 7193 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7194 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7195 | } |
| 7196 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7197 | /** |
| 7198 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7199 | * @dev_priv: i915 private structure |
| 7200 | * @pipe: pipe PLL to enable |
| 7201 | * @dpll: PLL configuration |
| 7202 | * |
| 7203 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7204 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7205 | * be enabled. |
| 7206 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7207 | 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] | 7208 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7209 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7210 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7211 | struct intel_crtc_state *pipe_config; |
| 7212 | |
| 7213 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7214 | if (!pipe_config) |
| 7215 | return -ENOMEM; |
| 7216 | |
| 7217 | pipe_config->base.crtc = &crtc->base; |
| 7218 | pipe_config->pixel_multiplier = 1; |
| 7219 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7220 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7221 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7222 | chv_compute_dpll(crtc, pipe_config); |
| 7223 | chv_prepare_pll(crtc, pipe_config); |
| 7224 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7225 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7226 | vlv_compute_dpll(crtc, pipe_config); |
| 7227 | vlv_prepare_pll(crtc, pipe_config); |
| 7228 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7229 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7230 | |
| 7231 | kfree(pipe_config); |
| 7232 | |
| 7233 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7234 | } |
| 7235 | |
| 7236 | /** |
| 7237 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7238 | * @dev_priv: i915 private structure |
| 7239 | * @pipe: pipe PLL to disable |
| 7240 | * |
| 7241 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7242 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7243 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7244 | 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] | 7245 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7246 | if (IS_CHERRYVIEW(dev_priv)) |
| 7247 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7248 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 7249 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7250 | } |
| 7251 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7252 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7253 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7254 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7255 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7256 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7257 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7258 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7259 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7260 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7261 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7262 | dpll = DPLL_VGA_MODE_DIS; |
| 7263 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7264 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7265 | dpll |= DPLLB_MODE_LVDS; |
| 7266 | else |
| 7267 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7268 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 7269 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 7270 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7271 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7272 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7273 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7274 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 7275 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7276 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7277 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7278 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7279 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7280 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7281 | |
| 7282 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7283 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7284 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7285 | else { |
| 7286 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7287 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7288 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7289 | } |
| 7290 | switch (clock->p2) { |
| 7291 | case 5: |
| 7292 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7293 | break; |
| 7294 | case 7: |
| 7295 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7296 | break; |
| 7297 | case 10: |
| 7298 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7299 | break; |
| 7300 | case 14: |
| 7301 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7302 | break; |
| 7303 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7304 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7305 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7306 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7307 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7308 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7309 | 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] | 7310 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7311 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7312 | else |
| 7313 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7314 | |
| 7315 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7316 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7317 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7318 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7319 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7320 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7321 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7322 | } |
| 7323 | } |
| 7324 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7325 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7326 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7327 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7328 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7329 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7330 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7331 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7332 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7333 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7334 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7335 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7336 | dpll = DPLL_VGA_MODE_DIS; |
| 7337 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7338 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7339 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7340 | } else { |
| 7341 | if (clock->p1 == 2) |
| 7342 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7343 | else |
| 7344 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7345 | if (clock->p2 == 4) |
| 7346 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7347 | } |
| 7348 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7349 | if (!IS_I830(dev_priv) && |
| 7350 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7351 | dpll |= DPLL_DVO_2X_MODE; |
| 7352 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7353 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7354 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7355 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7356 | else |
| 7357 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7358 | |
| 7359 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7360 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7361 | } |
| 7362 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7363 | 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] | 7364 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7365 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7366 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7367 | enum pipe pipe = crtc->pipe; |
| 7368 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
| 7369 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7370 | u32 crtc_vtotal, crtc_vblank_end; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7371 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7372 | |
| 7373 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7374 | * the hw state checker will get angry at the mismatch. */ |
| 7375 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7376 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7377 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7378 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7379 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7380 | crtc_vtotal -= 1; |
| 7381 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7382 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7383 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7384 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7385 | else |
| 7386 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7387 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7388 | if (vsyncshift < 0) |
| 7389 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7390 | } |
| 7391 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7392 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7393 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7394 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7395 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7396 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7397 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7398 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7399 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7400 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7401 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7402 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7403 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7404 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7405 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7406 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7407 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7408 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7409 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7410 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7411 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7412 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7413 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7414 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7415 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7416 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7417 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7418 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 7419 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7420 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7421 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7422 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7423 | } |
| 7424 | |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7425 | 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] | 7426 | { |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7427 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7428 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7429 | enum pipe pipe = crtc->pipe; |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7430 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7431 | /* pipesrc controls the size that is scaled from, which should |
| 7432 | * always be the user's requested size. |
| 7433 | */ |
| 7434 | I915_WRITE(PIPESRC(pipe), |
Maarten Lankhorst | 44fe7f3 | 2018-10-04 11:45:54 +0200 | [diff] [blame] | 7435 | ((crtc_state->pipe_src_w - 1) << 16) | |
| 7436 | (crtc_state->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7437 | } |
| 7438 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7439 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7440 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7441 | { |
| 7442 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7443 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7444 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7445 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7446 | |
| 7447 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7448 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7449 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7450 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7451 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7452 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7453 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7454 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7455 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7456 | |
| 7457 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7458 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7459 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7460 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7461 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7462 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7463 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7464 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7465 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7466 | |
| 7467 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7468 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7469 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7470 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7471 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7475 | struct intel_crtc_state *pipe_config) |
| 7476 | { |
| 7477 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7478 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7479 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7480 | |
| 7481 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7482 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7483 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7484 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7485 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7486 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7487 | } |
| 7488 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7489 | 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] | 7490 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7491 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7492 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7493 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7494 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7495 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7496 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7497 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7498 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7499 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7500 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7501 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7502 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7503 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7504 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7505 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7506 | |
| 7507 | mode->hsync = drm_mode_hsync(mode); |
| 7508 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7509 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7510 | } |
| 7511 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7512 | static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7513 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7514 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 7515 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7516 | u32 pipeconf; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7517 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7518 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7519 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 7520 | /* we keep both pipes enabled on 830 */ |
| 7521 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7522 | pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7523 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7524 | if (crtc_state->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7525 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7526 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7527 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7528 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7529 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7530 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7531 | if (crtc_state->dither && crtc_state->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7532 | pipeconf |= PIPECONF_DITHER_EN | |
| 7533 | PIPECONF_DITHER_TYPE_SP; |
| 7534 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7535 | switch (crtc_state->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7536 | case 18: |
| 7537 | pipeconf |= PIPECONF_6BPC; |
| 7538 | break; |
| 7539 | case 24: |
| 7540 | pipeconf |= PIPECONF_8BPC; |
| 7541 | break; |
| 7542 | case 30: |
| 7543 | pipeconf |= PIPECONF_10BPC; |
| 7544 | break; |
| 7545 | default: |
| 7546 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7547 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7548 | } |
| 7549 | } |
| 7550 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7551 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7552 | if (INTEL_GEN(dev_priv) < 4 || |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7553 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7554 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7555 | else |
| 7556 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7557 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7558 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7559 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7560 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7561 | crtc_state->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7562 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7563 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 7564 | I915_WRITE(PIPECONF(crtc->pipe), pipeconf); |
| 7565 | POSTING_READ(PIPECONF(crtc->pipe)); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7566 | } |
| 7567 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7568 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7569 | struct intel_crtc_state *crtc_state) |
| 7570 | { |
| 7571 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7572 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7573 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7574 | int refclk = 48000; |
| 7575 | |
| 7576 | memset(&crtc_state->dpll_hw_state, 0, |
| 7577 | sizeof(crtc_state->dpll_hw_state)); |
| 7578 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7579 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7580 | if (intel_panel_use_ssc(dev_priv)) { |
| 7581 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7582 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7583 | } |
| 7584 | |
| 7585 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7586 | } 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] | 7587 | limit = &intel_limits_i8xx_dvo; |
| 7588 | } else { |
| 7589 | limit = &intel_limits_i8xx_dac; |
| 7590 | } |
| 7591 | |
| 7592 | if (!crtc_state->clock_set && |
| 7593 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7594 | refclk, NULL, &crtc_state->dpll)) { |
| 7595 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7596 | return -EINVAL; |
| 7597 | } |
| 7598 | |
| 7599 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7600 | |
| 7601 | return 0; |
| 7602 | } |
| 7603 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7604 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7605 | struct intel_crtc_state *crtc_state) |
| 7606 | { |
| 7607 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7608 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7609 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7610 | int refclk = 96000; |
| 7611 | |
| 7612 | memset(&crtc_state->dpll_hw_state, 0, |
| 7613 | sizeof(crtc_state->dpll_hw_state)); |
| 7614 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7615 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7616 | if (intel_panel_use_ssc(dev_priv)) { |
| 7617 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7618 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7619 | } |
| 7620 | |
| 7621 | if (intel_is_dual_link_lvds(dev)) |
| 7622 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7623 | else |
| 7624 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7625 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7626 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7627 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7628 | } 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] | 7629 | limit = &intel_limits_g4x_sdvo; |
| 7630 | } else { |
| 7631 | /* The option is for other outputs */ |
| 7632 | limit = &intel_limits_i9xx_sdvo; |
| 7633 | } |
| 7634 | |
| 7635 | if (!crtc_state->clock_set && |
| 7636 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7637 | refclk, NULL, &crtc_state->dpll)) { |
| 7638 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7639 | return -EINVAL; |
| 7640 | } |
| 7641 | |
| 7642 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7643 | |
| 7644 | return 0; |
| 7645 | } |
| 7646 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7647 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7648 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7649 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7650 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7651 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7652 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7653 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7654 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7655 | memset(&crtc_state->dpll_hw_state, 0, |
| 7656 | sizeof(crtc_state->dpll_hw_state)); |
| 7657 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7658 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7659 | if (intel_panel_use_ssc(dev_priv)) { |
| 7660 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7661 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7662 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7663 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7664 | limit = &intel_limits_pineview_lvds; |
| 7665 | } else { |
| 7666 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7667 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7668 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7669 | if (!crtc_state->clock_set && |
| 7670 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7671 | refclk, NULL, &crtc_state->dpll)) { |
| 7672 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7673 | return -EINVAL; |
| 7674 | } |
| 7675 | |
| 7676 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7677 | |
| 7678 | return 0; |
| 7679 | } |
| 7680 | |
| 7681 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7682 | struct intel_crtc_state *crtc_state) |
| 7683 | { |
| 7684 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7685 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7686 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7687 | int refclk = 96000; |
| 7688 | |
| 7689 | memset(&crtc_state->dpll_hw_state, 0, |
| 7690 | sizeof(crtc_state->dpll_hw_state)); |
| 7691 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7692 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7693 | if (intel_panel_use_ssc(dev_priv)) { |
| 7694 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7695 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7696 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7697 | |
| 7698 | limit = &intel_limits_i9xx_lvds; |
| 7699 | } else { |
| 7700 | limit = &intel_limits_i9xx_sdvo; |
| 7701 | } |
| 7702 | |
| 7703 | if (!crtc_state->clock_set && |
| 7704 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7705 | refclk, NULL, &crtc_state->dpll)) { |
| 7706 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7707 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7708 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7709 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7710 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7711 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7712 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7713 | } |
| 7714 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7715 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7716 | struct intel_crtc_state *crtc_state) |
| 7717 | { |
| 7718 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7719 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7720 | |
| 7721 | memset(&crtc_state->dpll_hw_state, 0, |
| 7722 | sizeof(crtc_state->dpll_hw_state)); |
| 7723 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7724 | if (!crtc_state->clock_set && |
| 7725 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7726 | refclk, NULL, &crtc_state->dpll)) { |
| 7727 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7728 | return -EINVAL; |
| 7729 | } |
| 7730 | |
| 7731 | chv_compute_dpll(crtc, crtc_state); |
| 7732 | |
| 7733 | return 0; |
| 7734 | } |
| 7735 | |
| 7736 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7737 | struct intel_crtc_state *crtc_state) |
| 7738 | { |
| 7739 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 7740 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7741 | |
| 7742 | memset(&crtc_state->dpll_hw_state, 0, |
| 7743 | sizeof(crtc_state->dpll_hw_state)); |
| 7744 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7745 | if (!crtc_state->clock_set && |
| 7746 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7747 | refclk, NULL, &crtc_state->dpll)) { |
| 7748 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7749 | return -EINVAL; |
| 7750 | } |
| 7751 | |
| 7752 | vlv_compute_dpll(crtc, crtc_state); |
| 7753 | |
| 7754 | return 0; |
| 7755 | } |
| 7756 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7757 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7758 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7759 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7760 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7761 | u32 tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7762 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7763 | if (INTEL_GEN(dev_priv) <= 3 && |
| 7764 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7765 | return; |
| 7766 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7767 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7768 | if (!(tmp & PFIT_ENABLE)) |
| 7769 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7770 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7771 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7772 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7773 | if (crtc->pipe != PIPE_B) |
| 7774 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7775 | } else { |
| 7776 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7777 | return; |
| 7778 | } |
| 7779 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7780 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7781 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7782 | } |
| 7783 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7784 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7785 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7786 | { |
| 7787 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7788 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7789 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7790 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7791 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7792 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7793 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7794 | /* In case of DSI, DPLL will not be used */ |
| 7795 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7796 | return; |
| 7797 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7798 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7799 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7800 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7801 | |
| 7802 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7803 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7804 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7805 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7806 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7807 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7808 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7809 | } |
| 7810 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7811 | static void |
| 7812 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7813 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7814 | { |
| 7815 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7816 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7817 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 7818 | enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7819 | enum pipe pipe; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7820 | u32 val, base, offset; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7821 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7822 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7823 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7824 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7825 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7826 | if (!plane->get_hw_state(plane, &pipe)) |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7827 | return; |
| 7828 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 7829 | WARN_ON(pipe != crtc->pipe); |
| 7830 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7831 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7832 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7833 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7834 | return; |
| 7835 | } |
| 7836 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7837 | fb = &intel_fb->base; |
| 7838 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 7839 | fb->dev = dev; |
| 7840 | |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 7841 | val = I915_READ(DSPCNTR(i9xx_plane)); |
| 7842 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7843 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7844 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7845 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 7846 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7847 | } |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7848 | |
| 7849 | if (val & DISPPLANE_ROTATE_180) |
| 7850 | plane_config->rotation = DRM_MODE_ROTATE_180; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7851 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7852 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 7853 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B && |
| 7854 | val & DISPPLANE_MIRROR) |
| 7855 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 7856 | |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7857 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7858 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 7859 | fb->format = drm_format_info(fourcc); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7860 | |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 7861 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
| 7862 | offset = I915_READ(DSPOFFSET(i9xx_plane)); |
| 7863 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
| 7864 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7865 | if (plane_config->tiling) |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7866 | offset = I915_READ(DSPTILEOFF(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7867 | else |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7868 | offset = I915_READ(DSPLINOFF(i9xx_plane)); |
| 7869 | base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7870 | } else { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7871 | base = I915_READ(DSPADDR(i9xx_plane)); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7872 | } |
| 7873 | plane_config->base = base; |
| 7874 | |
| 7875 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7876 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7877 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7878 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7879 | val = I915_READ(DSPSTRIDE(i9xx_plane)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7880 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7881 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 7882 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7883 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7884 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7885 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 7886 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7887 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 7888 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7889 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7890 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7891 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7892 | } |
| 7893 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7894 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7895 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7896 | { |
| 7897 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7898 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7899 | int pipe = pipe_config->cpu_transcoder; |
| 7900 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7901 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7902 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7903 | int refclk = 100000; |
| 7904 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 7905 | /* In case of DSI, DPLL will not be used */ |
| 7906 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7907 | return; |
| 7908 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7909 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7910 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7911 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7912 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7913 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 7914 | 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] | 7915 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7916 | |
| 7917 | 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] | 7918 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 7919 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 7920 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7921 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7922 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7923 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7924 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 7925 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7926 | } |
| 7927 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7928 | static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc, |
| 7929 | struct intel_crtc_state *pipe_config) |
| 7930 | { |
| 7931 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7932 | enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB; |
| 7933 | |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 7934 | pipe_config->lspcon_downsampling = false; |
| 7935 | |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7936 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
| 7937 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
| 7938 | |
| 7939 | if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) { |
| 7940 | bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE; |
| 7941 | bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND; |
| 7942 | |
| 7943 | if (ycbcr420_enabled) { |
| 7944 | /* We support 4:2:0 in full blend mode only */ |
| 7945 | if (!blend) |
| 7946 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 7947 | else if (!(IS_GEMINILAKE(dev_priv) || |
| 7948 | INTEL_GEN(dev_priv) >= 10)) |
| 7949 | output = INTEL_OUTPUT_FORMAT_INVALID; |
| 7950 | else |
| 7951 | output = INTEL_OUTPUT_FORMAT_YCBCR420; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 7952 | } else { |
Shashank Sharma | 668b6c1 | 2018-10-12 11:53:14 +0530 | [diff] [blame] | 7953 | /* |
| 7954 | * Currently there is no interface defined to |
| 7955 | * check user preference between RGB/YCBCR444 |
| 7956 | * or YCBCR420. So the only possible case for |
| 7957 | * YCBCR444 usage is driving YCBCR420 output |
| 7958 | * with LSPCON, when pipe is configured for |
| 7959 | * YCBCR444 output and LSPCON takes care of |
| 7960 | * downsampling it. |
| 7961 | */ |
| 7962 | pipe_config->lspcon_downsampling = true; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 7963 | output = INTEL_OUTPUT_FORMAT_YCBCR444; |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 7964 | } |
| 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | pipe_config->output_format = output; |
| 7969 | } |
| 7970 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7971 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7972 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7973 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7974 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7975 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 7976 | intel_wakeref_t wakeref; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 7977 | u32 tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7978 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7979 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7980 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 7981 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 7982 | if (!wakeref) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7983 | return false; |
| 7984 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 7985 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7986 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 7987 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7988 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7989 | ret = false; |
| 7990 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7991 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7992 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 7993 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7994 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7995 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 7996 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7997 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7998 | case PIPECONF_6BPC: |
| 7999 | pipe_config->pipe_bpp = 18; |
| 8000 | break; |
| 8001 | case PIPECONF_8BPC: |
| 8002 | pipe_config->pipe_bpp = 24; |
| 8003 | break; |
| 8004 | case PIPECONF_10BPC: |
| 8005 | pipe_config->pipe_bpp = 30; |
| 8006 | break; |
| 8007 | default: |
| 8008 | break; |
| 8009 | } |
| 8010 | } |
| 8011 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8012 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8013 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8014 | pipe_config->limited_color_range = true; |
| 8015 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8016 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8017 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8018 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8019 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8020 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8021 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8022 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8023 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8024 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8025 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8026 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8027 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8028 | else |
| 8029 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8030 | pipe_config->pixel_multiplier = |
| 8031 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8032 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8033 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8034 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 8035 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8036 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8037 | pipe_config->pixel_multiplier = |
| 8038 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8039 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8040 | } else { |
| 8041 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8042 | * port and will be fixed up in the encoder->get_config |
| 8043 | * function. */ |
| 8044 | pipe_config->pixel_multiplier = 1; |
| 8045 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8046 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8047 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8048 | /* |
| 8049 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8050 | * on 830. Filter it out here so that we don't |
| 8051 | * report errors due to that. |
| 8052 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8053 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8054 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8055 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8056 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8057 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8058 | } else { |
| 8059 | /* Mask out read-only status bits. */ |
| 8060 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8061 | DPLL_PORTC_READY_MASK | |
| 8062 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8063 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8064 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8065 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8066 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 8067 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8068 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8069 | else |
| 8070 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8071 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8072 | /* |
| 8073 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8074 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8075 | * default. |
| 8076 | */ |
| 8077 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8078 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8079 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8080 | ret = true; |
| 8081 | |
| 8082 | out: |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 8083 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8084 | |
| 8085 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8086 | } |
| 8087 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8088 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8089 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8090 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8091 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8092 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8093 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8094 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8095 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8096 | bool has_ck505 = false; |
| 8097 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8098 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8099 | |
| 8100 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8101 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8102 | switch (encoder->type) { |
| 8103 | case INTEL_OUTPUT_LVDS: |
| 8104 | has_panel = true; |
| 8105 | has_lvds = true; |
| 8106 | break; |
| 8107 | case INTEL_OUTPUT_EDP: |
| 8108 | has_panel = true; |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 8109 | if (encoder->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8110 | has_cpu_edp = true; |
| 8111 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8112 | default: |
| 8113 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8114 | } |
| 8115 | } |
| 8116 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8117 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8118 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8119 | can_ssc = has_ck505; |
| 8120 | } else { |
| 8121 | has_ck505 = false; |
| 8122 | can_ssc = true; |
| 8123 | } |
| 8124 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8125 | /* Check if any DPLLs are using the SSC source */ |
| 8126 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8127 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8128 | |
| 8129 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8130 | continue; |
| 8131 | |
| 8132 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8133 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8134 | using_ssc_source = true; |
| 8135 | break; |
| 8136 | } |
| 8137 | } |
| 8138 | |
| 8139 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8140 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8141 | |
| 8142 | /* Ironlake: try to setup display ref clock before DPLL |
| 8143 | * enabling. This is only under driver's control after |
| 8144 | * PCH B stepping, previous chipset stepping should be |
| 8145 | * ignoring this setting. |
| 8146 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8147 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8148 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8149 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8150 | * compute the final state we want first and check if we need to |
| 8151 | * make any changes at all. |
| 8152 | */ |
| 8153 | final = val; |
| 8154 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8155 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8156 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8157 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8158 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8159 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8160 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8161 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 8162 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8163 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8164 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8165 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8166 | |
| 8167 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8168 | final |= DREF_SSC1_ENABLE; |
| 8169 | |
| 8170 | if (has_cpu_edp) { |
| 8171 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8172 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8173 | else |
| 8174 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8175 | } else |
| 8176 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8177 | } else if (using_ssc_source) { |
| 8178 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8179 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8180 | } |
| 8181 | |
| 8182 | if (final == val) |
| 8183 | return; |
| 8184 | |
| 8185 | /* Always enable nonspread source */ |
| 8186 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8187 | |
| 8188 | if (has_ck505) |
| 8189 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8190 | else |
| 8191 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8192 | |
| 8193 | if (has_panel) { |
| 8194 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8195 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8196 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8197 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8198 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8199 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8200 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8201 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8202 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8203 | |
| 8204 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8205 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8206 | POSTING_READ(PCH_DREF_CONTROL); |
| 8207 | udelay(200); |
| 8208 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8209 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8210 | |
| 8211 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8212 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8213 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8214 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8215 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8216 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8217 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8218 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8219 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8220 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8221 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8222 | POSTING_READ(PCH_DREF_CONTROL); |
| 8223 | udelay(200); |
| 8224 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8225 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8226 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8227 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8228 | |
| 8229 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8230 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8231 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8232 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8233 | POSTING_READ(PCH_DREF_CONTROL); |
| 8234 | udelay(200); |
| 8235 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8236 | if (!using_ssc_source) { |
| 8237 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8238 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8239 | /* Turn off the SSC source */ |
| 8240 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8241 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8242 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8243 | /* Turn off SSC1 */ |
| 8244 | val &= ~DREF_SSC1_ENABLE; |
| 8245 | |
| 8246 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 8247 | POSTING_READ(PCH_DREF_CONTROL); |
| 8248 | udelay(200); |
| 8249 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8250 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8251 | |
| 8252 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8253 | } |
| 8254 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8255 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8256 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8257 | u32 tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8258 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8259 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8260 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8261 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8262 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8263 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 8264 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8265 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8266 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8267 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8268 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8269 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8270 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 8271 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 8272 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8273 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8274 | } |
| 8275 | |
| 8276 | /* WaMPhyProgramming:hsw */ |
| 8277 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8278 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8279 | u32 tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8280 | |
| 8281 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8282 | tmp &= ~(0xFF << 24); |
| 8283 | tmp |= (0x12 << 24); |
| 8284 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8285 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8286 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8287 | tmp |= (1 << 11); |
| 8288 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8289 | |
| 8290 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8291 | tmp |= (1 << 11); |
| 8292 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8293 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8294 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8295 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8296 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8297 | |
| 8298 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8299 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8300 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8301 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8302 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8303 | tmp &= ~(7 << 13); |
| 8304 | tmp |= (5 << 13); |
| 8305 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8306 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8307 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8308 | tmp &= ~(7 << 13); |
| 8309 | tmp |= (5 << 13); |
| 8310 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8311 | |
| 8312 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8313 | tmp &= ~0xFF; |
| 8314 | tmp |= 0x1C; |
| 8315 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8316 | |
| 8317 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8318 | tmp &= ~0xFF; |
| 8319 | tmp |= 0x1C; |
| 8320 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8321 | |
| 8322 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8323 | tmp &= ~(0xFF << 16); |
| 8324 | tmp |= (0x1C << 16); |
| 8325 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8326 | |
| 8327 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8328 | tmp &= ~(0xFF << 16); |
| 8329 | tmp |= (0x1C << 16); |
| 8330 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8331 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8332 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8333 | tmp |= (1 << 27); |
| 8334 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8335 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8336 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8337 | tmp |= (1 << 27); |
| 8338 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8339 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8340 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8341 | tmp &= ~(0xF << 28); |
| 8342 | tmp |= (4 << 28); |
| 8343 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8344 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8345 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8346 | tmp &= ~(0xF << 28); |
| 8347 | tmp |= (4 << 28); |
| 8348 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8349 | } |
| 8350 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8351 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8352 | * Programming" based on the parameters passed: |
| 8353 | * - Sequence to enable CLKOUT_DP |
| 8354 | * - Sequence to enable CLKOUT_DP without spread |
| 8355 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8356 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8357 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 8358 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8359 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8360 | u32 reg, tmp; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8361 | |
| 8362 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8363 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8364 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 8365 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8366 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8367 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8368 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8369 | |
| 8370 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8371 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8372 | tmp |= SBI_SSCCTL_PATHALT; |
| 8373 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8374 | |
| 8375 | udelay(24); |
| 8376 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8377 | if (with_spread) { |
| 8378 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8379 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8380 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8381 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8382 | if (with_fdi) { |
| 8383 | lpt_reset_fdi_mphy(dev_priv); |
| 8384 | lpt_program_fdi_mphy(dev_priv); |
| 8385 | } |
| 8386 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8387 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8388 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8389 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8390 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8391 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8392 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8393 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8394 | } |
| 8395 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8396 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8397 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8398 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8399 | u32 reg, tmp; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8400 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8401 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8402 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 8403 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8404 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8405 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8406 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8407 | |
| 8408 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8409 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8410 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8411 | tmp |= SBI_SSCCTL_PATHALT; |
| 8412 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8413 | udelay(32); |
| 8414 | } |
| 8415 | tmp |= SBI_SSCCTL_DISABLE; |
| 8416 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8417 | } |
| 8418 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8419 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8420 | } |
| 8421 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8422 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8423 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8424 | static const u16 sscdivintphase[] = { |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8425 | [BEND_IDX( 50)] = 0x3B23, |
| 8426 | [BEND_IDX( 45)] = 0x3B23, |
| 8427 | [BEND_IDX( 40)] = 0x3C23, |
| 8428 | [BEND_IDX( 35)] = 0x3C23, |
| 8429 | [BEND_IDX( 30)] = 0x3D23, |
| 8430 | [BEND_IDX( 25)] = 0x3D23, |
| 8431 | [BEND_IDX( 20)] = 0x3E23, |
| 8432 | [BEND_IDX( 15)] = 0x3E23, |
| 8433 | [BEND_IDX( 10)] = 0x3F23, |
| 8434 | [BEND_IDX( 5)] = 0x3F23, |
| 8435 | [BEND_IDX( 0)] = 0x0025, |
| 8436 | [BEND_IDX( -5)] = 0x0025, |
| 8437 | [BEND_IDX(-10)] = 0x0125, |
| 8438 | [BEND_IDX(-15)] = 0x0125, |
| 8439 | [BEND_IDX(-20)] = 0x0225, |
| 8440 | [BEND_IDX(-25)] = 0x0225, |
| 8441 | [BEND_IDX(-30)] = 0x0325, |
| 8442 | [BEND_IDX(-35)] = 0x0325, |
| 8443 | [BEND_IDX(-40)] = 0x0425, |
| 8444 | [BEND_IDX(-45)] = 0x0425, |
| 8445 | [BEND_IDX(-50)] = 0x0525, |
| 8446 | }; |
| 8447 | |
| 8448 | /* |
| 8449 | * Bend CLKOUT_DP |
| 8450 | * steps -50 to 50 inclusive, in steps of 5 |
| 8451 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8452 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8453 | */ |
| 8454 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8455 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8456 | u32 tmp; |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8457 | int idx = BEND_IDX(steps); |
| 8458 | |
| 8459 | if (WARN_ON(steps % 5 != 0)) |
| 8460 | return; |
| 8461 | |
| 8462 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8463 | return; |
| 8464 | |
| 8465 | mutex_lock(&dev_priv->sb_lock); |
| 8466 | |
| 8467 | if (steps % 10 != 0) |
| 8468 | tmp = 0xAAAAAAAB; |
| 8469 | else |
| 8470 | tmp = 0x00000000; |
| 8471 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8472 | |
| 8473 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8474 | tmp &= 0xffff0000; |
| 8475 | tmp |= sscdivintphase[idx]; |
| 8476 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8477 | |
| 8478 | mutex_unlock(&dev_priv->sb_lock); |
| 8479 | } |
| 8480 | |
| 8481 | #undef BEND_IDX |
| 8482 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8483 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8484 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8485 | struct intel_encoder *encoder; |
| 8486 | bool has_vga = false; |
| 8487 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8488 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8489 | switch (encoder->type) { |
| 8490 | case INTEL_OUTPUT_ANALOG: |
| 8491 | has_vga = true; |
| 8492 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8493 | default: |
| 8494 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8495 | } |
| 8496 | } |
| 8497 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8498 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8499 | lpt_bend_clkout_dp(dev_priv, 0); |
| 8500 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8501 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8502 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8503 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8504 | } |
| 8505 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8506 | /* |
| 8507 | * Initialize reference clocks when the driver loads |
| 8508 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8509 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8510 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8511 | 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] | 8512 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8513 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8514 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8515 | } |
| 8516 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8517 | static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8518 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8519 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8520 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8521 | enum pipe pipe = crtc->pipe; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8522 | u32 val; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8523 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8524 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8525 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8526 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8527 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8528 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8529 | break; |
| 8530 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8531 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8532 | break; |
| 8533 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8534 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8535 | break; |
| 8536 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8537 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8538 | break; |
| 8539 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8540 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8541 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8542 | } |
| 8543 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8544 | if (crtc_state->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8545 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8546 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8547 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8548 | val |= PIPECONF_INTERLACED_ILK; |
| 8549 | else |
| 8550 | val |= PIPECONF_PROGRESSIVE; |
| 8551 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8552 | if (crtc_state->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8553 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8554 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8555 | I915_WRITE(PIPECONF(pipe), val); |
| 8556 | POSTING_READ(PIPECONF(pipe)); |
| 8557 | } |
| 8558 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8559 | static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8560 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8561 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8562 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 8563 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8564 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8565 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8566 | if (IS_HASWELL(dev_priv) && crtc_state->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8567 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8568 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8569 | if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8570 | val |= PIPECONF_INTERLACED_ILK; |
| 8571 | else |
| 8572 | val |= PIPECONF_PROGRESSIVE; |
| 8573 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8574 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8575 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8576 | } |
| 8577 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8578 | static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state) |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8579 | { |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8580 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 8581 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8582 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 8583 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8584 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8585 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8586 | switch (crtc_state->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8587 | case 18: |
| 8588 | val |= PIPEMISC_DITHER_6_BPC; |
| 8589 | break; |
| 8590 | case 24: |
| 8591 | val |= PIPEMISC_DITHER_8_BPC; |
| 8592 | break; |
| 8593 | case 30: |
| 8594 | val |= PIPEMISC_DITHER_10_BPC; |
| 8595 | break; |
| 8596 | case 36: |
| 8597 | val |= PIPEMISC_DITHER_12_BPC; |
| 8598 | break; |
| 8599 | default: |
| 8600 | /* Case prevented by pipe_config_set_bpp. */ |
| 8601 | BUG(); |
| 8602 | } |
| 8603 | |
Maarten Lankhorst | fdf7351 | 2018-10-04 11:45:52 +0200 | [diff] [blame] | 8604 | if (crtc_state->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8605 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8606 | |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8607 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || |
| 8608 | crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8609 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV; |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 8610 | |
| 8611 | if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 8612 | val |= PIPEMISC_YUV420_ENABLE | |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8613 | PIPEMISC_YUV420_MODE_FULL_BLEND; |
Shashank Sharma | b22ca99 | 2017-07-24 19:19:32 +0530 | [diff] [blame] | 8614 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8615 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8616 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8617 | } |
| 8618 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8619 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8620 | { |
| 8621 | /* |
| 8622 | * Account for spread spectrum to avoid |
| 8623 | * oversubscribing the link. Max center spread |
| 8624 | * is 2.5%; use 5% for safety's sake. |
| 8625 | */ |
| 8626 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8627 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8628 | } |
| 8629 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8630 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8631 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8632 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8633 | } |
| 8634 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8635 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8636 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8637 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8638 | { |
| 8639 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8640 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8641 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8642 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8643 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8644 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8645 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8646 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8647 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8648 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8649 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8650 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8651 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8652 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8653 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8654 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8655 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8656 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8657 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8658 | fp |= FP_CB_TUNE; |
| 8659 | |
| 8660 | if (reduced_clock) { |
| 8661 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8662 | |
| 8663 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8664 | fp2 |= FP_CB_TUNE; |
| 8665 | } else { |
| 8666 | fp2 = fp; |
| 8667 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8668 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8669 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8670 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8671 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8672 | dpll |= DPLLB_MODE_LVDS; |
| 8673 | else |
| 8674 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8675 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8676 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8677 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8678 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8679 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8680 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8681 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8682 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8683 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8684 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8685 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 8686 | /* |
| 8687 | * The high speed IO clock is only really required for |
| 8688 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 8689 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 8690 | * the clock needlessly does no real harm, except use up a |
| 8691 | * bit of power potentially. |
| 8692 | * |
| 8693 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 8694 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 8695 | * driving PCH ports at the same time. On SNB we could do this, |
| 8696 | * and potentially avoid enabling the second DPLL, but it's not |
| 8697 | * clear if it''s a win or loss power wise. No point in doing |
| 8698 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 8699 | */ |
| 8700 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 8701 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 8702 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 8703 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8704 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8705 | 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] | 8706 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8707 | 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] | 8708 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8709 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8710 | case 5: |
| 8711 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8712 | break; |
| 8713 | case 7: |
| 8714 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8715 | break; |
| 8716 | case 10: |
| 8717 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8718 | break; |
| 8719 | case 14: |
| 8720 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8721 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8722 | } |
| 8723 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8724 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8725 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8726 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8727 | else |
| 8728 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8729 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8730 | dpll |= DPLL_VCO_ENABLE; |
| 8731 | |
| 8732 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8733 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8734 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8735 | } |
| 8736 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8737 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8738 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8739 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8740 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8741 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8742 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8743 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8744 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8745 | memset(&crtc_state->dpll_hw_state, 0, |
| 8746 | sizeof(crtc_state->dpll_hw_state)); |
| 8747 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8748 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8749 | if (!crtc_state->has_pch_encoder) |
| 8750 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8751 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8752 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8753 | if (intel_panel_use_ssc(dev_priv)) { |
| 8754 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8755 | dev_priv->vbt.lvds_ssc_freq); |
| 8756 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8757 | } |
| 8758 | |
| 8759 | if (intel_is_dual_link_lvds(dev)) { |
| 8760 | if (refclk == 100000) |
| 8761 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8762 | else |
| 8763 | limit = &intel_limits_ironlake_dual_lvds; |
| 8764 | } else { |
| 8765 | if (refclk == 100000) |
| 8766 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8767 | else |
| 8768 | limit = &intel_limits_ironlake_single_lvds; |
| 8769 | } |
| 8770 | } else { |
| 8771 | limit = &intel_limits_ironlake_dac; |
| 8772 | } |
| 8773 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8774 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8775 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8776 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8777 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8778 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8779 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8780 | |
Gustavo A. R. Silva | cbaa331 | 2017-05-15 16:56:05 -0500 | [diff] [blame] | 8781 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8782 | |
Gustavo A. R. Silva | efd38b6 | 2017-05-15 17:00:28 -0500 | [diff] [blame] | 8783 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 8784 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 8785 | pipe_name(crtc->pipe)); |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8786 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8787 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8788 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8789 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8790 | } |
| 8791 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8792 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8793 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8794 | { |
| 8795 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8796 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8797 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8798 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8799 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8800 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8801 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8802 | & ~TU_SIZE_MASK; |
| 8803 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8804 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8805 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8806 | } |
| 8807 | |
| 8808 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8809 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8810 | struct intel_link_m_n *m_n, |
| 8811 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8812 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8813 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8814 | enum pipe pipe = crtc->pipe; |
| 8815 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8816 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8817 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8818 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8819 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8820 | & ~TU_SIZE_MASK; |
| 8821 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8822 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8823 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Maarten Lankhorst | 4207c8b | 2018-10-15 11:40:23 +0200 | [diff] [blame] | 8824 | |
| 8825 | if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8826 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8827 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8828 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8829 | & ~TU_SIZE_MASK; |
| 8830 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8831 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8832 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8833 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8834 | } else { |
| 8835 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8836 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8837 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8838 | & ~TU_SIZE_MASK; |
| 8839 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8840 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8841 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8842 | } |
| 8843 | } |
| 8844 | |
| 8845 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8846 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8847 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8848 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8849 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8850 | else |
| 8851 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8852 | &pipe_config->dp_m_n, |
| 8853 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8854 | } |
| 8855 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8856 | 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] | 8857 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8858 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8859 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8860 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8861 | } |
| 8862 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8863 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8864 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8865 | { |
| 8866 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8867 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8868 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 8869 | u32 ps_ctrl = 0; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8870 | int id = -1; |
| 8871 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8872 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8873 | /* find scaler attached to this pipe */ |
| 8874 | for (i = 0; i < crtc->num_scalers; i++) { |
| 8875 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 8876 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 8877 | id = i; |
| 8878 | pipe_config->pch_pfit.enabled = true; |
| 8879 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 8880 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 8881 | break; |
| 8882 | } |
| 8883 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8884 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 8885 | scaler_state->scaler_id = id; |
| 8886 | if (id >= 0) { |
| 8887 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 8888 | } else { |
| 8889 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8890 | } |
| 8891 | } |
| 8892 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8893 | static void |
| 8894 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8895 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8896 | { |
| 8897 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8898 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8899 | struct intel_plane *plane = to_intel_plane(crtc->base.primary); |
| 8900 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8901 | enum pipe pipe; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8902 | u32 val, base, offset, stride_mult, tiling, alpha; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8903 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8904 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8905 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8906 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8907 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8908 | if (!plane->get_hw_state(plane, &pipe)) |
Ville Syrjälä | 2924b8c | 2017-11-17 21:19:16 +0200 | [diff] [blame] | 8909 | return; |
| 8910 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 8911 | WARN_ON(pipe != crtc->pipe); |
| 8912 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8913 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8914 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8915 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8916 | return; |
| 8917 | } |
| 8918 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8919 | fb = &intel_fb->base; |
| 8920 | |
Ville Syrjälä | d2e9f5f | 2016-11-18 21:52:53 +0200 | [diff] [blame] | 8921 | fb->dev = dev; |
| 8922 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8923 | val = I915_READ(PLANE_CTL(pipe, plane_id)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8924 | |
James Ausmus | b597277 | 2018-01-30 11:49:16 -0200 | [diff] [blame] | 8925 | if (INTEL_GEN(dev_priv) >= 11) |
| 8926 | pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK; |
| 8927 | else |
| 8928 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8929 | |
| 8930 | if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) { |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8931 | alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id)); |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8932 | alpha &= PLANE_COLOR_ALPHA_MASK; |
| 8933 | } else { |
| 8934 | alpha = val & PLANE_CTL_ALPHA_MASK; |
| 8935 | } |
| 8936 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8937 | fourcc = skl_format_to_fourcc(pixel_format, |
James Ausmus | 4036c78 | 2017-11-13 10:11:28 -0800 | [diff] [blame] | 8938 | val & PLANE_CTL_ORDER_RGBX, alpha); |
Ville Syrjälä | 2f3f476 | 2016-11-18 21:52:57 +0200 | [diff] [blame] | 8939 | fb->format = drm_format_info(fourcc); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8940 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8941 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8942 | switch (tiling) { |
| 8943 | case PLANE_CTL_TILED_LINEAR: |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 8944 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8945 | break; |
| 8946 | case PLANE_CTL_TILED_X: |
| 8947 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8948 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8949 | break; |
| 8950 | case PLANE_CTL_TILED_Y: |
Imre Deak | 914a4fd | 2018-10-16 19:00:11 +0300 | [diff] [blame] | 8951 | plane_config->tiling = I915_TILING_Y; |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8952 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8953 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
| 8954 | else |
| 8955 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8956 | break; |
| 8957 | case PLANE_CTL_TILED_YF: |
Dhinakaran Pandiyan | 53867b4 | 2018-08-21 18:50:53 -0700 | [diff] [blame] | 8958 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 8959 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
| 8960 | else |
| 8961 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8962 | break; |
| 8963 | default: |
| 8964 | MISSING_CASE(tiling); |
| 8965 | goto error; |
| 8966 | } |
| 8967 | |
Ville Syrjälä | f43348a | 2018-11-20 15:54:50 +0200 | [diff] [blame] | 8968 | /* |
| 8969 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 8970 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 8971 | */ |
| 8972 | switch (val & PLANE_CTL_ROTATE_MASK) { |
| 8973 | case PLANE_CTL_ROTATE_0: |
| 8974 | plane_config->rotation = DRM_MODE_ROTATE_0; |
| 8975 | break; |
| 8976 | case PLANE_CTL_ROTATE_90: |
| 8977 | plane_config->rotation = DRM_MODE_ROTATE_270; |
| 8978 | break; |
| 8979 | case PLANE_CTL_ROTATE_180: |
| 8980 | plane_config->rotation = DRM_MODE_ROTATE_180; |
| 8981 | break; |
| 8982 | case PLANE_CTL_ROTATE_270: |
| 8983 | plane_config->rotation = DRM_MODE_ROTATE_90; |
| 8984 | break; |
| 8985 | } |
| 8986 | |
| 8987 | if (INTEL_GEN(dev_priv) >= 10 && |
| 8988 | val & PLANE_CTL_FLIP_HORIZONTAL) |
| 8989 | plane_config->rotation |= DRM_MODE_REFLECT_X; |
| 8990 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8991 | base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8992 | plane_config->base = base; |
| 8993 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8994 | offset = I915_READ(PLANE_OFFSET(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8995 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 8996 | val = I915_READ(PLANE_SIZE(pipe, plane_id)); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8997 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8998 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8999 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9000 | val = I915_READ(PLANE_STRIDE(pipe, plane_id)); |
Ville Syrjälä | b3cf5c0 | 2018-09-25 22:37:08 +0300 | [diff] [blame] | 9001 | stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9002 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9003 | |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 9004 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9005 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9006 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9007 | |
Ville Syrjälä | 282e83e | 2017-11-17 21:19:12 +0200 | [diff] [blame] | 9008 | DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9009 | crtc->base.name, plane->base.name, fb->width, fb->height, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 9010 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9011 | plane_config->size); |
| 9012 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9013 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9014 | return; |
| 9015 | |
| 9016 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 9017 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9018 | } |
| 9019 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9020 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9021 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9022 | { |
| 9023 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9024 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9025 | u32 tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9026 | |
| 9027 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9028 | |
| 9029 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9030 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9031 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9032 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9033 | |
| 9034 | /* We currently do not free assignements of panel fitters on |
| 9035 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9036 | * differentiates them) so just WARN about this case for now. */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 9037 | if (IS_GEN(dev_priv, 7)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9038 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9039 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9040 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9041 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9042 | } |
| 9043 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9044 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9045 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9046 | { |
| 9047 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9048 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9049 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9050 | intel_wakeref_t wakeref; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9051 | u32 tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9052 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9053 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9054 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9055 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 9056 | if (!wakeref) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9057 | return false; |
| 9058 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 9059 | pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9060 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9061 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9062 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9063 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9064 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9065 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9066 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9067 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9068 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9069 | case PIPECONF_6BPC: |
| 9070 | pipe_config->pipe_bpp = 18; |
| 9071 | break; |
| 9072 | case PIPECONF_8BPC: |
| 9073 | pipe_config->pipe_bpp = 24; |
| 9074 | break; |
| 9075 | case PIPECONF_10BPC: |
| 9076 | pipe_config->pipe_bpp = 30; |
| 9077 | break; |
| 9078 | case PIPECONF_12BPC: |
| 9079 | pipe_config->pipe_bpp = 36; |
| 9080 | break; |
| 9081 | default: |
| 9082 | break; |
| 9083 | } |
| 9084 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9085 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9086 | pipe_config->limited_color_range = true; |
| 9087 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9088 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9089 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9090 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9091 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9092 | pipe_config->has_pch_encoder = true; |
| 9093 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9094 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9095 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9096 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9097 | |
| 9098 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9099 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9100 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9101 | /* |
| 9102 | * The pipe->pch transcoder and pch transcoder->pll |
| 9103 | * mapping is fixed. |
| 9104 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9105 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9106 | } else { |
| 9107 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9108 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9109 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9110 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9111 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9112 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9113 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9114 | pipe_config->shared_dpll = |
| 9115 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9116 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9117 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9118 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9119 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9120 | |
| 9121 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9122 | pipe_config->pixel_multiplier = |
| 9123 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9124 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9125 | |
| 9126 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9127 | } else { |
| 9128 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9129 | } |
| 9130 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9131 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9132 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9133 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9134 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9135 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9136 | ret = true; |
| 9137 | |
| 9138 | out: |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9139 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9140 | |
| 9141 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9142 | } |
| 9143 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9144 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9145 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 9146 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9147 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9148 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9149 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9150 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9151 | pipe_name(crtc->pipe)); |
| 9152 | |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 9153 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2), |
Imre Deak | 9c3a16c | 2017-08-14 18:15:30 +0300 | [diff] [blame] | 9154 | "Display power well on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9155 | 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] | 9156 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9157 | 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] | 9158 | 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] | 9159 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9160 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9161 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9162 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9163 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9164 | 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] | 9165 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9166 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9167 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9168 | 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] | 9169 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9170 | /* |
| 9171 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9172 | * interrupts remain enabled. We used to check for that, but since it's |
| 9173 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9174 | * the interrupts, the check below should be enough. |
| 9175 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9176 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9177 | } |
| 9178 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9179 | static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9180 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9181 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9182 | return I915_READ(D_COMP_HSW); |
| 9183 | else |
| 9184 | return I915_READ(D_COMP_BDW); |
| 9185 | } |
| 9186 | |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9187 | 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] | 9188 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 9189 | if (IS_HASWELL(dev_priv)) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9190 | mutex_lock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9191 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9192 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 9193 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 9194 | mutex_unlock(&dev_priv->pcu_lock); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9195 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9196 | I915_WRITE(D_COMP_BDW, val); |
| 9197 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9198 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9199 | } |
| 9200 | |
| 9201 | /* |
| 9202 | * This function implements pieces of two sequences from BSpec: |
| 9203 | * - Sequence for display software to disable LCPLL |
| 9204 | * - Sequence for display software to allow package C8+ |
| 9205 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9206 | * register. Callers should take care of disabling all the display engine |
| 9207 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9208 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9209 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9210 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9211 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9212 | u32 val; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9213 | |
| 9214 | assert_can_disable_lcpll(dev_priv); |
| 9215 | |
| 9216 | val = I915_READ(LCPLL_CTL); |
| 9217 | |
| 9218 | if (switch_to_fclk) { |
| 9219 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9220 | I915_WRITE(LCPLL_CTL, val); |
| 9221 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9222 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9223 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9224 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9225 | |
| 9226 | val = I915_READ(LCPLL_CTL); |
| 9227 | } |
| 9228 | |
| 9229 | val |= LCPLL_PLL_DISABLE; |
| 9230 | I915_WRITE(LCPLL_CTL, val); |
| 9231 | POSTING_READ(LCPLL_CTL); |
| 9232 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 9233 | 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] | 9234 | DRM_ERROR("LCPLL still locked\n"); |
| 9235 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9236 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9237 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9238 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9239 | ndelay(100); |
| 9240 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9241 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9242 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9243 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9244 | |
| 9245 | if (allow_power_down) { |
| 9246 | val = I915_READ(LCPLL_CTL); |
| 9247 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9248 | I915_WRITE(LCPLL_CTL, val); |
| 9249 | POSTING_READ(LCPLL_CTL); |
| 9250 | } |
| 9251 | } |
| 9252 | |
| 9253 | /* |
| 9254 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9255 | * source. |
| 9256 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9257 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9258 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9259 | u32 val; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9260 | |
| 9261 | val = I915_READ(LCPLL_CTL); |
| 9262 | |
| 9263 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9264 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9265 | return; |
| 9266 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9267 | /* |
| 9268 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9269 | * 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] | 9270 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9271 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9272 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9273 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9274 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9275 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9276 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9277 | } |
| 9278 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9279 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9280 | val |= D_COMP_COMP_FORCE; |
| 9281 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9282 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9283 | |
| 9284 | val = I915_READ(LCPLL_CTL); |
| 9285 | val &= ~LCPLL_PLL_DISABLE; |
| 9286 | I915_WRITE(LCPLL_CTL, val); |
| 9287 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 9288 | if (intel_wait_for_register(dev_priv, |
| 9289 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 9290 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9291 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9292 | |
| 9293 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9294 | val = I915_READ(LCPLL_CTL); |
| 9295 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9296 | I915_WRITE(LCPLL_CTL, val); |
| 9297 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 9298 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9299 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9300 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9301 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9302 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9303 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9304 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 9305 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 9306 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9307 | } |
| 9308 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9309 | /* |
| 9310 | * Package states C8 and deeper are really deep PC states that can only be |
| 9311 | * reached when all the devices on the system allow it, so even if the graphics |
| 9312 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9313 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9314 | * |
| 9315 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9316 | * well is disabled and most interrupts are disabled, and these are also |
| 9317 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9318 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9319 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9320 | * hang the machine. |
| 9321 | * |
| 9322 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9323 | * the state of some registers, so when we come back from PC8+ we need to |
| 9324 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9325 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9326 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9327 | * because of the runtime PM support). |
| 9328 | * |
| 9329 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9330 | * documentation. |
| 9331 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9332 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9333 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9334 | u32 val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9335 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9336 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9337 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9338 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9339 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9340 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9341 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9342 | } |
| 9343 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9344 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9345 | hsw_disable_lcpll(dev_priv, true, true); |
| 9346 | } |
| 9347 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9348 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9349 | { |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9350 | u32 val; |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9351 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9352 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9353 | |
| 9354 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9355 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9356 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9357 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9358 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9359 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9360 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9361 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9362 | } |
| 9363 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9364 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9365 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9366 | { |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9367 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9368 | struct intel_atomic_state *state = |
| 9369 | to_intel_atomic_state(crtc_state->base.state); |
| 9370 | |
Madhav Chauhan | 70a057b | 2018-11-29 16:12:18 +0200 | [diff] [blame] | 9371 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) || |
| 9372 | IS_ICELAKE(dev_priv)) { |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9373 | struct intel_encoder *encoder = |
Ville Syrjälä | 5a0b385 | 2018-05-18 18:29:27 +0300 | [diff] [blame] | 9374 | intel_get_crtc_new_encoder(state, crtc_state); |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9375 | |
| 9376 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { |
Chris Wilson | 4303178 | 2018-09-13 14:16:26 +0100 | [diff] [blame] | 9377 | DRM_DEBUG_KMS("failed to find PLL for pipe %c\n", |
| 9378 | pipe_name(crtc->pipe)); |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9379 | return -EINVAL; |
Paulo Zanoni | 44a126b | 2017-03-22 15:58:45 -0300 | [diff] [blame] | 9380 | } |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9381 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9382 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9383 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9384 | } |
| 9385 | |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9386 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9387 | enum port port, |
| 9388 | struct intel_crtc_state *pipe_config) |
| 9389 | { |
| 9390 | enum intel_dpll_id id; |
| 9391 | u32 temp; |
| 9392 | |
| 9393 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
Paulo Zanoni | dfbd450 | 2017-08-25 16:40:04 -0300 | [diff] [blame] | 9394 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9395 | |
| 9396 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) |
| 9397 | return; |
| 9398 | |
| 9399 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9400 | } |
| 9401 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9402 | static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9403 | enum port port, |
| 9404 | struct intel_crtc_state *pipe_config) |
| 9405 | { |
| 9406 | enum intel_dpll_id id; |
| 9407 | u32 temp; |
| 9408 | |
| 9409 | /* TODO: TBT pll not implemented. */ |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9410 | if (intel_port_is_combophy(dev_priv, port)) { |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9411 | temp = I915_READ(DPCLKA_CFGCR0_ICL) & |
| 9412 | DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); |
| 9413 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
| 9414 | |
Vandita Kulkarni | a54270d | 2018-10-03 12:52:00 +0530 | [diff] [blame] | 9415 | if (WARN_ON(!intel_dpll_is_combophy(id))) |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9416 | return; |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9417 | } else if (intel_port_is_tc(dev_priv, port)) { |
Vandita Kulkarni | cb6caf7 | 2018-10-03 12:51:58 +0530 | [diff] [blame] | 9418 | id = icl_port_to_mg_pll_id(port); |
Vandita Kulkarni | 8ea59e6 | 2018-10-03 12:51:59 +0530 | [diff] [blame] | 9419 | } else { |
| 9420 | WARN(1, "Invalid port %x\n", port); |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9421 | return; |
| 9422 | } |
| 9423 | |
| 9424 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); |
| 9425 | } |
| 9426 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9427 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9428 | enum port port, |
| 9429 | struct intel_crtc_state *pipe_config) |
| 9430 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9431 | enum intel_dpll_id id; |
| 9432 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9433 | switch (port) { |
| 9434 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9435 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9436 | break; |
| 9437 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9438 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9439 | break; |
| 9440 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9441 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9442 | break; |
| 9443 | default: |
| 9444 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9445 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9446 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9447 | |
| 9448 | 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] | 9449 | } |
| 9450 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9451 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9452 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9453 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9454 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9455 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9456 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9457 | |
| 9458 | 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] | 9459 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9460 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9461 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9462 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9463 | |
| 9464 | 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] | 9465 | } |
| 9466 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9467 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9468 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9469 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9470 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9471 | enum intel_dpll_id id; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9472 | u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9473 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9474 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9475 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9476 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9477 | break; |
| 9478 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9479 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9480 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9481 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9482 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9483 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9484 | case PORT_CLK_SEL_LCPLL_810: |
| 9485 | id = DPLL_ID_LCPLL_810; |
| 9486 | break; |
| 9487 | case PORT_CLK_SEL_LCPLL_1350: |
| 9488 | id = DPLL_ID_LCPLL_1350; |
| 9489 | break; |
| 9490 | case PORT_CLK_SEL_LCPLL_2700: |
| 9491 | id = DPLL_ID_LCPLL_2700; |
| 9492 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9493 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 9494 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9495 | /* fall through */ |
| 9496 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9497 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9498 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9499 | |
| 9500 | 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] | 9501 | } |
| 9502 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9503 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9504 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9505 | u64 *power_domain_mask) |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9506 | { |
| 9507 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9508 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9509 | enum intel_display_power_domain power_domain; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9510 | unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP); |
| 9511 | unsigned long enabled_panel_transcoders = 0; |
| 9512 | enum transcoder panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9513 | u32 tmp; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9514 | |
| 9515 | if (IS_ICELAKE(dev_priv)) |
| 9516 | panel_transcoder_mask |= |
| 9517 | BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9518 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9519 | /* |
| 9520 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9521 | * and DSI transcoders handled below. |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9522 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9523 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9524 | |
| 9525 | /* |
| 9526 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9527 | * consistency and less surprising code; it's in always on power). |
| 9528 | */ |
Chris Wilson | 1b4bd5c | 2019-01-16 15:54:21 +0000 | [diff] [blame] | 9529 | for_each_set_bit(panel_transcoder, |
| 9530 | &panel_transcoder_mask, |
| 9531 | ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) { |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9532 | enum pipe trans_pipe; |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9533 | |
| 9534 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder)); |
| 9535 | if (!(tmp & TRANS_DDI_FUNC_ENABLE)) |
| 9536 | continue; |
| 9537 | |
| 9538 | /* |
| 9539 | * Log all enabled ones, only use the first one. |
| 9540 | * |
| 9541 | * FIXME: This won't work for two separate DSI displays. |
| 9542 | */ |
| 9543 | enabled_panel_transcoders |= BIT(panel_transcoder); |
| 9544 | if (enabled_panel_transcoders != BIT(panel_transcoder)) |
| 9545 | continue; |
| 9546 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9547 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9548 | default: |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9549 | WARN(1, "unknown pipe linked to transcoder %s\n", |
| 9550 | transcoder_name(panel_transcoder)); |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 9551 | /* fall through */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9552 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9553 | case TRANS_DDI_EDP_INPUT_A_ON: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9554 | trans_pipe = PIPE_A; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9555 | break; |
| 9556 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9557 | trans_pipe = PIPE_B; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9558 | break; |
| 9559 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
Madhav Chauhan | 2ca711c | 2018-11-29 16:12:27 +0200 | [diff] [blame] | 9560 | trans_pipe = PIPE_C; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9561 | break; |
| 9562 | } |
| 9563 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9564 | if (trans_pipe == crtc->pipe) |
| 9565 | pipe_config->cpu_transcoder = panel_transcoder; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9566 | } |
| 9567 | |
Jani Nikula | 0716931 | 2018-12-04 12:19:26 +0200 | [diff] [blame] | 9568 | /* |
| 9569 | * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1 |
| 9570 | */ |
| 9571 | WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) && |
| 9572 | enabled_panel_transcoders != BIT(TRANSCODER_EDP)); |
| 9573 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9574 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9575 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9576 | return false; |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9577 | |
| 9578 | WARN_ON(*power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9579 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9580 | |
| 9581 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9582 | |
| 9583 | return tmp & PIPECONF_ENABLE; |
| 9584 | } |
| 9585 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9586 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9587 | struct intel_crtc_state *pipe_config, |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9588 | u64 *power_domain_mask) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9589 | { |
| 9590 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9591 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9592 | enum intel_display_power_domain power_domain; |
| 9593 | enum port port; |
| 9594 | enum transcoder cpu_transcoder; |
| 9595 | u32 tmp; |
| 9596 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9597 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9598 | if (port == PORT_A) |
| 9599 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9600 | else |
| 9601 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9602 | |
| 9603 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9604 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9605 | continue; |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9606 | |
| 9607 | WARN_ON(*power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9608 | *power_domain_mask |= BIT_ULL(power_domain); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9609 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9610 | /* |
| 9611 | * The PLL needs to be enabled with a valid divider |
| 9612 | * configuration, otherwise accessing DSI registers will hang |
| 9613 | * the machine. See BSpec North Display Engine |
| 9614 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9615 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9616 | */ |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 9617 | if (!bxt_dsi_pll_is_enabled(dev_priv)) |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9618 | break; |
| 9619 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9620 | /* XXX: this works for video mode only */ |
| 9621 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9622 | if (!(tmp & DPI_ENABLE)) |
| 9623 | continue; |
| 9624 | |
| 9625 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9626 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9627 | continue; |
| 9628 | |
| 9629 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9630 | break; |
| 9631 | } |
| 9632 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9633 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9634 | } |
| 9635 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9636 | 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] | 9637 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9638 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9639 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9640 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9641 | enum port port; |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 9642 | u32 tmp; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9643 | |
| 9644 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9645 | |
| 9646 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9647 | |
Paulo Zanoni | 970888e | 2018-05-21 17:25:44 -0700 | [diff] [blame] | 9648 | if (IS_ICELAKE(dev_priv)) |
| 9649 | icelake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9650 | else if (IS_CANNONLAKE(dev_priv)) |
Kahola, Mika | 8b0f7e0 | 2017-06-09 15:26:03 -0700 | [diff] [blame] | 9651 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); |
| 9652 | else if (IS_GEN9_BC(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9653 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9654 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9655 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9656 | else |
| 9657 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9658 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9659 | pll = pipe_config->shared_dpll; |
| 9660 | if (pll) { |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 9661 | WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll, |
| 9662 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9663 | } |
| 9664 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9665 | /* |
| 9666 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9667 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9668 | * the PCH transcoder is on. |
| 9669 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9670 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9671 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9672 | pipe_config->has_pch_encoder = true; |
| 9673 | |
| 9674 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9675 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9676 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9677 | |
| 9678 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9679 | } |
| 9680 | } |
| 9681 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9682 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9683 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9684 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9685 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9686 | enum intel_display_power_domain power_domain; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9687 | u64 power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9688 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9689 | |
Imre Deak | e79dfb5 | 2017-07-20 01:50:57 +0300 | [diff] [blame] | 9690 | intel_crtc_init_scalers(crtc, pipe_config); |
Imre Deak | 5fb9dad | 2017-07-20 14:28:20 +0300 | [diff] [blame] | 9691 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9692 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9693 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9694 | return false; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9695 | power_domain_mask = BIT_ULL(power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9696 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9697 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9698 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9699 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9700 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 9701 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 9702 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 9703 | WARN_ON(active); |
| 9704 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9705 | } |
| 9706 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9707 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9708 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9709 | |
Madhav Chauhan | 2eae5d6 | 2018-11-29 16:12:28 +0200 | [diff] [blame] | 9710 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || |
| 9711 | IS_ICELAKE(dev_priv)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9712 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9713 | intel_get_pipe_timings(crtc, pipe_config); |
| 9714 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9715 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9716 | intel_get_pipe_src_size(crtc, pipe_config); |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 9717 | intel_get_crtc_ycbcr_config(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9718 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9719 | pipe_config->gamma_mode = |
| 9720 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9721 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9722 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9723 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9724 | WARN_ON(power_domain_mask & BIT_ULL(power_domain)); |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 9725 | power_domain_mask |= BIT_ULL(power_domain); |
Chris Wilson | 04161d6 | 2019-01-14 14:21:27 +0000 | [diff] [blame] | 9726 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9727 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9728 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 9729 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 9730 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9731 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9732 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 9733 | if (hsw_crtc_supports_ips(crtc)) { |
| 9734 | if (IS_HASWELL(dev_priv)) |
| 9735 | pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE; |
| 9736 | else { |
| 9737 | /* |
| 9738 | * We cannot readout IPS state on broadwell, set to |
| 9739 | * true so we can set it to a defined state on first |
| 9740 | * commit. |
| 9741 | */ |
| 9742 | pipe_config->ips_enabled = true; |
| 9743 | } |
| 9744 | } |
| 9745 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9746 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 9747 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 9748 | pipe_config->pixel_multiplier = |
| 9749 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 9750 | } else { |
| 9751 | pipe_config->pixel_multiplier = 1; |
| 9752 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9753 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9754 | out: |
| 9755 | for_each_power_domain(power_domain, power_domain_mask) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 9756 | intel_display_power_put_unchecked(dev_priv, power_domain); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9757 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9758 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9759 | } |
| 9760 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9761 | 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] | 9762 | { |
| 9763 | struct drm_i915_private *dev_priv = |
| 9764 | to_i915(plane_state->base.plane->dev); |
| 9765 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 9766 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 9767 | u32 base; |
| 9768 | |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 9769 | if (INTEL_INFO(dev_priv)->display.cursor_needs_physical) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9770 | base = obj->phys_handle->busaddr; |
| 9771 | else |
| 9772 | base = intel_plane_ggtt_offset(plane_state); |
| 9773 | |
Ville Syrjälä | c11ada0 | 2018-09-07 18:24:04 +0300 | [diff] [blame] | 9774 | base += plane_state->color_plane[0].offset; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9775 | |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9776 | /* ILK+ do this automagically */ |
| 9777 | if (HAS_GMCH_DISPLAY(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 9778 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | 1cecc83 | 2017-03-27 21:55:34 +0300 | [diff] [blame] | 9779 | base += (plane_state->base.crtc_h * |
| 9780 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; |
| 9781 | |
| 9782 | return base; |
| 9783 | } |
| 9784 | |
Ville Syrjälä | ed27022 | 2017-03-27 21:55:36 +0300 | [diff] [blame] | 9785 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
| 9786 | { |
| 9787 | int x = plane_state->base.crtc_x; |
| 9788 | int y = plane_state->base.crtc_y; |
| 9789 | u32 pos = 0; |
| 9790 | |
| 9791 | if (x < 0) { |
| 9792 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 9793 | x = -x; |
| 9794 | } |
| 9795 | pos |= x << CURSOR_X_SHIFT; |
| 9796 | |
| 9797 | if (y < 0) { |
| 9798 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 9799 | y = -y; |
| 9800 | } |
| 9801 | pos |= y << CURSOR_Y_SHIFT; |
| 9802 | |
| 9803 | return pos; |
| 9804 | } |
| 9805 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9806 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9807 | { |
| 9808 | const struct drm_mode_config *config = |
| 9809 | &plane_state->base.plane->dev->mode_config; |
| 9810 | int width = plane_state->base.crtc_w; |
| 9811 | int height = plane_state->base.crtc_h; |
| 9812 | |
| 9813 | return width > 0 && width <= config->cursor_width && |
| 9814 | height > 0 && height <= config->cursor_height; |
| 9815 | } |
| 9816 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9817 | 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] | 9818 | { |
| 9819 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9820 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9821 | int src_x, src_y; |
| 9822 | u32 offset; |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9823 | int ret; |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9824 | |
| 9825 | intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation); |
| 9826 | plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation); |
| 9827 | |
Ville Syrjälä | fc3fed5 | 2018-09-18 17:02:43 +0300 | [diff] [blame] | 9828 | ret = intel_plane_check_stride(plane_state); |
| 9829 | if (ret) |
| 9830 | return ret; |
| 9831 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9832 | src_x = plane_state->base.src_x >> 16; |
| 9833 | src_y = plane_state->base.src_y >> 16; |
| 9834 | |
| 9835 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
| 9836 | offset = intel_plane_compute_aligned_offset(&src_x, &src_y, |
| 9837 | plane_state, 0); |
| 9838 | |
| 9839 | if (src_x != 0 || src_y != 0) { |
| 9840 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); |
| 9841 | return -EINVAL; |
| 9842 | } |
| 9843 | |
| 9844 | plane_state->color_plane[0].offset = offset; |
| 9845 | |
| 9846 | return 0; |
| 9847 | } |
| 9848 | |
| 9849 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
| 9850 | struct intel_plane_state *plane_state) |
| 9851 | { |
| 9852 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9853 | int ret; |
| 9854 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9855 | if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
| 9856 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 9857 | return -EINVAL; |
| 9858 | } |
| 9859 | |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9860 | ret = drm_atomic_helper_check_plane_state(&plane_state->base, |
| 9861 | &crtc_state->base, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 9862 | DRM_PLANE_HELPER_NO_SCALING, |
| 9863 | DRM_PLANE_HELPER_NO_SCALING, |
| 9864 | true, true); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9865 | if (ret) |
| 9866 | return ret; |
| 9867 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9868 | if (!plane_state->base.visible) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9869 | return 0; |
| 9870 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 9871 | ret = intel_plane_check_src_coordinates(plane_state); |
| 9872 | if (ret) |
| 9873 | return ret; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9874 | |
Ville Syrjälä | fce8d23 | 2018-09-07 18:24:13 +0300 | [diff] [blame] | 9875 | ret = intel_cursor_check_surface(plane_state); |
| 9876 | if (ret) |
| 9877 | return ret; |
Ville Syrjälä | 1e7b4fd | 2017-03-27 21:55:44 +0300 | [diff] [blame] | 9878 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9879 | return 0; |
| 9880 | } |
| 9881 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 9882 | static unsigned int |
| 9883 | i845_cursor_max_stride(struct intel_plane *plane, |
| 9884 | u32 pixel_format, u64 modifier, |
| 9885 | unsigned int rotation) |
| 9886 | { |
| 9887 | return 2048; |
| 9888 | } |
| 9889 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9890 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 9891 | const struct intel_plane_state *plane_state) |
| 9892 | { |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9893 | return CURSOR_ENABLE | |
| 9894 | CURSOR_GAMMA_ENABLE | |
| 9895 | CURSOR_FORMAT_ARGB | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9896 | CURSOR_STRIDE(plane_state->color_plane[0].stride); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 9897 | } |
| 9898 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9899 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
| 9900 | { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9901 | int width = plane_state->base.crtc_w; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9902 | |
| 9903 | /* |
| 9904 | * 845g/865g are only limited by the width of their cursors, |
| 9905 | * the height is arbitrary up to the precision of the register. |
| 9906 | */ |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 9907 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9908 | } |
| 9909 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 9910 | static int i845_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9911 | struct intel_plane_state *plane_state) |
| 9912 | { |
| 9913 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9914 | int ret; |
| 9915 | |
| 9916 | ret = intel_check_cursor(crtc_state, plane_state); |
| 9917 | if (ret) |
| 9918 | return ret; |
| 9919 | |
| 9920 | /* 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] | 9921 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9922 | return 0; |
| 9923 | |
| 9924 | /* Check for which cursor types we support */ |
| 9925 | if (!i845_cursor_size_ok(plane_state)) { |
| 9926 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 9927 | plane_state->base.crtc_w, |
| 9928 | plane_state->base.crtc_h); |
| 9929 | return -EINVAL; |
| 9930 | } |
| 9931 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 9932 | WARN_ON(plane_state->base.visible && |
| 9933 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 9934 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9935 | switch (fb->pitches[0]) { |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9936 | case 256: |
| 9937 | case 512: |
| 9938 | case 1024: |
| 9939 | case 2048: |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9940 | break; |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 9941 | default: |
| 9942 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", |
| 9943 | fb->pitches[0]); |
| 9944 | return -EINVAL; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9945 | } |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9946 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 9947 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
| 9948 | |
| 9949 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9950 | } |
| 9951 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9952 | static void i845_update_cursor(struct intel_plane *plane, |
| 9953 | const struct intel_crtc_state *crtc_state, |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9954 | const struct intel_plane_state *plane_state) |
| 9955 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 9956 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9957 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
| 9958 | unsigned long irqflags; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9959 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 9960 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 9961 | unsigned int width = plane_state->base.crtc_w; |
| 9962 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9963 | |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 9964 | cntl = plane_state->ctl; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9965 | size = (height << 12) | width; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9966 | |
| 9967 | base = intel_cursor_base(plane_state); |
| 9968 | pos = intel_cursor_position(plane_state); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 9969 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9970 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9971 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 9972 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9973 | /* On these chipsets we can only modify the base/size/stride |
| 9974 | * whilst the cursor is disabled. |
| 9975 | */ |
| 9976 | if (plane->cursor.base != base || |
| 9977 | plane->cursor.size != size || |
| 9978 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9979 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9980 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9981 | I915_WRITE_FW(CURSIZE, size); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9982 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dd584fc | 2017-03-09 17:44:33 +0200 | [diff] [blame] | 9983 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 9984 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 9985 | plane->cursor.base = base; |
| 9986 | plane->cursor.size = size; |
| 9987 | plane->cursor.cntl = cntl; |
| 9988 | } else { |
| 9989 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 9990 | } |
| 9991 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9992 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
| 9993 | } |
| 9994 | |
| 9995 | static void i845_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 9996 | const struct intel_crtc_state *crtc_state) |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 9997 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 9998 | i845_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 9999 | } |
| 10000 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10001 | static bool i845_cursor_get_hw_state(struct intel_plane *plane, |
| 10002 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10003 | { |
| 10004 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10005 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10006 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10007 | bool ret; |
| 10008 | |
| 10009 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10010 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 10011 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10012 | return false; |
| 10013 | |
| 10014 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
| 10015 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10016 | *pipe = PIPE_A; |
| 10017 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10018 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10019 | |
| 10020 | return ret; |
| 10021 | } |
| 10022 | |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 10023 | static unsigned int |
| 10024 | i9xx_cursor_max_stride(struct intel_plane *plane, |
| 10025 | u32 pixel_format, u64 modifier, |
| 10026 | unsigned int rotation) |
| 10027 | { |
| 10028 | return plane->base.dev->mode_config.cursor_width * 4; |
| 10029 | } |
| 10030 | |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10031 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
| 10032 | const struct intel_plane_state *plane_state) |
| 10033 | { |
| 10034 | struct drm_i915_private *dev_priv = |
| 10035 | to_i915(plane_state->base.plane->dev); |
| 10036 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10037 | u32 cntl = 0; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10038 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10039 | if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) |
Ville Syrjälä | e876b78 | 2018-01-30 22:38:05 +0200 | [diff] [blame] | 10040 | cntl |= MCURSOR_TRICKLE_FEED_DISABLE; |
| 10041 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10042 | if (INTEL_GEN(dev_priv) <= 10) { |
| 10043 | cntl |= MCURSOR_GAMMA_ENABLE; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10044 | |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10045 | if (HAS_DDI(dev_priv)) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10046 | cntl |= MCURSOR_PIPE_CSC_ENABLE; |
José Roberto de Souza | c894d63 | 2018-05-18 13:15:47 -0700 | [diff] [blame] | 10047 | } |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10048 | |
Ville Syrjälä | 32ea06b | 2018-01-30 22:38:01 +0200 | [diff] [blame] | 10049 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
| 10050 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10051 | |
| 10052 | switch (plane_state->base.crtc_w) { |
| 10053 | case 64: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10054 | cntl |= MCURSOR_MODE_64_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10055 | break; |
| 10056 | case 128: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10057 | cntl |= MCURSOR_MODE_128_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10058 | break; |
| 10059 | case 256: |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10060 | cntl |= MCURSOR_MODE_256_ARGB_AX; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10061 | break; |
| 10062 | default: |
| 10063 | MISSING_CASE(plane_state->base.crtc_w); |
| 10064 | return 0; |
| 10065 | } |
| 10066 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 10067 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10068 | cntl |= MCURSOR_ROTATE_180; |
Ville Syrjälä | 292889e | 2017-03-17 23:18:01 +0200 | [diff] [blame] | 10069 | |
| 10070 | return cntl; |
| 10071 | } |
| 10072 | |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10073 | 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] | 10074 | { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10075 | struct drm_i915_private *dev_priv = |
| 10076 | to_i915(plane_state->base.plane->dev); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10077 | int width = plane_state->base.crtc_w; |
| 10078 | int height = plane_state->base.crtc_h; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10079 | |
Ville Syrjälä | 3637ecf | 2017-03-27 21:55:40 +0300 | [diff] [blame] | 10080 | if (!intel_cursor_size_ok(plane_state)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10081 | return false; |
| 10082 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10083 | /* Cursor width is limited to a few power-of-two sizes */ |
| 10084 | switch (width) { |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10085 | case 256: |
| 10086 | case 128: |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10087 | case 64: |
| 10088 | break; |
| 10089 | default: |
| 10090 | return false; |
| 10091 | } |
| 10092 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10093 | /* |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10094 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor |
| 10095 | * height from 8 lines up to the cursor width, when the |
| 10096 | * cursor is not rotated. Everything else requires square |
| 10097 | * cursors. |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10098 | */ |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10099 | if (HAS_CUR_FBC(dev_priv) && |
Dave Airlie | a82256b | 2017-05-30 15:25:28 +1000 | [diff] [blame] | 10100 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10101 | if (height < 8 || height > width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10102 | return false; |
| 10103 | } else { |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10104 | if (height != width) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10105 | return false; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10106 | } |
| 10107 | |
| 10108 | return true; |
| 10109 | } |
| 10110 | |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10111 | static int i9xx_check_cursor(struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10112 | struct intel_plane_state *plane_state) |
| 10113 | { |
Ville Syrjälä | eb0f504 | 2018-08-28 17:27:06 +0300 | [diff] [blame] | 10114 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10115 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10116 | const struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10117 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10118 | int ret; |
| 10119 | |
| 10120 | ret = intel_check_cursor(crtc_state, plane_state); |
| 10121 | if (ret) |
| 10122 | return ret; |
| 10123 | |
| 10124 | /* 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] | 10125 | if (!fb) |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10126 | return 0; |
| 10127 | |
| 10128 | /* Check for which cursor types we support */ |
| 10129 | if (!i9xx_cursor_size_ok(plane_state)) { |
| 10130 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 10131 | plane_state->base.crtc_w, |
| 10132 | plane_state->base.crtc_h); |
| 10133 | return -EINVAL; |
| 10134 | } |
| 10135 | |
Ville Syrjälä | df79cf4 | 2018-09-11 18:01:39 +0300 | [diff] [blame] | 10136 | WARN_ON(plane_state->base.visible && |
| 10137 | plane_state->color_plane[0].stride != fb->pitches[0]); |
| 10138 | |
Ville Syrjälä | 1e1bb87 | 2017-03-27 21:55:41 +0300 | [diff] [blame] | 10139 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
| 10140 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", |
| 10141 | fb->pitches[0], plane_state->base.crtc_w); |
| 10142 | return -EINVAL; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 10143 | } |
| 10144 | |
| 10145 | /* |
| 10146 | * There's something wrong with the cursor on CHV pipe C. |
| 10147 | * If it straddles the left edge of the screen then |
| 10148 | * moving it away from the edge or disabling it often |
| 10149 | * results in a pipe underrun, and often that can lead to |
| 10150 | * dead pipe (constant underrun reported, and it scans |
| 10151 | * out just a solid color). To recover from that, the |
| 10152 | * display power well must be turned off and on again. |
| 10153 | * Refuse the put the cursor into that compromised position. |
| 10154 | */ |
| 10155 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && |
| 10156 | plane_state->base.visible && plane_state->base.crtc_x < 0) { |
| 10157 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 10158 | return -EINVAL; |
| 10159 | } |
| 10160 | |
| 10161 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
| 10162 | |
| 10163 | return 0; |
| 10164 | } |
| 10165 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10166 | static void i9xx_update_cursor(struct intel_plane *plane, |
| 10167 | const struct intel_crtc_state *crtc_state, |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10168 | const struct intel_plane_state *plane_state) |
| 10169 | { |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 10170 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10171 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10172 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10173 | unsigned long irqflags; |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10174 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10175 | if (plane_state && plane_state->base.visible) { |
Ville Syrjälä | a0864d5 | 2017-03-23 21:27:09 +0200 | [diff] [blame] | 10176 | cntl = plane_state->ctl; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10177 | |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10178 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
| 10179 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); |
| 10180 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10181 | base = intel_cursor_base(plane_state); |
| 10182 | pos = intel_cursor_position(plane_state); |
| 10183 | } |
| 10184 | |
| 10185 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 10186 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10187 | /* |
| 10188 | * On some platforms writing CURCNTR first will also |
| 10189 | * cause CURPOS to be armed by the CURBASE write. |
| 10190 | * Without the CURCNTR write the CURPOS write would |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10191 | * arm itself. Thus we always update CURCNTR before |
| 10192 | * CURPOS. |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10193 | * |
| 10194 | * On other platforms CURPOS always requires the |
| 10195 | * CURBASE write to arm the update. Additonally |
| 10196 | * a write to any of the cursor register will cancel |
| 10197 | * an already armed cursor update. Thus leaving out |
| 10198 | * the CURBASE write after CURPOS could lead to a |
| 10199 | * cursor that doesn't appear to move, or even change |
| 10200 | * shape. Thus we always write CURBASE. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10201 | * |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10202 | * The other registers are armed by by the CURBASE write |
| 10203 | * except when the plane is getting enabled at which time |
| 10204 | * the CURCNTR write arms the update. |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10205 | */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 10206 | |
| 10207 | if (INTEL_GEN(dev_priv) >= 9) |
| 10208 | skl_write_cursor_wm(plane, crtc_state); |
| 10209 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10210 | if (plane->cursor.base != base || |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 10211 | plane->cursor.size != fbc_ctl || |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10212 | plane->cursor.cntl != cntl) { |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10213 | if (HAS_CUR_FBC(dev_priv)) |
| 10214 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); |
Ville Syrjälä | 83234d1 | 2018-11-14 23:07:17 +0200 | [diff] [blame] | 10215 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10216 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 75343a4 | 2017-03-27 21:55:38 +0300 | [diff] [blame] | 10217 | I915_WRITE_FW(CURBASE(pipe), base); |
| 10218 | |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10219 | plane->cursor.base = base; |
| 10220 | plane->cursor.size = fbc_ctl; |
| 10221 | plane->cursor.cntl = cntl; |
| 10222 | } else { |
| 10223 | I915_WRITE_FW(CURPOS(pipe), pos); |
Ville Syrjälä | 8753d2b | 2017-07-14 18:52:27 +0300 | [diff] [blame] | 10224 | I915_WRITE_FW(CURBASE(pipe), base); |
Ville Syrjälä | e11ffdd | 2017-03-27 21:55:46 +0300 | [diff] [blame] | 10225 | } |
| 10226 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10227 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10228 | } |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10229 | |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 10230 | static void i9xx_disable_cursor(struct intel_plane *plane, |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10231 | const struct intel_crtc_state *crtc_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10232 | { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 10233 | i9xx_update_cursor(plane, crtc_state, NULL); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10234 | } |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 10235 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10236 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane, |
| 10237 | enum pipe *pipe) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10238 | { |
| 10239 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 10240 | enum intel_display_power_domain power_domain; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10241 | intel_wakeref_t wakeref; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10242 | bool ret; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10243 | u32 val; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10244 | |
| 10245 | /* |
| 10246 | * Not 100% correct for planes that can move between pipes, |
| 10247 | * but that's only the case for gen2-3 which don't have any |
| 10248 | * display power wells. |
| 10249 | */ |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10250 | power_domain = POWER_DOMAIN_PIPE(plane->pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10251 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 10252 | if (!wakeref) |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10253 | return false; |
| 10254 | |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10255 | val = I915_READ(CURCNTR(plane->pipe)); |
| 10256 | |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 10257 | ret = val & MCURSOR_MODE; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 10258 | |
| 10259 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
| 10260 | *pipe = plane->pipe; |
| 10261 | else |
| 10262 | *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >> |
| 10263 | MCURSOR_PIPE_SELECT_SHIFT; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10264 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 10265 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 10266 | |
| 10267 | return ret; |
| 10268 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10269 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10270 | /* VESA 640x480x72Hz mode to set on the pipe */ |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10271 | static const struct drm_display_mode load_detect_mode = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10272 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10273 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10274 | }; |
| 10275 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10276 | struct drm_framebuffer * |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10277 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
| 10278 | struct drm_mode_fb_cmd2 *mode_cmd) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10279 | { |
| 10280 | struct intel_framebuffer *intel_fb; |
| 10281 | int ret; |
| 10282 | |
| 10283 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10284 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10285 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10286 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 10287 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10288 | if (ret) |
| 10289 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10290 | |
| 10291 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10292 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10293 | err: |
| 10294 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10295 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10296 | } |
| 10297 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10298 | static int intel_modeset_disable_planes(struct drm_atomic_state *state, |
| 10299 | struct drm_crtc *crtc) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10300 | { |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10301 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10302 | struct drm_plane_state *plane_state; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10303 | int ret, i; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10304 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10305 | ret = drm_atomic_add_affected_planes(state, crtc); |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10306 | if (ret) |
| 10307 | return ret; |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10308 | |
| 10309 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 10310 | if (plane_state->crtc != crtc) |
| 10311 | continue; |
| 10312 | |
| 10313 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 10314 | if (ret) |
| 10315 | return ret; |
| 10316 | |
| 10317 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 10318 | } |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10319 | |
| 10320 | return 0; |
| 10321 | } |
| 10322 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10323 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | bacdcd5 | 2017-05-18 22:38:37 +0300 | [diff] [blame] | 10324 | const struct drm_display_mode *mode, |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10325 | struct intel_load_detect_pipe *old, |
| 10326 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10327 | { |
| 10328 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10329 | struct intel_encoder *intel_encoder = |
| 10330 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10331 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10332 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10333 | struct drm_crtc *crtc = NULL; |
| 10334 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10335 | struct drm_i915_private *dev_priv = to_i915(dev); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10336 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10337 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10338 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10339 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10340 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10341 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10342 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10343 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10344 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10345 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10346 | old->restore_state = NULL; |
| 10347 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10348 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10349 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10350 | /* |
| 10351 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10352 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10353 | * - if the connector already has an assigned crtc, use it (but make |
| 10354 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10355 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10356 | * - try to find the first unused crtc that can drive this connector, |
| 10357 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10358 | */ |
| 10359 | |
| 10360 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10361 | if (connector->state->crtc) { |
| 10362 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10363 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10364 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10365 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10366 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10367 | |
| 10368 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10369 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10370 | } |
| 10371 | |
| 10372 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10373 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10374 | i++; |
| 10375 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10376 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10377 | |
| 10378 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10379 | if (ret) |
| 10380 | goto fail; |
| 10381 | |
| 10382 | if (possible_crtc->state->enable) { |
| 10383 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10384 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10385 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10386 | |
| 10387 | crtc = possible_crtc; |
| 10388 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10389 | } |
| 10390 | |
| 10391 | /* |
| 10392 | * If we didn't find an unused CRTC, don't use any. |
| 10393 | */ |
| 10394 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10395 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Dan Carpenter | f4bf77b | 2017-04-14 22:54:25 +0300 | [diff] [blame] | 10396 | ret = -ENODEV; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10397 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10398 | } |
| 10399 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10400 | found: |
| 10401 | intel_crtc = to_intel_crtc(crtc); |
| 10402 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10403 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10404 | restore_state = drm_atomic_state_alloc(dev); |
| 10405 | if (!state || !restore_state) { |
| 10406 | ret = -ENOMEM; |
| 10407 | goto fail; |
| 10408 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10409 | |
| 10410 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10411 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10412 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10413 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10414 | if (IS_ERR(connector_state)) { |
| 10415 | ret = PTR_ERR(connector_state); |
| 10416 | goto fail; |
| 10417 | } |
| 10418 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10419 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10420 | if (ret) |
| 10421 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10422 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10423 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10424 | if (IS_ERR(crtc_state)) { |
| 10425 | ret = PTR_ERR(crtc_state); |
| 10426 | goto fail; |
| 10427 | } |
| 10428 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10429 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10430 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10431 | if (!mode) |
| 10432 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10433 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10434 | 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] | 10435 | if (ret) |
| 10436 | goto fail; |
| 10437 | |
Ville Syrjälä | 20bdc11 | 2017-12-20 10:35:45 +0100 | [diff] [blame] | 10438 | ret = intel_modeset_disable_planes(state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10439 | if (ret) |
| 10440 | goto fail; |
| 10441 | |
| 10442 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10443 | if (!ret) |
| 10444 | 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] | 10445 | if (!ret) |
| 10446 | ret = drm_atomic_add_affected_planes(restore_state, crtc); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10447 | if (ret) { |
| 10448 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10449 | goto fail; |
| 10450 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10451 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10452 | ret = drm_atomic_commit(state); |
| 10453 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10454 | 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] | 10455 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10456 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10457 | |
| 10458 | old->restore_state = restore_state; |
Chris Wilson | 7abbd11 | 2017-01-19 11:37:49 +0000 | [diff] [blame] | 10459 | drm_atomic_state_put(state); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10460 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10461 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 10462 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10463 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10464 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10465 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 10466 | if (state) { |
| 10467 | drm_atomic_state_put(state); |
| 10468 | state = NULL; |
| 10469 | } |
| 10470 | if (restore_state) { |
| 10471 | drm_atomic_state_put(restore_state); |
| 10472 | restore_state = NULL; |
| 10473 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10474 | |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 10475 | if (ret == -EDEADLK) |
| 10476 | return ret; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10477 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10478 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10479 | } |
| 10480 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10481 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10482 | struct intel_load_detect_pipe *old, |
| 10483 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10484 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10485 | struct intel_encoder *intel_encoder = |
| 10486 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10487 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10488 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10489 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10490 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10491 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10492 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10493 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10494 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10495 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10496 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10497 | |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 10498 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10499 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10500 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 10501 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10502 | } |
| 10503 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10504 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10505 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10506 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10507 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10508 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10509 | |
| 10510 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10511 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 10512 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10513 | return 120000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10514 | else if (!IS_GEN(dev_priv, 2)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10515 | return 96000; |
| 10516 | else |
| 10517 | return 48000; |
| 10518 | } |
| 10519 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10520 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10521 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10522 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10523 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10524 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10525 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10526 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10527 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10528 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 10529 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10530 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10531 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10532 | |
| 10533 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10534 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10535 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10536 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10537 | |
| 10538 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10539 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10540 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10541 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10542 | } else { |
| 10543 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10544 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10545 | } |
| 10546 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 10547 | if (!IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10548 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10549 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10550 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10551 | else |
| 10552 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10553 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10554 | |
| 10555 | switch (dpll & DPLL_MODE_MASK) { |
| 10556 | case DPLLB_MODE_DAC_SERIAL: |
| 10557 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10558 | 5 : 10; |
| 10559 | break; |
| 10560 | case DPLLB_MODE_LVDS: |
| 10561 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10562 | 7 : 14; |
| 10563 | break; |
| 10564 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10565 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10566 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10567 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10568 | } |
| 10569 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 10570 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10571 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10572 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10573 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10574 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10575 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10576 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10577 | |
| 10578 | if (is_lvds) { |
| 10579 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10580 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10581 | |
| 10582 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10583 | clock.p2 = 7; |
| 10584 | else |
| 10585 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10586 | } else { |
| 10587 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10588 | clock.p1 = 2; |
| 10589 | else { |
| 10590 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10591 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10592 | } |
| 10593 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10594 | clock.p2 = 4; |
| 10595 | else |
| 10596 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10597 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10598 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10599 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10600 | } |
| 10601 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10602 | /* |
| 10603 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10604 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10605 | * encoder's get_config() function. |
| 10606 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10607 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10608 | } |
| 10609 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10610 | int intel_dotclock_calculate(int link_freq, |
| 10611 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10612 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10613 | /* |
| 10614 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10615 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10616 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10617 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10618 | * |
| 10619 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10620 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10621 | */ |
| 10622 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10623 | if (!m_n->link_n) |
| 10624 | return 0; |
| 10625 | |
Chris Wilson | 3123698 | 2017-09-13 11:51:53 +0100 | [diff] [blame] | 10626 | 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] | 10627 | } |
| 10628 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10629 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10630 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10631 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10632 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10633 | |
| 10634 | /* read out port_clock from the DPLL */ |
| 10635 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10636 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10637 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10638 | * In case there is an active pipe without active ports, |
| 10639 | * we may need some idea for the dotclock anyway. |
| 10640 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10641 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10642 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10643 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10644 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10645 | } |
| 10646 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10647 | /* Returns the currently programmed mode of the given encoder. */ |
| 10648 | struct drm_display_mode * |
| 10649 | intel_encoder_current_mode(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10650 | { |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10651 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 10652 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10653 | struct drm_display_mode *mode; |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10654 | struct intel_crtc *crtc; |
| 10655 | enum pipe pipe; |
| 10656 | |
| 10657 | if (!encoder->get_hw_state(encoder, &pipe)) |
| 10658 | return NULL; |
| 10659 | |
| 10660 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10661 | |
| 10662 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10663 | if (!mode) |
| 10664 | return NULL; |
| 10665 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10666 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 10667 | if (!crtc_state) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10668 | kfree(mode); |
| 10669 | return NULL; |
| 10670 | } |
| 10671 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10672 | crtc_state->base.crtc = &crtc->base; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10673 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10674 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
| 10675 | kfree(crtc_state); |
| 10676 | kfree(mode); |
| 10677 | return NULL; |
| 10678 | } |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10679 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10680 | encoder->get_config(encoder, crtc_state); |
Ville Syrjälä | e30a154 | 2016-04-01 18:37:25 +0300 | [diff] [blame] | 10681 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10682 | intel_mode_from_pipe_config(mode, crtc_state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10683 | |
Ville Syrjälä | de33081 | 2017-10-09 19:19:50 +0300 | [diff] [blame] | 10684 | kfree(crtc_state); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10685 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10686 | return mode; |
| 10687 | } |
| 10688 | |
| 10689 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10690 | { |
| 10691 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10692 | |
| 10693 | drm_crtc_cleanup(crtc); |
| 10694 | kfree(intel_crtc); |
| 10695 | } |
| 10696 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10697 | /** |
| 10698 | * intel_wm_need_update - Check whether watermarks need updating |
Chris Wilson | 6bf1981 | 2018-12-31 14:35:05 +0000 | [diff] [blame] | 10699 | * @cur: current plane state |
| 10700 | * @new: new plane state |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10701 | * |
| 10702 | * Check current plane state versus the new one to determine whether |
| 10703 | * watermarks need to be recalculated. |
| 10704 | * |
| 10705 | * Returns true or false. |
| 10706 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10707 | static bool intel_wm_need_update(struct intel_plane_state *cur, |
| 10708 | struct intel_plane_state *new) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10709 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10710 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10711 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10712 | return true; |
| 10713 | |
| 10714 | if (!cur->base.fb || !new->base.fb) |
| 10715 | return false; |
| 10716 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 10717 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10718 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10719 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 10720 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 10721 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 10722 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10723 | return true; |
| 10724 | |
| 10725 | return false; |
| 10726 | } |
| 10727 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10728 | static bool needs_scaling(const struct intel_plane_state *state) |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10729 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10730 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 10731 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 10732 | int dst_w = drm_rect_width(&state->base.dst); |
| 10733 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 10734 | |
| 10735 | return (src_w != dst_w || src_h != dst_h); |
| 10736 | } |
| 10737 | |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10738 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
| 10739 | struct drm_crtc_state *crtc_state, |
| 10740 | const struct intel_plane_state *old_plane_state, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10741 | struct drm_plane_state *plane_state) |
| 10742 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10743 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10744 | struct drm_crtc *crtc = crtc_state->crtc; |
| 10745 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10746 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10747 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 10748 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10749 | bool mode_changed = needs_modeset(crtc_state); |
Ville Syrjälä | b2b5550 | 2017-08-23 18:22:23 +0300 | [diff] [blame] | 10750 | bool was_crtc_enabled = old_crtc_state->base.active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10751 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10752 | bool turn_off, turn_on, visible, was_visible; |
| 10753 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 10754 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10755 | |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10756 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10757 | ret = skl_update_scaler_plane( |
| 10758 | to_intel_crtc_state(crtc_state), |
| 10759 | to_intel_plane_state(plane_state)); |
| 10760 | if (ret) |
| 10761 | return ret; |
| 10762 | } |
| 10763 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10764 | was_visible = old_plane_state->base.visible; |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10765 | visible = plane_state->visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10766 | |
| 10767 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 10768 | was_visible = false; |
| 10769 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10770 | /* |
| 10771 | * Visibility is calculated as if the crtc was on, but |
| 10772 | * after scaler setup everything depends on it being off |
| 10773 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 10774 | * |
| 10775 | * FIXME this is wrong for watermarks. Watermarks should also |
| 10776 | * be computed as if the pipe would be active. Perhaps move |
| 10777 | * per-plane wm computation to the .check_plane() hook, and |
| 10778 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 10779 | */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10780 | if (!is_crtc_enabled) { |
Maarten Lankhorst | 1d4258d | 2017-01-12 10:43:45 +0100 | [diff] [blame] | 10781 | plane_state->visible = visible = false; |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10782 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
| 10783 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10784 | |
| 10785 | if (!was_visible && !visible) |
| 10786 | return 0; |
| 10787 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10788 | if (fb != old_plane_state->base.fb) |
| 10789 | pipe_config->fb_changed = true; |
| 10790 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10791 | turn_off = was_visible && (!visible || mode_changed); |
| 10792 | turn_on = visible && (!was_visible || mode_changed); |
| 10793 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10794 | 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] | 10795 | intel_crtc->base.base.id, intel_crtc->base.name, |
| 10796 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10797 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10798 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10799 | 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] | 10800 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 10801 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10802 | turn_off, turn_on, mode_changed); |
| 10803 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10804 | if (turn_on) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10805 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10806 | pipe_config->update_wm_pre = true; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10807 | |
| 10808 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10809 | if (plane->id != PLANE_CURSOR) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 10810 | pipe_config->disable_cxsr = true; |
| 10811 | } else if (turn_off) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10812 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10813 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 10814 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10815 | /* must disable cxsr around plane enable/disable */ |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10816 | if (plane->id != PLANE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 10817 | pipe_config->disable_cxsr = true; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 10818 | } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state), |
| 10819 | to_intel_plane_state(plane_state))) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 10820 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
Ville Syrjälä | b4ede6d | 2017-03-02 19:15:01 +0200 | [diff] [blame] | 10821 | /* FIXME bollocks */ |
| 10822 | pipe_config->update_wm_pre = true; |
| 10823 | pipe_config->update_wm_post = true; |
| 10824 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 10825 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10826 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 10827 | if (visible || was_visible) |
Ville Syrjälä | e9728bd | 2017-03-02 19:14:51 +0200 | [diff] [blame] | 10828 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10829 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10830 | /* |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10831 | * ILK/SNB DVSACNTR/Sprite Enable |
| 10832 | * IVB SPR_CTL/Sprite Enable |
| 10833 | * "When in Self Refresh Big FIFO mode, a write to enable the |
| 10834 | * plane will be internally buffered and delayed while Big FIFO |
| 10835 | * mode is exiting." |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10836 | * |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10837 | * Which means that enabling the sprite can take an extra frame |
| 10838 | * when we start in big FIFO mode (LP1+). Thus we need to drop |
| 10839 | * down to LP0 and wait for vblank in order to make sure the |
| 10840 | * sprite gets enabled on the next vblank after the register write. |
| 10841 | * Doing otherwise would risk enabling the sprite one frame after |
| 10842 | * we've already signalled flip completion. We can resume LP1+ |
| 10843 | * once the sprite has been enabled. |
| 10844 | * |
| 10845 | * |
| 10846 | * WaCxSRDisabledForSpriteScaling:ivb |
| 10847 | * IVB SPR_SCALE/Scaling Enable |
| 10848 | * "Low Power watermarks must be disabled for at least one |
| 10849 | * frame before enabling sprite scaling, and kept disabled |
| 10850 | * until sprite scaling is disabled." |
| 10851 | * |
| 10852 | * ILK/SNB DVSASCALE/Scaling Enable |
| 10853 | * "When in Self Refresh Big FIFO mode, scaling enable will be |
| 10854 | * masked off while Big FIFO mode is exiting." |
| 10855 | * |
| 10856 | * Despite the w/a only being listed for IVB we assume that |
| 10857 | * the ILK/SNB note has similar ramifications, hence we apply |
| 10858 | * the w/a on all three platforms. |
Juha-Pekka Heikkila | d8af327 | 2018-12-20 13:26:08 +0200 | [diff] [blame] | 10859 | * |
| 10860 | * With experimental results seems this is needed also for primary |
| 10861 | * plane, not only sprite plane. |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10862 | */ |
Juha-Pekka Heikkila | d8af327 | 2018-12-20 13:26:08 +0200 | [diff] [blame] | 10863 | if (plane->id != PLANE_CURSOR && |
Lucas De Marchi | f3ce44a | 2018-12-12 10:10:44 -0800 | [diff] [blame] | 10864 | (IS_GEN_RANGE(dev_priv, 5, 6) || |
Ville Syrjälä | 8e7a442 | 2018-10-04 15:15:27 +0300 | [diff] [blame] | 10865 | IS_IVYBRIDGE(dev_priv)) && |
| 10866 | (turn_on || (!needs_scaling(old_plane_state) && |
| 10867 | needs_scaling(to_intel_plane_state(plane_state))))) |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 10868 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10869 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 10870 | return 0; |
| 10871 | } |
| 10872 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10873 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10874 | const struct intel_encoder *b) |
| 10875 | { |
| 10876 | /* masks could be asymmetric, so check both ways */ |
| 10877 | return a == b || (a->cloneable & (1 << b->type) && |
| 10878 | b->cloneable & (1 << a->type)); |
| 10879 | } |
| 10880 | |
| 10881 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 10882 | struct intel_crtc *crtc, |
| 10883 | struct intel_encoder *encoder) |
| 10884 | { |
| 10885 | struct intel_encoder *source_encoder; |
| 10886 | struct drm_connector *connector; |
| 10887 | struct drm_connector_state *connector_state; |
| 10888 | int i; |
| 10889 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 10890 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10891 | if (connector_state->crtc != &crtc->base) |
| 10892 | continue; |
| 10893 | |
| 10894 | source_encoder = |
| 10895 | to_intel_encoder(connector_state->best_encoder); |
| 10896 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10897 | return false; |
| 10898 | } |
| 10899 | |
| 10900 | return true; |
| 10901 | } |
| 10902 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10903 | static int icl_add_linked_planes(struct intel_atomic_state *state) |
| 10904 | { |
| 10905 | struct intel_plane *plane, *linked; |
| 10906 | struct intel_plane_state *plane_state, *linked_plane_state; |
| 10907 | int i; |
| 10908 | |
| 10909 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10910 | linked = plane_state->linked_plane; |
| 10911 | |
| 10912 | if (!linked) |
| 10913 | continue; |
| 10914 | |
| 10915 | linked_plane_state = intel_atomic_get_plane_state(state, linked); |
| 10916 | if (IS_ERR(linked_plane_state)) |
| 10917 | return PTR_ERR(linked_plane_state); |
| 10918 | |
| 10919 | WARN_ON(linked_plane_state->linked_plane != plane); |
| 10920 | WARN_ON(linked_plane_state->slave == plane_state->slave); |
| 10921 | } |
| 10922 | |
| 10923 | return 0; |
| 10924 | } |
| 10925 | |
| 10926 | static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state) |
| 10927 | { |
| 10928 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 10929 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 10930 | struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state); |
| 10931 | struct intel_plane *plane, *linked; |
| 10932 | struct intel_plane_state *plane_state; |
| 10933 | int i; |
| 10934 | |
| 10935 | if (INTEL_GEN(dev_priv) < 11) |
| 10936 | return 0; |
| 10937 | |
| 10938 | /* |
| 10939 | * Destroy all old plane links and make the slave plane invisible |
| 10940 | * in the crtc_state->active_planes mask. |
| 10941 | */ |
| 10942 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10943 | if (plane->pipe != crtc->pipe || !plane_state->linked_plane) |
| 10944 | continue; |
| 10945 | |
| 10946 | plane_state->linked_plane = NULL; |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 10947 | if (plane_state->slave && !plane_state->base.visible) { |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10948 | crtc_state->active_planes &= ~BIT(plane->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 10949 | crtc_state->update_planes |= BIT(plane->id); |
| 10950 | } |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10951 | |
| 10952 | plane_state->slave = false; |
| 10953 | } |
| 10954 | |
| 10955 | if (!crtc_state->nv12_planes) |
| 10956 | return 0; |
| 10957 | |
| 10958 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 10959 | struct intel_plane_state *linked_state = NULL; |
| 10960 | |
| 10961 | if (plane->pipe != crtc->pipe || |
| 10962 | !(crtc_state->nv12_planes & BIT(plane->id))) |
| 10963 | continue; |
| 10964 | |
| 10965 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) { |
| 10966 | if (!icl_is_nv12_y_plane(linked->id)) |
| 10967 | continue; |
| 10968 | |
| 10969 | if (crtc_state->active_planes & BIT(linked->id)) |
| 10970 | continue; |
| 10971 | |
| 10972 | linked_state = intel_atomic_get_plane_state(state, linked); |
| 10973 | if (IS_ERR(linked_state)) |
| 10974 | return PTR_ERR(linked_state); |
| 10975 | |
| 10976 | break; |
| 10977 | } |
| 10978 | |
| 10979 | if (!linked_state) { |
| 10980 | DRM_DEBUG_KMS("Need %d free Y planes for NV12\n", |
| 10981 | hweight8(crtc_state->nv12_planes)); |
| 10982 | |
| 10983 | return -EINVAL; |
| 10984 | } |
| 10985 | |
| 10986 | plane_state->linked_plane = linked; |
| 10987 | |
| 10988 | linked_state->slave = true; |
| 10989 | linked_state->linked_plane = plane; |
| 10990 | crtc_state->active_planes |= BIT(linked->id); |
Ville Syrjälä | afbd8a7 | 2018-11-27 18:37:42 +0200 | [diff] [blame] | 10991 | crtc_state->update_planes |= BIT(linked->id); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 10992 | DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name); |
| 10993 | } |
| 10994 | |
| 10995 | return 0; |
| 10996 | } |
| 10997 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 10998 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 10999 | struct drm_crtc_state *crtc_state) |
| 11000 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11001 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11002 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11003 | struct intel_crtc_state *pipe_config = |
| 11004 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11005 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11006 | bool mode_changed = needs_modeset(crtc_state); |
| 11007 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11008 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11009 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 11010 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11011 | if (mode_changed && crtc_state->enable && |
| 11012 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11013 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11014 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11015 | pipe_config); |
| 11016 | if (ret) |
| 11017 | return ret; |
| 11018 | } |
| 11019 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11020 | if (crtc_state->color_mgmt_changed) { |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 11021 | ret = intel_color_check(pipe_config); |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11022 | if (ret) |
| 11023 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 11024 | |
| 11025 | /* |
| 11026 | * Changing color management on Intel hardware is |
| 11027 | * handled as part of planes update. |
| 11028 | */ |
| 11029 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11030 | } |
| 11031 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11032 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11033 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 11034 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11035 | if (ret) { |
| 11036 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11037 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11038 | } |
| 11039 | } |
| 11040 | |
Ville Syrjälä | f255c62 | 2018-11-08 17:10:13 +0200 | [diff] [blame] | 11041 | if (dev_priv->display.compute_intermediate_wm) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11042 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 11043 | return 0; |
| 11044 | |
| 11045 | /* |
| 11046 | * Calculate 'intermediate' watermarks that satisfy both the |
| 11047 | * old state and the new state. We can program these |
| 11048 | * immediately. |
| 11049 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 11050 | ret = dev_priv->display.compute_intermediate_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11051 | if (ret) { |
| 11052 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 11053 | return ret; |
| 11054 | } |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11055 | } |
| 11056 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11057 | if (INTEL_GEN(dev_priv) >= 9) { |
Hans de Goede | 2c5c415 | 2018-12-17 15:19:03 +0100 | [diff] [blame] | 11058 | if (mode_changed || pipe_config->update_pipe) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11059 | ret = skl_update_scaler_crtc(pipe_config); |
| 11060 | |
| 11061 | if (!ret) |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 11062 | ret = icl_check_nv12_planes(pipe_config); |
| 11063 | if (!ret) |
Mahesh Kumar | 73b0ca8 | 2017-05-26 20:45:46 +0530 | [diff] [blame] | 11064 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, |
| 11065 | pipe_config); |
| 11066 | if (!ret) |
Ander Conselvan de Oliveira | 6ebc692 | 2017-02-23 09:15:59 +0200 | [diff] [blame] | 11067 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11068 | pipe_config); |
| 11069 | } |
| 11070 | |
Maarten Lankhorst | 24f2845 | 2017-11-22 19:39:01 +0100 | [diff] [blame] | 11071 | if (HAS_IPS(dev_priv)) |
| 11072 | pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config); |
| 11073 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11074 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11075 | } |
| 11076 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11077 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11078 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11079 | }; |
| 11080 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11081 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11082 | { |
| 11083 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11084 | struct drm_connector_list_iter conn_iter; |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11085 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11086 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11087 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11088 | if (connector->base.state->crtc) |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11089 | drm_connector_put(&connector->base); |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11090 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11091 | if (connector->base.encoder) { |
| 11092 | connector->base.state->best_encoder = |
| 11093 | connector->base.encoder; |
| 11094 | connector->base.state->crtc = |
| 11095 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 11096 | |
Thomas Zimmermann | ef196b5 | 2018-06-18 13:01:50 +0200 | [diff] [blame] | 11097 | drm_connector_get(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11098 | } else { |
| 11099 | connector->base.state->best_encoder = NULL; |
| 11100 | connector->base.state->crtc = NULL; |
| 11101 | } |
| 11102 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 11103 | drm_connector_list_iter_end(&conn_iter); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11104 | } |
| 11105 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11106 | static int |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11107 | compute_sink_pipe_bpp(const struct drm_connector_state *conn_state, |
| 11108 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11109 | { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11110 | struct drm_connector *connector = conn_state->connector; |
| 11111 | const struct drm_display_info *info = &connector->display_info; |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11112 | int bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11113 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11114 | switch (conn_state->max_bpc) { |
| 11115 | case 6 ... 7: |
| 11116 | bpp = 6 * 3; |
| 11117 | break; |
| 11118 | case 8 ... 9: |
| 11119 | bpp = 8 * 3; |
| 11120 | break; |
| 11121 | case 10 ... 11: |
| 11122 | bpp = 10 * 3; |
| 11123 | break; |
| 11124 | case 12: |
| 11125 | bpp = 12 * 3; |
| 11126 | break; |
| 11127 | default: |
| 11128 | return -EINVAL; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11129 | } |
| 11130 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11131 | if (bpp < pipe_config->pipe_bpp) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11132 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of " |
| 11133 | "EDID bpp %d, requested bpp %d, max platform bpp %d\n", |
| 11134 | connector->base.id, connector->name, |
| 11135 | bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc, |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11136 | pipe_config->pipe_bpp); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11137 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11138 | pipe_config->pipe_bpp = bpp; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11139 | } |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11140 | |
Radhakrishna Sripada | f1a1217 | 2018-10-22 18:44:00 -0700 | [diff] [blame] | 11141 | return 0; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11142 | } |
| 11143 | |
| 11144 | static int |
| 11145 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11146 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 11147 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11148 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11149 | struct drm_atomic_state *state = pipe_config->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11150 | struct drm_connector *connector; |
| 11151 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11152 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11153 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11154 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 11155 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11156 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11157 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 11158 | bpp = 12*3; |
| 11159 | else |
| 11160 | bpp = 8*3; |
| 11161 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11162 | pipe_config->pipe_bpp = bpp; |
| 11163 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11164 | /* Clamp display bpp to connector max bpp */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11165 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11166 | int ret; |
| 11167 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11168 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 11169 | continue; |
| 11170 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11171 | ret = compute_sink_pipe_bpp(connector_state, pipe_config); |
| 11172 | if (ret) |
| 11173 | return ret; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11174 | } |
| 11175 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11176 | return 0; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11177 | } |
| 11178 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11179 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 11180 | { |
| 11181 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 11182 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 11183 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 11184 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 11185 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 11186 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 11187 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 11188 | } |
| 11189 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11190 | static inline void |
| 11191 | 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] | 11192 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11193 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11194 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 11195 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11196 | m_n->gmch_m, m_n->gmch_n, |
| 11197 | m_n->link_m, m_n->link_n, m_n->tu); |
| 11198 | } |
| 11199 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11200 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
| 11201 | |
| 11202 | static const char * const output_type_str[] = { |
| 11203 | OUTPUT_TYPE(UNUSED), |
| 11204 | OUTPUT_TYPE(ANALOG), |
| 11205 | OUTPUT_TYPE(DVO), |
| 11206 | OUTPUT_TYPE(SDVO), |
| 11207 | OUTPUT_TYPE(LVDS), |
| 11208 | OUTPUT_TYPE(TVOUT), |
| 11209 | OUTPUT_TYPE(HDMI), |
| 11210 | OUTPUT_TYPE(DP), |
| 11211 | OUTPUT_TYPE(EDP), |
| 11212 | OUTPUT_TYPE(DSI), |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11213 | OUTPUT_TYPE(DDI), |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11214 | OUTPUT_TYPE(DP_MST), |
| 11215 | }; |
| 11216 | |
| 11217 | #undef OUTPUT_TYPE |
| 11218 | |
| 11219 | static void snprintf_output_types(char *buf, size_t len, |
| 11220 | unsigned int output_types) |
| 11221 | { |
| 11222 | char *str = buf; |
| 11223 | int i; |
| 11224 | |
| 11225 | str[0] = '\0'; |
| 11226 | |
| 11227 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { |
| 11228 | int r; |
| 11229 | |
| 11230 | if ((output_types & BIT(i)) == 0) |
| 11231 | continue; |
| 11232 | |
| 11233 | r = snprintf(str, len, "%s%s", |
| 11234 | str != buf ? "," : "", output_type_str[i]); |
| 11235 | if (r >= len) |
| 11236 | break; |
| 11237 | str += r; |
| 11238 | len -= r; |
| 11239 | |
| 11240 | output_types &= ~BIT(i); |
| 11241 | } |
| 11242 | |
| 11243 | WARN_ON_ONCE(output_types != 0); |
| 11244 | } |
| 11245 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11246 | static const char * const output_format_str[] = { |
| 11247 | [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid", |
| 11248 | [INTEL_OUTPUT_FORMAT_RGB] = "RGB", |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11249 | [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0", |
Shashank Sharma | 8c79f84 | 2018-10-12 11:53:09 +0530 | [diff] [blame] | 11250 | [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4", |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11251 | }; |
| 11252 | |
| 11253 | static const char *output_formats(enum intel_output_format format) |
| 11254 | { |
Shashank Sharma | 33b7f3e | 2018-10-12 11:53:08 +0530 | [diff] [blame] | 11255 | if (format >= ARRAY_SIZE(output_format_str)) |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11256 | format = INTEL_OUTPUT_FORMAT_INVALID; |
| 11257 | return output_format_str[format]; |
| 11258 | } |
| 11259 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11260 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11261 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11262 | const char *context) |
| 11263 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11264 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11265 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11266 | struct drm_plane *plane; |
| 11267 | struct intel_plane *intel_plane; |
| 11268 | struct intel_plane_state *state; |
| 11269 | struct drm_framebuffer *fb; |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11270 | char buf[64]; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11271 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 11272 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 11273 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11274 | |
Ville Syrjälä | 40b2be4 | 2017-10-10 15:11:59 +0300 | [diff] [blame] | 11275 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
| 11276 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", |
| 11277 | buf, pipe_config->output_types); |
| 11278 | |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11279 | DRM_DEBUG_KMS("output format: %s\n", |
| 11280 | output_formats(pipe_config->output_format)); |
| 11281 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11282 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 11283 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11284 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11285 | |
| 11286 | if (pipe_config->has_pch_encoder) |
| 11287 | intel_dump_m_n_config(pipe_config, "fdi", |
| 11288 | pipe_config->fdi_lanes, |
| 11289 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11290 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11291 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 11292 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 11293 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 11294 | if (pipe_config->has_drrs) |
| 11295 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 11296 | pipe_config->lane_count, |
| 11297 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 11298 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11299 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11300 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11301 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 11302 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11303 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11304 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11305 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11306 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 11307 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11308 | 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] | 11309 | pipe_config->port_clock, |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11310 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
| 11311 | pipe_config->pixel_rate); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11312 | |
| 11313 | if (INTEL_GEN(dev_priv) >= 9) |
| 11314 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 11315 | crtc->num_scalers, |
| 11316 | pipe_config->scaler_state.scaler_users, |
| 11317 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11318 | |
| 11319 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 11320 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 11321 | pipe_config->gmch_pfit.control, |
| 11322 | pipe_config->gmch_pfit.pgm_ratios, |
| 11323 | pipe_config->gmch_pfit.lvds_border_bits); |
| 11324 | else |
| 11325 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 11326 | pipe_config->pch_pfit.pos, |
| 11327 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 11328 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 11329 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 11330 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 11331 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11332 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 11333 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 11334 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11335 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 11336 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11337 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11338 | intel_plane = to_intel_plane(plane); |
| 11339 | if (intel_plane->pipe != crtc->pipe) |
| 11340 | continue; |
| 11341 | |
| 11342 | state = to_intel_plane_state(plane->state); |
| 11343 | fb = state->base.fb; |
| 11344 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 11345 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 11346 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11347 | continue; |
| 11348 | } |
| 11349 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11350 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 11351 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 11352 | fb->base.id, fb->width, fb->height, |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 11353 | drm_get_format_name(fb->format->format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 11354 | if (INTEL_GEN(dev_priv) >= 9) |
| 11355 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 11356 | state->scaler_id, |
| 11357 | state->base.src.x1 >> 16, |
| 11358 | state->base.src.y1 >> 16, |
| 11359 | drm_rect_width(&state->base.src) >> 16, |
| 11360 | drm_rect_height(&state->base.src) >> 16, |
| 11361 | state->base.dst.x1, state->base.dst.y1, |
| 11362 | drm_rect_width(&state->base.dst), |
| 11363 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 11364 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11365 | } |
| 11366 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11367 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11368 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11369 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11370 | struct drm_connector *connector; |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11371 | struct drm_connector_list_iter conn_iter; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11372 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11373 | unsigned int used_mst_ports = 0; |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11374 | bool ret = true; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11375 | |
| 11376 | /* |
| 11377 | * Walk the connector list instead of the encoder |
| 11378 | * list to detect the problem on ddi platforms |
| 11379 | * where there's just one encoder per digital port. |
| 11380 | */ |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11381 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 11382 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11383 | struct drm_connector_state *connector_state; |
| 11384 | struct intel_encoder *encoder; |
| 11385 | |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 11386 | connector_state = drm_atomic_get_new_connector_state(state, connector); |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 11387 | if (!connector_state) |
| 11388 | connector_state = connector->state; |
| 11389 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 11390 | if (!connector_state->best_encoder) |
| 11391 | continue; |
| 11392 | |
| 11393 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11394 | |
| 11395 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11396 | |
| 11397 | switch (encoder->type) { |
| 11398 | unsigned int port_mask; |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11399 | case INTEL_OUTPUT_DDI: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 11400 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11401 | break; |
Gustavo A. R. Silva | f0d759f | 2018-06-28 17:35:41 -0500 | [diff] [blame] | 11402 | /* else: fall through */ |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 11403 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11404 | case INTEL_OUTPUT_HDMI: |
| 11405 | case INTEL_OUTPUT_EDP: |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11406 | port_mask = 1 << encoder->port; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11407 | |
| 11408 | /* the same port mustn't appear more than once */ |
| 11409 | if (used_ports & port_mask) |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11410 | ret = false; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11411 | |
| 11412 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11413 | break; |
| 11414 | case INTEL_OUTPUT_DP_MST: |
| 11415 | used_mst_ports |= |
Ville Syrjälä | 8f4f279 | 2017-11-09 17:24:34 +0200 | [diff] [blame] | 11416 | 1 << encoder->port; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11417 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11418 | default: |
| 11419 | break; |
| 11420 | } |
| 11421 | } |
Gustavo Padovan | 2fd96b4 | 2017-05-11 16:10:44 -0300 | [diff] [blame] | 11422 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11423 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 11424 | /* can't mix MST and SST/HDMI on the same port */ |
| 11425 | if (used_ports & used_mst_ports) |
| 11426 | return false; |
| 11427 | |
Maarten Lankhorst | bd67a8c | 2018-02-15 10:14:25 +0100 | [diff] [blame] | 11428 | return ret; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 11429 | } |
| 11430 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11431 | static void |
| 11432 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 11433 | { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11434 | struct drm_i915_private *dev_priv = |
| 11435 | to_i915(crtc_state->base.crtc->dev); |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11436 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11437 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11438 | struct intel_shared_dpll *shared_dpll; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11439 | struct intel_crtc_wm_state wm_state; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11440 | bool force_thru, ips_force_disable; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11441 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 11442 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 11443 | * kzalloc'd. Code that depends on any field being zero should be |
| 11444 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 11445 | * only fields that are know to not cause problems are preserved. */ |
| 11446 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11447 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11448 | shared_dpll = crtc_state->shared_dpll; |
| 11449 | dpll_hw_state = crtc_state->dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11450 | force_thru = crtc_state->pch_pfit.force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11451 | ips_force_disable = crtc_state->ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11452 | if (IS_G4X(dev_priv) || |
| 11453 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11454 | wm_state = crtc_state->wm; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11455 | |
Chris Wilson | d2fa80a | 2017-03-03 15:46:44 +0000 | [diff] [blame] | 11456 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
| 11457 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); |
| 11458 | memset(&crtc_state->base + 1, 0, |
| 11459 | sizeof(*crtc_state) - sizeof(crtc_state->base)); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11460 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 11461 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 11462 | crtc_state->shared_dpll = shared_dpll; |
| 11463 | crtc_state->dpll_hw_state = dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 11464 | crtc_state->pch_pfit.force_thru = force_thru; |
Ville Syrjälä | 6e64462 | 2017-08-17 17:55:09 +0300 | [diff] [blame] | 11465 | crtc_state->ips_force_disable = ips_force_disable; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 11466 | if (IS_G4X(dev_priv) || |
| 11467 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 11468 | crtc_state->wm = wm_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11469 | } |
| 11470 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 11471 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11472 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11473 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11474 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 11475 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11476 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 11477 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11478 | struct drm_connector_state *connector_state; |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11479 | int base_bpp, ret; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11480 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11481 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11482 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11483 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11484 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 11485 | pipe_config->cpu_transcoder = |
| 11486 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11487 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11488 | /* |
| 11489 | * Sanitize sync polarity flags based on requested ones. If neither |
| 11490 | * positive or negative polarity is requested, treat this as meaning |
| 11491 | * negative polarity. |
| 11492 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11493 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11494 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11495 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11496 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11497 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11498 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11499 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 11500 | |
Ville Syrjälä | bcce8d8 | 2018-11-07 23:35:22 +0200 | [diff] [blame] | 11501 | ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 11502 | pipe_config); |
| 11503 | if (ret) |
| 11504 | return ret; |
| 11505 | |
| 11506 | base_bpp = pipe_config->pipe_bpp; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11507 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11508 | /* |
| 11509 | * Determine the real pipe dimensions. Note that stereo modes can |
| 11510 | * increase the actual pipe size due to the frame doubling and |
| 11511 | * insertion of additional space for blanks between the frame. This |
| 11512 | * is stored in the crtc timings. We use the requested mode to do this |
| 11513 | * computation to clearly distinguish it from the adjusted mode, which |
| 11514 | * can be changed by the connectors in the below retry loop. |
| 11515 | */ |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 11516 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 11517 | &pipe_config->pipe_src_w, |
| 11518 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 11519 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11520 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11521 | if (connector_state->crtc != crtc) |
| 11522 | continue; |
| 11523 | |
| 11524 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11525 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11526 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 11527 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11528 | return -EINVAL; |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 11529 | } |
| 11530 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11531 | /* |
| 11532 | * Determine output_types before calling the .compute_config() |
| 11533 | * hooks so that the hooks can use this information safely. |
| 11534 | */ |
Ville Syrjälä | 7e732ca | 2017-10-27 22:31:24 +0300 | [diff] [blame] | 11535 | if (encoder->compute_output_type) |
| 11536 | pipe_config->output_types |= |
| 11537 | BIT(encoder->compute_output_type(encoder, pipe_config, |
| 11538 | connector_state)); |
| 11539 | else |
| 11540 | pipe_config->output_types |= BIT(encoder->type); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11541 | } |
| 11542 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11543 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11544 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11545 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 11546 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11547 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11548 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11549 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 11550 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 11551 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11552 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 11553 | * adjust it according to limitations or connector properties, and also |
| 11554 | * a chance to reject the mode entirely. |
| 11555 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 11556 | 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] | 11557 | if (connector_state->crtc != crtc) |
| 11558 | continue; |
| 11559 | |
| 11560 | encoder = to_intel_encoder(connector_state->best_encoder); |
Lyude Paul | 204474a | 2019-01-15 15:08:00 -0500 | [diff] [blame] | 11561 | ret = encoder->compute_config(encoder, pipe_config, |
| 11562 | connector_state); |
| 11563 | if (ret < 0) { |
| 11564 | if (ret != -EDEADLK) |
| 11565 | DRM_DEBUG_KMS("Encoder config failure: %d\n", |
| 11566 | ret); |
| 11567 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11568 | } |
| 11569 | } |
| 11570 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11571 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 11572 | * done afterwards in case the encoder adjusts the mode. */ |
| 11573 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11574 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11575 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 11576 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 11577 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 11578 | if (ret == -EDEADLK) |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11579 | return ret; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11580 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11581 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11582 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11583 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11584 | |
| 11585 | if (ret == RETRY) { |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11586 | if (WARN(!retry, "loop in pipe configuration computation\n")) |
| 11587 | return -EINVAL; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 11588 | |
| 11589 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 11590 | retry = false; |
| 11591 | goto encoder_retry; |
| 11592 | } |
| 11593 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 11594 | /* Dithering seems to not pass-through bits correctly when it should, so |
Manasi Navare | 611032b | 2017-01-24 08:21:49 -0800 | [diff] [blame] | 11595 | * only enable it on 6bpc panels and when its not a compliance |
| 11596 | * test requesting 6bpc video pattern. |
| 11597 | */ |
| 11598 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && |
| 11599 | !pipe_config->dither_force_disable; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 11600 | 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] | 11601 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11602 | |
Ville Syrjälä | d26592c | 2018-11-07 23:35:21 +0200 | [diff] [blame] | 11603 | return 0; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11604 | } |
| 11605 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11606 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11607 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11608 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11609 | |
| 11610 | if (clock1 == clock2) |
| 11611 | return true; |
| 11612 | |
| 11613 | if (!clock1 || !clock2) |
| 11614 | return false; |
| 11615 | |
| 11616 | diff = abs(clock1 - clock2); |
| 11617 | |
| 11618 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11619 | return true; |
| 11620 | |
| 11621 | return false; |
| 11622 | } |
| 11623 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11624 | static bool |
| 11625 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 11626 | unsigned int m2, unsigned int n2, |
| 11627 | bool exact) |
| 11628 | { |
| 11629 | if (m == m2 && n == n2) |
| 11630 | return true; |
| 11631 | |
| 11632 | if (exact || !m || !n || !m2 || !n2) |
| 11633 | return false; |
| 11634 | |
| 11635 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 11636 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11637 | if (n > n2) { |
| 11638 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11639 | m2 <<= 1; |
| 11640 | n2 <<= 1; |
| 11641 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11642 | } else if (n < n2) { |
| 11643 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11644 | m <<= 1; |
| 11645 | n <<= 1; |
| 11646 | } |
| 11647 | } |
| 11648 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 11649 | if (n != n2) |
| 11650 | return false; |
| 11651 | |
| 11652 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11653 | } |
| 11654 | |
| 11655 | static bool |
| 11656 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 11657 | struct intel_link_m_n *m2_n2, |
| 11658 | bool adjust) |
| 11659 | { |
| 11660 | if (m_n->tu == m2_n2->tu && |
| 11661 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 11662 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 11663 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 11664 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 11665 | if (adjust) |
| 11666 | *m2_n2 = *m_n; |
| 11667 | |
| 11668 | return true; |
| 11669 | } |
| 11670 | |
| 11671 | return false; |
| 11672 | } |
| 11673 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11674 | static void __printf(3, 4) |
| 11675 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 11676 | { |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11677 | struct va_format vaf; |
| 11678 | va_list args; |
| 11679 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11680 | va_start(args, format); |
| 11681 | vaf.fmt = format; |
| 11682 | vaf.va = &args; |
| 11683 | |
Joe Perches | 99a9548 | 2018-03-13 15:02:15 -0700 | [diff] [blame] | 11684 | if (adjust) |
| 11685 | drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf); |
| 11686 | else |
| 11687 | drm_err("mismatch in %s %pV", name, &vaf); |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11688 | |
| 11689 | va_end(args); |
| 11690 | } |
| 11691 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11692 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11693 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11694 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11695 | struct intel_crtc_state *pipe_config, |
| 11696 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11697 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11698 | bool ret = true; |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11699 | bool fixup_inherited = adjust && |
| 11700 | (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) && |
| 11701 | !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11702 | |
Maarten Lankhorst | d19f958 | 2019-01-08 17:08:40 +0100 | [diff] [blame^] | 11703 | if (fixup_inherited && !i915_modparams.fastboot) { |
| 11704 | DRM_DEBUG_KMS("initial modeset and fastboot not set\n"); |
| 11705 | ret = false; |
| 11706 | } |
| 11707 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11708 | #define PIPE_CONF_CHECK_X(name) do { \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11709 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11710 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11711 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11712 | current_config->name, \ |
| 11713 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11714 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11715 | } \ |
| 11716 | } while (0) |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11717 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11718 | #define PIPE_CONF_CHECK_I(name) do { \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11719 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11720 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11721 | "(expected %i, found %i)\n", \ |
| 11722 | current_config->name, \ |
| 11723 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11724 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11725 | } \ |
| 11726 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11727 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11728 | #define PIPE_CONF_CHECK_BOOL(name) do { \ |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11729 | if (current_config->name != pipe_config->name) { \ |
| 11730 | pipe_config_err(adjust, __stringify(name), \ |
| 11731 | "(expected %s, found %s)\n", \ |
| 11732 | yesno(current_config->name), \ |
| 11733 | yesno(pipe_config->name)); \ |
| 11734 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11735 | } \ |
| 11736 | } while (0) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11737 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11738 | /* |
| 11739 | * Checks state where we only read out the enabling, but not the entire |
| 11740 | * state itself (like full infoframes or ELD for audio). These states |
| 11741 | * require a full modeset on bootup to fix up. |
| 11742 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11743 | #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11744 | if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ |
| 11745 | PIPE_CONF_CHECK_BOOL(name); \ |
| 11746 | } else { \ |
| 11747 | pipe_config_err(adjust, __stringify(name), \ |
| 11748 | "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \ |
| 11749 | yesno(current_config->name), \ |
| 11750 | yesno(pipe_config->name)); \ |
| 11751 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11752 | } \ |
| 11753 | } while (0) |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11754 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11755 | #define PIPE_CONF_CHECK_P(name) do { \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11756 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11757 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11758 | "(expected %p, found %p)\n", \ |
| 11759 | current_config->name, \ |
| 11760 | pipe_config->name); \ |
| 11761 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11762 | } \ |
| 11763 | } while (0) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11764 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11765 | #define PIPE_CONF_CHECK_M_N(name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11766 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11767 | &pipe_config->name,\ |
| 11768 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11769 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11770 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11771 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11772 | current_config->name.tu, \ |
| 11773 | current_config->name.gmch_m, \ |
| 11774 | current_config->name.gmch_n, \ |
| 11775 | current_config->name.link_m, \ |
| 11776 | current_config->name.link_n, \ |
| 11777 | pipe_config->name.tu, \ |
| 11778 | pipe_config->name.gmch_m, \ |
| 11779 | pipe_config->name.gmch_n, \ |
| 11780 | pipe_config->name.link_m, \ |
| 11781 | pipe_config->name.link_n); \ |
| 11782 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11783 | } \ |
| 11784 | } while (0) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11785 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 11786 | /* This is required for BDW+ where there is only one set of registers for |
| 11787 | * switching between high and low RR. |
| 11788 | * This macro can be used whenever a comparison has to be made between one |
| 11789 | * hw state and multiple sw state variables. |
| 11790 | */ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11791 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11792 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 11793 | &pipe_config->name, adjust) && \ |
| 11794 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 11795 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11796 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11797 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 11798 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 11799 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 11800 | current_config->name.tu, \ |
| 11801 | current_config->name.gmch_m, \ |
| 11802 | current_config->name.gmch_n, \ |
| 11803 | current_config->name.link_m, \ |
| 11804 | current_config->name.link_n, \ |
| 11805 | current_config->alt_name.tu, \ |
| 11806 | current_config->alt_name.gmch_m, \ |
| 11807 | current_config->alt_name.gmch_n, \ |
| 11808 | current_config->alt_name.link_m, \ |
| 11809 | current_config->alt_name.link_n, \ |
| 11810 | pipe_config->name.tu, \ |
| 11811 | pipe_config->name.gmch_m, \ |
| 11812 | pipe_config->name.gmch_n, \ |
| 11813 | pipe_config->name.link_m, \ |
| 11814 | pipe_config->name.link_n); \ |
| 11815 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11816 | } \ |
| 11817 | } while (0) |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11818 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11819 | #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11820 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11821 | pipe_config_err(adjust, __stringify(name), \ |
| 11822 | "(%x) (expected %i, found %i)\n", \ |
| 11823 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11824 | current_config->name & (mask), \ |
| 11825 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11826 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11827 | } \ |
| 11828 | } while (0) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11829 | |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11830 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11831 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 11832 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11833 | "(expected %i, found %i)\n", \ |
| 11834 | current_config->name, \ |
| 11835 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11836 | ret = false; \ |
Ville Syrjälä | eadd272 | 2018-03-16 20:36:25 +0200 | [diff] [blame] | 11837 | } \ |
| 11838 | } while (0) |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11839 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11840 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11841 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11842 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11843 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11844 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11845 | PIPE_CONF_CHECK_BOOL(has_pch_encoder); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11846 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11847 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11848 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 11849 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 11850 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11851 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11852 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11853 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11854 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11855 | if (current_config->has_drrs) |
| 11856 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 11857 | } else |
| 11858 | 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] | 11859 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 11860 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 11861 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11862 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11863 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11864 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11865 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11866 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11867 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11868 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11869 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11870 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11871 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11872 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11873 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11874 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11875 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11876 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Shashank Sharma | d9facae | 2018-10-12 11:53:07 +0530 | [diff] [blame] | 11877 | PIPE_CONF_CHECK_I(output_format); |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11878 | PIPE_CONF_CHECK_BOOL(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 11879 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 11880 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11881 | PIPE_CONF_CHECK_BOOL(limited_color_range); |
Shashank Sharma | 1595363 | 2017-03-13 16:54:03 +0530 | [diff] [blame] | 11882 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11883 | PIPE_CONF_CHECK_BOOL(hdmi_scrambling); |
| 11884 | PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11885 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11886 | |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11887 | PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11888 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11889 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11890 | DRM_MODE_FLAG_INTERLACE); |
| 11891 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11892 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11893 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11894 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11895 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11896 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11897 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11898 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11899 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11900 | DRM_MODE_FLAG_NVSYNC); |
| 11901 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11902 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11903 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 11904 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 11905 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 11906 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 11907 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11908 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11909 | if (!adjust) { |
| 11910 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11911 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 11912 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11913 | PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 11914 | if (current_config->pch_pfit.enabled) { |
| 11915 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 11916 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 11917 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11918 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11919 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 11920 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 11921 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 11922 | |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11923 | PIPE_CONF_CHECK_BOOL(double_wide); |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11924 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11925 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11926 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11927 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11928 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11929 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11930 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 11931 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11932 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11933 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11934 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Paulo Zanoni | 2de3813 | 2017-09-22 17:53:42 -0300 | [diff] [blame] | 11935 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
| 11936 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); |
| 11937 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); |
| 11938 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); |
| 11939 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); |
| 11940 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); |
| 11941 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); |
| 11942 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); |
| 11943 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); |
| 11944 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); |
| 11945 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); |
| 11946 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); |
Paulo Zanoni | c27e917 | 2018-04-27 16:14:36 -0700 | [diff] [blame] | 11947 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); |
| 11948 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); |
| 11949 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); |
| 11950 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); |
| 11951 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); |
| 11952 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); |
| 11953 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); |
| 11954 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); |
| 11955 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); |
| 11956 | PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11957 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 11958 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 11959 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 11960 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11961 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11962 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11963 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11964 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11965 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11966 | |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 11967 | PIPE_CONF_CHECK_I(min_voltage_level); |
| 11968 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11969 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11970 | #undef PIPE_CONF_CHECK_I |
Maarten Lankhorst | d640bf7 | 2017-11-10 12:34:55 +0100 | [diff] [blame] | 11971 | #undef PIPE_CONF_CHECK_BOOL |
Maarten Lankhorst | 4493e09 | 2017-11-10 12:34:56 +0100 | [diff] [blame] | 11972 | #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11973 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11974 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11975 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11976 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11977 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 11978 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11979 | } |
| 11980 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11981 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 11982 | const struct intel_crtc_state *pipe_config) |
| 11983 | { |
| 11984 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 11985 | 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] | 11986 | &pipe_config->fdi_m_n); |
| 11987 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 11988 | |
| 11989 | /* |
| 11990 | * FDI already provided one idea for the dotclock. |
| 11991 | * Yell if the encoder disagrees. |
| 11992 | */ |
| 11993 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 11994 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 11995 | fdi_dotclock, dotclock); |
| 11996 | } |
| 11997 | } |
| 11998 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 11999 | static void verify_wm_state(struct drm_crtc *crtc, |
| 12000 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12001 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12002 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12003 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12004 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 12005 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 12006 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12007 | struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES]; |
| 12008 | struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12009 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12010 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12011 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12012 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12013 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12014 | return; |
| 12015 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12016 | skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 12017 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12018 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12019 | skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv); |
| 12020 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12021 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12022 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12023 | |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 12024 | if (INTEL_GEN(dev_priv) >= 11) |
| 12025 | if (hw_ddb.enabled_slices != sw_ddb->enabled_slices) |
| 12026 | DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n", |
| 12027 | sw_ddb->enabled_slices, |
| 12028 | hw_ddb.enabled_slices); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12029 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 12030 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12031 | hw_plane_wm = &hw_wm.planes[plane]; |
| 12032 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12033 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12034 | /* Watermarks */ |
| 12035 | for (level = 0; level <= max_level; level++) { |
| 12036 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12037 | &sw_plane_wm->wm[level])) |
| 12038 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12039 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12040 | 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", |
| 12041 | pipe_name(pipe), plane + 1, level, |
| 12042 | sw_plane_wm->wm[level].plane_en, |
| 12043 | sw_plane_wm->wm[level].plane_res_b, |
| 12044 | sw_plane_wm->wm[level].plane_res_l, |
| 12045 | hw_plane_wm->wm[level].plane_en, |
| 12046 | hw_plane_wm->wm[level].plane_res_b, |
| 12047 | hw_plane_wm->wm[level].plane_res_l); |
| 12048 | } |
| 12049 | |
| 12050 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12051 | &sw_plane_wm->trans_wm)) { |
| 12052 | 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", |
| 12053 | pipe_name(pipe), plane + 1, |
| 12054 | sw_plane_wm->trans_wm.plane_en, |
| 12055 | sw_plane_wm->trans_wm.plane_res_b, |
| 12056 | sw_plane_wm->trans_wm.plane_res_l, |
| 12057 | hw_plane_wm->trans_wm.plane_en, |
| 12058 | hw_plane_wm->trans_wm.plane_res_b, |
| 12059 | hw_plane_wm->trans_wm.plane_res_l); |
| 12060 | } |
| 12061 | |
| 12062 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12063 | hw_ddb_entry = &hw_ddb_y[plane]; |
| 12064 | 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] | 12065 | |
| 12066 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12067 | 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] | 12068 | pipe_name(pipe), plane + 1, |
| 12069 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12070 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 12071 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12072 | } |
| 12073 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12074 | /* |
| 12075 | * cursor |
| 12076 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 12077 | * allocation. In that case since the ddb allocation will be updated |
| 12078 | * once the plane becomes visible, we can skip this check |
| 12079 | */ |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 12080 | if (1) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12081 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 12082 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12083 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12084 | /* Watermarks */ |
| 12085 | for (level = 0; level <= max_level; level++) { |
| 12086 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 12087 | &sw_plane_wm->wm[level])) |
| 12088 | continue; |
| 12089 | |
| 12090 | 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", |
| 12091 | pipe_name(pipe), level, |
| 12092 | sw_plane_wm->wm[level].plane_en, |
| 12093 | sw_plane_wm->wm[level].plane_res_b, |
| 12094 | sw_plane_wm->wm[level].plane_res_l, |
| 12095 | hw_plane_wm->wm[level].plane_en, |
| 12096 | hw_plane_wm->wm[level].plane_res_b, |
| 12097 | hw_plane_wm->wm[level].plane_res_l); |
| 12098 | } |
| 12099 | |
| 12100 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 12101 | &sw_plane_wm->trans_wm)) { |
| 12102 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 12103 | pipe_name(pipe), |
| 12104 | sw_plane_wm->trans_wm.plane_en, |
| 12105 | sw_plane_wm->trans_wm.plane_res_b, |
| 12106 | sw_plane_wm->trans_wm.plane_res_l, |
| 12107 | hw_plane_wm->trans_wm.plane_en, |
| 12108 | hw_plane_wm->trans_wm.plane_res_b, |
| 12109 | hw_plane_wm->trans_wm.plane_res_l); |
| 12110 | } |
| 12111 | |
| 12112 | /* DDB */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 12113 | hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR]; |
| 12114 | 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] | 12115 | |
| 12116 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 12117 | 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] | 12118 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 12119 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 12120 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12121 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12122 | } |
| 12123 | } |
| 12124 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12125 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12126 | verify_connector_state(struct drm_device *dev, |
| 12127 | struct drm_atomic_state *state, |
| 12128 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12129 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12130 | struct drm_connector *connector; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12131 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12132 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12133 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12134 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12135 | struct drm_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12136 | struct drm_crtc_state *crtc_state = NULL; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12137 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12138 | if (new_conn_state->crtc != crtc) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12139 | continue; |
| 12140 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12141 | if (crtc) |
| 12142 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
| 12143 | |
| 12144 | intel_connector_verify_state(crtc_state, new_conn_state); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12145 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12146 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12147 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12148 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12149 | } |
| 12150 | |
| 12151 | static void |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12152 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12153 | { |
| 12154 | struct intel_encoder *encoder; |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12155 | struct drm_connector *connector; |
| 12156 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 12157 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12158 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12159 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12160 | bool enabled = false, found = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12161 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12162 | |
| 12163 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12164 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12165 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12166 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12167 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
| 12168 | new_conn_state, i) { |
| 12169 | if (old_conn_state->best_encoder == &encoder->base) |
| 12170 | found = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12171 | |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12172 | if (new_conn_state->best_encoder != &encoder->base) |
| 12173 | continue; |
| 12174 | found = enabled = true; |
| 12175 | |
| 12176 | I915_STATE_WARN(new_conn_state->crtc != |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12177 | encoder->base.crtc, |
| 12178 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12179 | } |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12180 | |
| 12181 | if (!found) |
| 12182 | continue; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12183 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12184 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12185 | "encoder's enabled state mismatch " |
| 12186 | "(expected %i, found %i)\n", |
| 12187 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12188 | |
| 12189 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12190 | bool active; |
| 12191 | |
| 12192 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12193 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12194 | "encoder detached but still enabled on pipe %c.\n", |
| 12195 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12196 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12197 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12198 | } |
| 12199 | |
| 12200 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12201 | verify_crtc_state(struct drm_crtc *crtc, |
| 12202 | struct drm_crtc_state *old_crtc_state, |
| 12203 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12204 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12205 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12206 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12207 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12208 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12209 | struct intel_crtc_state *pipe_config, *sw_config; |
| 12210 | struct drm_atomic_state *old_state; |
| 12211 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12212 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12213 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 12214 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12215 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12216 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12217 | pipe_config->base.crtc = crtc; |
| 12218 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12219 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12220 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12221 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12222 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12223 | |
Ville Syrjälä | e56134b | 2017-06-01 17:36:19 +0300 | [diff] [blame] | 12224 | /* we keep both pipes enabled on 830 */ |
| 12225 | if (IS_I830(dev_priv)) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12226 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12227 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12228 | I915_STATE_WARN(new_crtc_state->active != active, |
| 12229 | "crtc active state doesn't match with hw state " |
| 12230 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12231 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12232 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 12233 | "transitional active state does not match atomic hw state " |
| 12234 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12235 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12236 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12237 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12238 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12239 | active = encoder->get_hw_state(encoder, &pipe); |
| 12240 | I915_STATE_WARN(active != new_crtc_state->active, |
| 12241 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12242 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12243 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12244 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12245 | "Encoder connected to wrong pipe %c\n", |
| 12246 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12247 | |
Ville Syrjälä | e1214b9 | 2017-10-27 22:31:23 +0300 | [diff] [blame] | 12248 | if (active) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12249 | encoder->get_config(encoder, pipe_config); |
| 12250 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12251 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 12252 | intel_crtc_compute_pixel_rate(pipe_config); |
| 12253 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12254 | if (!new_crtc_state->active) |
| 12255 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12256 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12257 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12258 | |
Maarten Lankhorst | 749d98b | 2017-05-11 10:28:43 +0200 | [diff] [blame] | 12259 | sw_config = to_intel_crtc_state(new_crtc_state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12260 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12261 | pipe_config, false)) { |
| 12262 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 12263 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 12264 | "[hw state]"); |
| 12265 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 12266 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12267 | } |
| 12268 | } |
| 12269 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12270 | static void |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 12271 | intel_verify_planes(struct intel_atomic_state *state) |
| 12272 | { |
| 12273 | struct intel_plane *plane; |
| 12274 | const struct intel_plane_state *plane_state; |
| 12275 | int i; |
| 12276 | |
| 12277 | for_each_new_intel_plane_in_state(state, plane, |
| 12278 | plane_state, i) |
| 12279 | assert_plane(plane, plane_state->base.visible); |
| 12280 | } |
| 12281 | |
| 12282 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12283 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 12284 | struct intel_shared_dpll *pll, |
| 12285 | struct drm_crtc *crtc, |
| 12286 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12287 | { |
| 12288 | struct intel_dpll_hw_state dpll_hw_state; |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12289 | unsigned int crtc_mask; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12290 | bool active; |
| 12291 | |
| 12292 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12293 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 12294 | DRM_DEBUG_KMS("%s\n", pll->info->name); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12295 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 12296 | 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] | 12297 | |
Lucas De Marchi | 5cd281f | 2018-03-20 15:06:36 -0700 | [diff] [blame] | 12298 | if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12299 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12300 | "pll in active use but not on in sw tracking\n"); |
| 12301 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12302 | "pll is on but not used by any active crtc\n"); |
| 12303 | I915_STATE_WARN(pll->on != active, |
| 12304 | "pll on state mismatch (expected %i, found %i)\n", |
| 12305 | pll->on, active); |
| 12306 | } |
| 12307 | |
| 12308 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12309 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12310 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12311 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12312 | |
| 12313 | return; |
| 12314 | } |
| 12315 | |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12316 | crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12317 | |
| 12318 | if (new_state->active) |
| 12319 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 12320 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 12321 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12322 | else |
| 12323 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12324 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 12325 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 12326 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12327 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12328 | "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] | 12329 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12330 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12331 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12332 | &dpll_hw_state, |
| 12333 | sizeof(dpll_hw_state)), |
| 12334 | "pll hw state mismatch\n"); |
| 12335 | } |
| 12336 | |
| 12337 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12338 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 12339 | struct drm_crtc_state *old_crtc_state, |
| 12340 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12341 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12342 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12343 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 12344 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 12345 | |
| 12346 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12347 | 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] | 12348 | |
| 12349 | if (old_state->shared_dpll && |
| 12350 | old_state->shared_dpll != new_state->shared_dpll) { |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 12351 | unsigned int crtc_mask = drm_crtc_mask(crtc); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12352 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 12353 | |
| 12354 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 12355 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 12356 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 12357 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12358 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 12359 | pipe_name(drm_crtc_index(crtc))); |
| 12360 | } |
| 12361 | } |
| 12362 | |
| 12363 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12364 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12365 | struct drm_atomic_state *state, |
| 12366 | struct drm_crtc_state *old_state, |
| 12367 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12368 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12369 | if (!needs_modeset(new_state) && |
| 12370 | !to_intel_crtc_state(new_state)->update_pipe) |
| 12371 | return; |
| 12372 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12373 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12374 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12375 | verify_crtc_state(crtc, old_state, new_state); |
| 12376 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12377 | } |
| 12378 | |
| 12379 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12380 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12381 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12382 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12383 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12384 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12385 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12386 | 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] | 12387 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12388 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12389 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12390 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 12391 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 12392 | { |
Daniel Vetter | 86b0426 | 2017-03-01 10:52:26 +0100 | [diff] [blame] | 12393 | verify_encoder_state(dev, state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 12394 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 12395 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12396 | } |
| 12397 | |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12398 | 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] | 12399 | { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12400 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12401 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12402 | |
| 12403 | /* |
| 12404 | * The scanline counter increments at the leading edge of hsync. |
| 12405 | * |
| 12406 | * On most platforms it starts counting from vtotal-1 on the |
| 12407 | * first active line. That means the scanline counter value is |
| 12408 | * always one less than what we would expect. Ie. just after |
| 12409 | * start of vblank, which also occurs at start of hsync (on the |
| 12410 | * last active line), the scanline counter will read vblank_start-1. |
| 12411 | * |
| 12412 | * On gen2 the scanline counter starts counting from 1 instead |
| 12413 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 12414 | * to keep the value positive), instead of adding one. |
| 12415 | * |
| 12416 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 12417 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 12418 | * there's an extra 1 line difference. So we need to add two instead of |
| 12419 | * one to the value. |
Ville Syrjälä | ec1b4ee | 2016-12-15 19:47:34 +0200 | [diff] [blame] | 12420 | * |
| 12421 | * On VLV/CHV DSI the scanline counter would appear to increment |
| 12422 | * approx. 1/3 of a scanline before start of vblank. Unfortunately |
| 12423 | * that means we can't tell whether we're in vblank or not while |
| 12424 | * we're on that particular line. We must still set scanline_offset |
| 12425 | * to 1 so that the vblank timestamps come out correct when we query |
| 12426 | * the scanline counter from within the vblank interrupt handler. |
| 12427 | * However if queried just before the start of vblank we'll get an |
| 12428 | * answer that's slightly in the future. |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12429 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 12430 | if (IS_GEN(dev_priv, 2)) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12431 | 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] | 12432 | int vtotal; |
| 12433 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 12434 | vtotal = adjusted_mode->crtc_vtotal; |
| 12435 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12436 | vtotal /= 2; |
| 12437 | |
| 12438 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12439 | } else if (HAS_DDI(dev_priv) && |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12440 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 12441 | crtc->scanline_offset = 2; |
| 12442 | } else |
| 12443 | crtc->scanline_offset = 1; |
| 12444 | } |
| 12445 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12446 | 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] | 12447 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12448 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12449 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12450 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12451 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12452 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12453 | |
| 12454 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12455 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12456 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12457 | 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] | 12458 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12459 | struct intel_shared_dpll *old_dpll = |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12460 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12461 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12462 | if (!needs_modeset(new_crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 12463 | continue; |
| 12464 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12465 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12466 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12467 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 12468 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12469 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 12470 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12471 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 12472 | } |
| 12473 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12474 | /* |
| 12475 | * This implements the workaround described in the "notes" section of the mode |
| 12476 | * set sequence documentation. When going from no pipes or single pipe to |
| 12477 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 12478 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 12479 | */ |
| 12480 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 12481 | { |
| 12482 | struct drm_crtc_state *crtc_state; |
| 12483 | struct intel_crtc *intel_crtc; |
| 12484 | struct drm_crtc *crtc; |
| 12485 | struct intel_crtc_state *first_crtc_state = NULL; |
| 12486 | struct intel_crtc_state *other_crtc_state = NULL; |
| 12487 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 12488 | int i; |
| 12489 | |
| 12490 | /* 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] | 12491 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12492 | intel_crtc = to_intel_crtc(crtc); |
| 12493 | |
| 12494 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 12495 | continue; |
| 12496 | |
| 12497 | if (first_crtc_state) { |
| 12498 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 12499 | break; |
| 12500 | } else { |
| 12501 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 12502 | first_pipe = intel_crtc->pipe; |
| 12503 | } |
| 12504 | } |
| 12505 | |
| 12506 | /* No workaround needed? */ |
| 12507 | if (!first_crtc_state) |
| 12508 | return 0; |
| 12509 | |
| 12510 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 12511 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 12512 | struct intel_crtc_state *pipe_config; |
| 12513 | |
| 12514 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 12515 | if (IS_ERR(pipe_config)) |
| 12516 | return PTR_ERR(pipe_config); |
| 12517 | |
| 12518 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 12519 | |
| 12520 | if (!pipe_config->base.active || |
| 12521 | needs_modeset(&pipe_config->base)) |
| 12522 | continue; |
| 12523 | |
| 12524 | /* 2 or more enabled crtcs means no need for w/a */ |
| 12525 | if (enabled_pipe != INVALID_PIPE) |
| 12526 | return 0; |
| 12527 | |
| 12528 | enabled_pipe = intel_crtc->pipe; |
| 12529 | } |
| 12530 | |
| 12531 | if (enabled_pipe != INVALID_PIPE) |
| 12532 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 12533 | else if (other_crtc_state) |
| 12534 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 12535 | |
| 12536 | return 0; |
| 12537 | } |
| 12538 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12539 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 12540 | { |
| 12541 | struct drm_crtc *crtc; |
| 12542 | |
| 12543 | /* Add all pipes to the state */ |
| 12544 | for_each_crtc(state->dev, crtc) { |
| 12545 | struct drm_crtc_state *crtc_state; |
| 12546 | |
| 12547 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12548 | if (IS_ERR(crtc_state)) |
| 12549 | return PTR_ERR(crtc_state); |
| 12550 | } |
| 12551 | |
| 12552 | return 0; |
| 12553 | } |
| 12554 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12555 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 12556 | { |
| 12557 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12558 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12559 | /* |
| 12560 | * Add all pipes to the state, and force |
| 12561 | * a modeset on all the active ones. |
| 12562 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12563 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12564 | struct drm_crtc_state *crtc_state; |
| 12565 | int ret; |
| 12566 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12567 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 12568 | if (IS_ERR(crtc_state)) |
| 12569 | return PTR_ERR(crtc_state); |
| 12570 | |
| 12571 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 12572 | continue; |
| 12573 | |
| 12574 | crtc_state->mode_changed = true; |
| 12575 | |
| 12576 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 12577 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12578 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12579 | |
| 12580 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 12581 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12582 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12583 | } |
| 12584 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 12585 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12586 | } |
| 12587 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12588 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12589 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12590 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12591 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12592 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12593 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12594 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12595 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12596 | if (!check_digital_port_conflicts(state)) { |
| 12597 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 12598 | return -EINVAL; |
| 12599 | } |
| 12600 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12601 | intel_state->modeset = true; |
| 12602 | intel_state->active_crtcs = dev_priv->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12603 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
| 12604 | intel_state->cdclk.actual = dev_priv->cdclk.actual; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12605 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12606 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12607 | if (new_crtc_state->active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12608 | intel_state->active_crtcs |= 1 << i; |
| 12609 | else |
| 12610 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12611 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12612 | if (old_crtc_state->active != new_crtc_state->active) |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 12613 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12614 | } |
| 12615 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12616 | /* |
| 12617 | * See if the config requires any additional preparation, e.g. |
| 12618 | * to adjust global state with pipes off. We need to do this |
| 12619 | * here so we can get the modeset_pipe updated config for the new |
| 12620 | * mode set on this crtc. For other crtcs we need to use the |
| 12621 | * adjusted_mode bits in the crtc directly. |
| 12622 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12623 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 12624 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 12625 | if (ret < 0) |
| 12626 | return ret; |
| 12627 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12628 | /* |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12629 | * Writes to dev_priv->cdclk.logical must protected by |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12630 | * holding all the crtc locks, even if we don't end up |
| 12631 | * touching the hardware |
| 12632 | */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12633 | if (intel_cdclk_changed(&dev_priv->cdclk.logical, |
| 12634 | &intel_state->cdclk.logical)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12635 | ret = intel_lock_all_pipes(state); |
| 12636 | if (ret < 0) |
| 12637 | return ret; |
| 12638 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 12639 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12640 | /* All pipes must be switched off while we change the cdclk. */ |
Ville Syrjälä | 64600bd | 2017-10-24 12:52:08 +0300 | [diff] [blame] | 12641 | if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual, |
| 12642 | &intel_state->cdclk.actual)) { |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 12643 | ret = intel_modeset_all_pipes(state); |
| 12644 | if (ret < 0) |
| 12645 | return ret; |
| 12646 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 12647 | |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12648 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
| 12649 | intel_state->cdclk.logical.cdclk, |
| 12650 | intel_state->cdclk.actual.cdclk); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 12651 | DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n", |
| 12652 | intel_state->cdclk.logical.voltage_level, |
| 12653 | intel_state->cdclk.actual.voltage_level); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12654 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12655 | to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12656 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12657 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12658 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12659 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12660 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12661 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 12662 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12663 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 12664 | } |
| 12665 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12666 | /* |
| 12667 | * Handle calculation of various watermark data at the end of the atomic check |
| 12668 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 12669 | * handlers to ensure that all derived state has been updated. |
| 12670 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12671 | static int calc_watermark_data(struct intel_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12672 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12673 | struct drm_device *dev = state->base.dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12674 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 12675 | |
| 12676 | /* Is there platform-specific watermark information to calculate? */ |
| 12677 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 12678 | return dev_priv->display.compute_global_watermarks(state); |
| 12679 | |
| 12680 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12681 | } |
| 12682 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12683 | /** |
| 12684 | * intel_atomic_check - validate state object |
| 12685 | * @dev: drm device |
| 12686 | * @state: state to validate |
| 12687 | */ |
| 12688 | static int intel_atomic_check(struct drm_device *dev, |
| 12689 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12690 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12691 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12692 | 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] | 12693 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12694 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12695 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12696 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12697 | |
Maarten Lankhorst | 8c58f73 | 2018-02-21 10:28:08 +0100 | [diff] [blame] | 12698 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 12699 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 12700 | crtc_state, i) { |
| 12701 | if (crtc_state->mode.private_flags != |
| 12702 | old_crtc_state->mode.private_flags) |
| 12703 | crtc_state->mode_changed = true; |
| 12704 | } |
| 12705 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 12706 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12707 | if (ret) |
| 12708 | return ret; |
| 12709 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12710 | 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] | 12711 | struct intel_crtc_state *pipe_config = |
| 12712 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12713 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12714 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12715 | continue; |
| 12716 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12717 | if (!crtc_state->enable) { |
| 12718 | any_ms = true; |
| 12719 | continue; |
| 12720 | } |
| 12721 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12722 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ville Syrjälä | 8e2b4df | 2018-11-07 23:35:20 +0200 | [diff] [blame] | 12723 | if (ret == -EDEADLK) |
| 12724 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12725 | if (ret) { |
| 12726 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 12727 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12728 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 12729 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12730 | |
Maarten Lankhorst | d19f958 | 2019-01-08 17:08:40 +0100 | [diff] [blame^] | 12731 | if (intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12732 | to_intel_crtc_state(old_crtc_state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 12733 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12734 | crtc_state->mode_changed = false; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12735 | pipe_config->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12736 | } |
| 12737 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 12738 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12739 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12740 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 12741 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 12742 | needs_modeset(crtc_state) ? |
| 12743 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12744 | } |
| 12745 | |
Lyude Paul | eceae14 | 2019-01-10 19:53:41 -0500 | [diff] [blame] | 12746 | ret = drm_dp_mst_atomic_check(state); |
| 12747 | if (ret) |
| 12748 | return ret; |
| 12749 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 12750 | if (any_ms) { |
| 12751 | ret = intel_modeset_checks(state); |
| 12752 | |
| 12753 | if (ret) |
| 12754 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12755 | } else { |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 12756 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 12757 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 12758 | |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 12759 | ret = icl_add_linked_planes(intel_state); |
| 12760 | if (ret) |
| 12761 | return ret; |
| 12762 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 12763 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 12764 | if (ret) |
| 12765 | return ret; |
| 12766 | |
Ville Syrjälä | dd57602 | 2017-11-17 21:19:14 +0200 | [diff] [blame] | 12767 | intel_fbc_choose_crtc(dev_priv, intel_state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 12768 | return calc_watermark_data(intel_state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12769 | } |
| 12770 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12771 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12772 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12773 | { |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 12774 | return drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 12775 | } |
| 12776 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12777 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 12778 | { |
| 12779 | struct drm_device *dev = crtc->base.dev; |
| 12780 | |
| 12781 | if (!dev->max_vblank_count) |
Dhinakaran Pandiyan | 734cbbf | 2018-02-02 21:12:54 -0800 | [diff] [blame] | 12782 | return (u32)drm_crtc_accurate_vblank_count(&crtc->base); |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 12783 | |
| 12784 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 12785 | } |
| 12786 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12787 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 12788 | struct drm_atomic_state *state, |
| 12789 | struct drm_crtc_state *old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12790 | struct drm_crtc_state *new_crtc_state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12791 | { |
| 12792 | struct drm_device *dev = crtc->dev; |
| 12793 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 12794 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12795 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
| 12796 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12797 | struct intel_plane_state *new_plane_state = |
| 12798 | intel_atomic_get_new_plane_state(to_intel_atomic_state(state), |
| 12799 | to_intel_plane(crtc->primary)); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12800 | |
| 12801 | if (modeset) { |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 12802 | update_scanline_offset(pipe_config); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12803 | dev_priv->display.crtc_enable(pipe_config, state); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 12804 | |
| 12805 | /* vblanks work again, re-enable pipe CRC. */ |
| 12806 | intel_crtc_enable_pipe_crc(intel_crtc); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12807 | } else { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12808 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
| 12809 | pipe_config); |
Hans de Goede | 608ed4a | 2018-12-20 14:21:18 +0100 | [diff] [blame] | 12810 | |
| 12811 | if (pipe_config->update_pipe) |
| 12812 | intel_encoders_update_pipe(crtc, pipe_config, state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12813 | } |
| 12814 | |
Maarten Lankhorst | 50c42fc | 2018-12-20 16:17:19 +0100 | [diff] [blame] | 12815 | if (pipe_config->update_pipe && !pipe_config->enable_fbc) |
| 12816 | intel_fbc_disable(intel_crtc); |
| 12817 | else if (new_plane_state) |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 12818 | intel_fbc_enable(intel_crtc, pipe_config, new_plane_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12819 | |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12820 | intel_begin_crtc_commit(crtc, old_crtc_state); |
| 12821 | |
Ville Syrjälä | 5f2e511 | 2018-11-14 23:07:27 +0200 | [diff] [blame] | 12822 | if (INTEL_GEN(dev_priv) >= 9) |
| 12823 | skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
| 12824 | else |
| 12825 | i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc); |
Maarten Lankhorst | 6c246b8 | 2018-09-20 12:27:08 +0200 | [diff] [blame] | 12826 | |
| 12827 | intel_finish_crtc_commit(crtc, old_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12828 | } |
| 12829 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12830 | static void intel_update_crtcs(struct drm_atomic_state *state) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12831 | { |
| 12832 | struct drm_crtc *crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12833 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12834 | int i; |
| 12835 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12836 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 12837 | if (!new_crtc_state->active) |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12838 | continue; |
| 12839 | |
| 12840 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12841 | new_crtc_state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 12842 | } |
| 12843 | } |
| 12844 | |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12845 | static void skl_update_crtcs(struct drm_atomic_state *state) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12846 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12847 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12848 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 12849 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12850 | struct intel_crtc *intel_crtc; |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12851 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12852 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12853 | unsigned int updated = 0; |
| 12854 | bool progress; |
| 12855 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12856 | int i; |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12857 | u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices; |
| 12858 | u8 required_slices = intel_state->wm_results.ddb.enabled_slices; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12859 | struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12860 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12861 | 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] | 12862 | /* ignore allocations for crtc's that have been turned off. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12863 | if (new_crtc_state->active) |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12864 | entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12865 | |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12866 | /* If 2nd DBuf slice required, enable it here */ |
| 12867 | if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices) |
| 12868 | icl_dbuf_slices_update(dev_priv, required_slices); |
| 12869 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12870 | /* |
| 12871 | * Whenever the number of active pipes changes, we need to make sure we |
| 12872 | * update the pipes in the right order so that their ddb allocations |
| 12873 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 12874 | * cause pipe underruns and other bad stuff. |
| 12875 | */ |
| 12876 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12877 | progress = false; |
| 12878 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12879 | 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] | 12880 | bool vbl_wait = false; |
| 12881 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12882 | |
| 12883 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2179481 | 2017-08-23 18:22:26 +0300 | [diff] [blame] | 12884 | cstate = to_intel_crtc_state(new_crtc_state); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12885 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12886 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12887 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12888 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 12889 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12890 | if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb, |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 12891 | entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12892 | INTEL_INFO(dev_priv)->num_pipes, i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12893 | continue; |
| 12894 | |
| 12895 | updated |= cmask; |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 12896 | entries[i] = cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12897 | |
| 12898 | /* |
| 12899 | * If this is an already active pipe, it's DDB changed, |
| 12900 | * and this isn't the last pipe that needs updating |
| 12901 | * then we need to wait for a vblank to pass for the |
| 12902 | * new ddb allocation to take effect. |
| 12903 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 12904 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 12905 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12906 | !new_crtc_state->active_changed && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12907 | intel_state->wm_results.dirty_pipes != updated) |
| 12908 | vbl_wait = true; |
| 12909 | |
| 12910 | intel_update_crtc(crtc, state, old_crtc_state, |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 12911 | new_crtc_state); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12912 | |
| 12913 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 12914 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12915 | |
| 12916 | progress = true; |
| 12917 | } |
| 12918 | } while (progress); |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 12919 | |
| 12920 | /* If 2nd DBuf slice is no more required disable it */ |
| 12921 | if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices) |
| 12922 | icl_dbuf_slices_update(dev_priv, required_slices); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 12923 | } |
| 12924 | |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 12925 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
| 12926 | { |
| 12927 | struct intel_atomic_state *state, *next; |
| 12928 | struct llist_node *freed; |
| 12929 | |
| 12930 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); |
| 12931 | llist_for_each_entry_safe(state, next, freed, freed) |
| 12932 | drm_atomic_state_put(&state->base); |
| 12933 | } |
| 12934 | |
| 12935 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) |
| 12936 | { |
| 12937 | struct drm_i915_private *dev_priv = |
| 12938 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); |
| 12939 | |
| 12940 | intel_atomic_helper_free_state(dev_priv); |
| 12941 | } |
| 12942 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12943 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
| 12944 | { |
| 12945 | struct wait_queue_entry wait_fence, wait_reset; |
| 12946 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); |
| 12947 | |
| 12948 | init_wait_entry(&wait_fence, 0); |
| 12949 | init_wait_entry(&wait_reset, 0); |
| 12950 | for (;;) { |
| 12951 | prepare_to_wait(&intel_state->commit_ready.wait, |
| 12952 | &wait_fence, TASK_UNINTERRUPTIBLE); |
| 12953 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, |
| 12954 | &wait_reset, TASK_UNINTERRUPTIBLE); |
| 12955 | |
| 12956 | |
| 12957 | if (i915_sw_fence_done(&intel_state->commit_ready) |
| 12958 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) |
| 12959 | break; |
| 12960 | |
| 12961 | schedule(); |
| 12962 | } |
| 12963 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); |
| 12964 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); |
| 12965 | } |
| 12966 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 12967 | static void intel_atomic_cleanup_work(struct work_struct *work) |
| 12968 | { |
| 12969 | struct drm_atomic_state *state = |
| 12970 | container_of(work, struct drm_atomic_state, commit_work); |
| 12971 | struct drm_i915_private *i915 = to_i915(state->dev); |
| 12972 | |
| 12973 | drm_atomic_helper_cleanup_planes(&i915->drm, state); |
| 12974 | drm_atomic_helper_commit_cleanup_done(state); |
| 12975 | drm_atomic_state_put(state); |
| 12976 | |
| 12977 | intel_atomic_helper_free_state(i915); |
| 12978 | } |
| 12979 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12980 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12981 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 12982 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12983 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12984 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 12985 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12986 | struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 12987 | struct drm_crtc *crtc; |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 12988 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 12989 | u64 put_domains[I915_MAX_PIPES] = {}; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 12990 | intel_wakeref_t wakeref = 0; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 12991 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 12992 | |
Daniel Vetter | 9db529a | 2017-08-08 10:08:28 +0200 | [diff] [blame] | 12993 | intel_atomic_commit_fence_wait(intel_state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 12994 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 12995 | drm_atomic_helper_wait_for_dependencies(state); |
| 12996 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 12997 | if (intel_state->modeset) |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 12998 | wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 12999 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13000 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13001 | old_intel_crtc_state = to_intel_crtc_state(old_crtc_state); |
| 13002 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
| 13003 | intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13004 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13005 | if (needs_modeset(new_crtc_state) || |
| 13006 | to_intel_crtc_state(new_crtc_state)->update_pipe) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13007 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13008 | put_domains[intel_crtc->pipe] = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13009 | modeset_get_crtc_power_domains(crtc, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13010 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13011 | } |
| 13012 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13013 | if (!needs_modeset(new_crtc_state)) |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13014 | continue; |
| 13015 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13016 | intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13017 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13018 | if (old_crtc_state->active) { |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 13019 | intel_crtc_disable_planes(intel_state, intel_crtc); |
Maarten Lankhorst | 033b7a2 | 2018-03-08 13:02:02 +0100 | [diff] [blame] | 13020 | |
| 13021 | /* |
| 13022 | * We need to disable pipe CRC before disabling the pipe, |
| 13023 | * or we race against vblank off. |
| 13024 | */ |
| 13025 | intel_crtc_disable_pipe_crc(intel_crtc); |
| 13026 | |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13027 | dev_priv->display.crtc_disable(old_intel_crtc_state, state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13028 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 13029 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | 65c307f | 2018-10-05 11:52:44 +0200 | [diff] [blame] | 13030 | intel_disable_shared_dpll(old_intel_crtc_state); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 13031 | |
| 13032 | /* |
| 13033 | * Underruns don't always raise |
| 13034 | * interrupts, so check manually. |
| 13035 | */ |
| 13036 | intel_check_cpu_fifo_underruns(dev_priv); |
| 13037 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13038 | |
Ville Syrjälä | a748fae | 2018-10-25 16:05:36 +0300 | [diff] [blame] | 13039 | /* FIXME unify this for all platforms */ |
| 13040 | if (!new_crtc_state->active && |
| 13041 | !HAS_GMCH_DISPLAY(dev_priv) && |
| 13042 | dev_priv->display.initial_watermarks) |
| 13043 | dev_priv->display.initial_watermarks(intel_state, |
| 13044 | new_intel_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13045 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13046 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13047 | |
Daniel Vetter | 7a1530d7 | 2017-12-07 15:32:02 +0100 | [diff] [blame] | 13048 | /* FIXME: Eventually get rid of our intel_crtc->config pointer */ |
| 13049 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
| 13050 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13051 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13052 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13053 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13054 | |
Ville Syrjälä | b0587e4 | 2017-01-26 21:52:01 +0200 | [diff] [blame] | 13055 | intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 13056 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13057 | /* |
| 13058 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 13059 | * have more then one pipe enabled |
| 13060 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13061 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13062 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13063 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13064 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13065 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13066 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13067 | /* Complete the events for pipes that have now been disabled */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13068 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 13069 | bool modeset = needs_modeset(new_crtc_state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13070 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13071 | /* Complete events for now disable pipes here. */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13072 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13073 | spin_lock_irq(&dev->event_lock); |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13074 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13075 | spin_unlock_irq(&dev->event_lock); |
| 13076 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13077 | new_crtc_state->event = NULL; |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 13078 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13079 | } |
| 13080 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13081 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13082 | dev_priv->display.update_crtcs(state); |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 13083 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13084 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 13085 | * already, but still need the state for the delayed optimization. To |
| 13086 | * fix this: |
| 13087 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 13088 | * - schedule that vblank worker _before_ calling hw_done |
| 13089 | * - at the start of commit_tail, cancel it _synchrously |
| 13090 | * - switch over to the vblank wait helper in the core after that since |
| 13091 | * we don't need out special handling any more. |
| 13092 | */ |
Maarten Lankhorst | b44d5c0 | 2017-09-04 12:48:33 +0200 | [diff] [blame] | 13093 | drm_atomic_helper_wait_for_flip_done(dev, state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13094 | |
| 13095 | /* |
| 13096 | * Now that the vblank has passed, we can go ahead and program the |
| 13097 | * optimal watermarks on platforms that need two-step watermark |
| 13098 | * programming. |
| 13099 | * |
| 13100 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13101 | */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13102 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13103 | new_intel_crtc_state = to_intel_crtc_state(new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13104 | |
| 13105 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13106 | dev_priv->display.optimize_watermarks(intel_state, |
Maarten Lankhorst | a1cccdcf | 2018-09-20 12:27:04 +0200 | [diff] [blame] | 13107 | new_intel_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13108 | } |
| 13109 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13110 | 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] | 13111 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13112 | |
| 13113 | if (put_domains[i]) |
| 13114 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13115 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13116 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13117 | } |
| 13118 | |
Ville Syrjälä | cff109f | 2017-11-17 21:19:17 +0200 | [diff] [blame] | 13119 | if (intel_state->modeset) |
| 13120 | intel_verify_planes(intel_state); |
| 13121 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 13122 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 13123 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 13124 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13125 | drm_atomic_helper_commit_hw_done(state); |
| 13126 | |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13127 | if (intel_state->modeset) { |
| 13128 | /* As one of the primary mmio accessors, KMS has a high |
| 13129 | * likelihood of triggering bugs in unclaimed access. After we |
| 13130 | * finish modesetting, see if an error has been flagged, and if |
| 13131 | * so enable debugging for the next modeset - and hope we catch |
| 13132 | * the culprit. |
| 13133 | */ |
| 13134 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 13135 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref); |
Chris Wilson | d5553c0 | 2017-05-04 12:55:08 +0100 | [diff] [blame] | 13136 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13137 | |
Chris Wilson | 8d52e44 | 2018-06-23 11:39:51 +0100 | [diff] [blame] | 13138 | /* |
| 13139 | * Defer the cleanup of the old state to a separate worker to not |
| 13140 | * impede the current task (userspace for blocking modesets) that |
| 13141 | * are executed inline. For out-of-line asynchronous modesets/flips, |
| 13142 | * deferring to a new worker seems overkill, but we would place a |
| 13143 | * schedule point (cond_resched()) here anyway to keep latencies |
| 13144 | * down. |
| 13145 | */ |
| 13146 | INIT_WORK(&state->commit_work, intel_atomic_cleanup_work); |
Chris Wilson | 41db645 | 2018-07-12 12:57:29 +0100 | [diff] [blame] | 13147 | queue_work(system_highpri_wq, &state->commit_work); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13148 | } |
| 13149 | |
| 13150 | static void intel_atomic_commit_work(struct work_struct *work) |
| 13151 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13152 | struct drm_atomic_state *state = |
| 13153 | container_of(work, struct drm_atomic_state, commit_work); |
| 13154 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13155 | intel_atomic_commit_tail(state); |
| 13156 | } |
| 13157 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13158 | static int __i915_sw_fence_call |
| 13159 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 13160 | enum i915_sw_fence_notify notify) |
| 13161 | { |
| 13162 | struct intel_atomic_state *state = |
| 13163 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 13164 | |
| 13165 | switch (notify) { |
| 13166 | case FENCE_COMPLETE: |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13167 | /* we do blocking waits in the worker, nothing to do here */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13168 | break; |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13169 | case FENCE_FREE: |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 13170 | { |
| 13171 | struct intel_atomic_helper *helper = |
| 13172 | &to_i915(state->base.dev)->atomic_helper; |
| 13173 | |
| 13174 | if (llist_add(&state->freed, &helper->free_list)) |
| 13175 | schedule_work(&helper->free_work); |
| 13176 | break; |
| 13177 | } |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13178 | } |
| 13179 | |
| 13180 | return NOTIFY_DONE; |
| 13181 | } |
| 13182 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13183 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 13184 | { |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13185 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13186 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13187 | int i; |
| 13188 | |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13189 | 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] | 13190 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 13191 | intel_fb_obj(new_plane_state->fb), |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 13192 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13193 | } |
| 13194 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13195 | /** |
| 13196 | * intel_atomic_commit - commit validated state object |
| 13197 | * @dev: DRM device |
| 13198 | * @state: the top-level driver state object |
| 13199 | * @nonblock: nonblocking commit |
| 13200 | * |
| 13201 | * This function commits a top-level state object that has been validated |
| 13202 | * with drm_atomic_helper_check(). |
| 13203 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13204 | * RETURNS |
| 13205 | * Zero for success or -errno. |
| 13206 | */ |
| 13207 | static int intel_atomic_commit(struct drm_device *dev, |
| 13208 | struct drm_atomic_state *state, |
| 13209 | bool nonblock) |
| 13210 | { |
| 13211 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13212 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13213 | int ret = 0; |
| 13214 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13215 | drm_atomic_state_get(state); |
| 13216 | i915_sw_fence_init(&intel_state->commit_ready, |
| 13217 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13218 | |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13219 | /* |
| 13220 | * The intel_legacy_cursor_update() fast path takes care |
| 13221 | * of avoiding the vblank waits for simple cursor |
| 13222 | * movement and flips. For cursor on/off and size changes, |
| 13223 | * we want to perform the vblank waits so that watermark |
| 13224 | * updates happen during the correct frames. Gen9+ have |
| 13225 | * double buffered watermarks and so shouldn't need this. |
| 13226 | * |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13227 | * Unset state->legacy_cursor_update before the call to |
| 13228 | * drm_atomic_helper_setup_commit() because otherwise |
| 13229 | * drm_atomic_helper_wait_for_flip_done() is a noop and |
| 13230 | * we get FIFO underruns because we didn't wait |
| 13231 | * for vblank. |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13232 | * |
| 13233 | * FIXME doing watermarks and fb cleanup from a vblank worker |
| 13234 | * (assuming we had any) would solve these problems. |
| 13235 | */ |
Maarten Lankhorst | 213f1bd | 2017-09-19 14:14:19 +0200 | [diff] [blame] | 13236 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
| 13237 | struct intel_crtc_state *new_crtc_state; |
| 13238 | struct intel_crtc *crtc; |
| 13239 | int i; |
| 13240 | |
| 13241 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) |
| 13242 | if (new_crtc_state->wm.need_postvbl_update || |
| 13243 | new_crtc_state->update_wm_post) |
| 13244 | state->legacy_cursor_update = false; |
| 13245 | } |
Ville Syrjälä | 440df93 | 2017-03-29 17:21:23 +0300 | [diff] [blame] | 13246 | |
Maarten Lankhorst | 3cf50c6 | 2017-09-19 14:14:18 +0200 | [diff] [blame] | 13247 | ret = intel_atomic_prepare_commit(dev, state); |
| 13248 | if (ret) { |
| 13249 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
| 13250 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13251 | return ret; |
| 13252 | } |
| 13253 | |
| 13254 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 13255 | if (!ret) |
| 13256 | ret = drm_atomic_helper_swap_state(state, true); |
| 13257 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13258 | if (ret) { |
| 13259 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 13260 | |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13261 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | 0806f4e | 2017-07-11 16:33:07 +0200 | [diff] [blame] | 13262 | return ret; |
| 13263 | } |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13264 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 13265 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 13266 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13267 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13268 | if (intel_state->modeset) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 13269 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
| 13270 | sizeof(intel_state->min_cdclk)); |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 13271 | memcpy(dev_priv->min_voltage_level, |
| 13272 | intel_state->min_voltage_level, |
| 13273 | sizeof(intel_state->min_voltage_level)); |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13274 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 13275 | dev_priv->cdclk.logical = intel_state->cdclk.logical; |
| 13276 | dev_priv->cdclk.actual = intel_state->cdclk.actual; |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 13277 | } |
| 13278 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 13279 | drm_atomic_state_get(state); |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13280 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13281 | |
| 13282 | i915_sw_fence_commit(&intel_state->commit_ready); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13283 | if (nonblock && intel_state->modeset) { |
| 13284 | queue_work(dev_priv->modeset_wq, &state->commit_work); |
| 13285 | } else if (nonblock) { |
Daniel Vetter | 42b062b | 2017-08-08 10:08:27 +0200 | [diff] [blame] | 13286 | queue_work(system_unbound_wq, &state->commit_work); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13287 | } else { |
| 13288 | if (intel_state->modeset) |
| 13289 | flush_workqueue(dev_priv->modeset_wq); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 13290 | intel_atomic_commit_tail(state); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 13291 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13292 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13293 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13294 | } |
| 13295 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13296 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Daniel Vetter | 3fab2f0 | 2017-04-03 10:32:57 +0200 | [diff] [blame] | 13297 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13298 | .set_config = drm_atomic_helper_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13299 | .destroy = intel_crtc_destroy, |
Maarten Lankhorst | 4c01ded | 2016-12-22 11:33:23 +0100 | [diff] [blame] | 13300 | .page_flip = drm_atomic_helper_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13301 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13302 | .atomic_destroy_state = intel_crtc_destroy_state, |
Tomeu Vizoso | 8c6b709 | 2017-01-10 14:43:04 +0100 | [diff] [blame] | 13303 | .set_crc_source = intel_crtc_set_crc_source, |
Mahesh Kumar | a8c2083 | 2018-07-13 19:29:38 +0530 | [diff] [blame] | 13304 | .verify_crc_source = intel_crtc_verify_crc_source, |
Mahesh Kumar | 260bc55 | 2018-07-13 19:29:39 +0530 | [diff] [blame] | 13305 | .get_crc_sources = intel_crtc_get_crc_sources, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13306 | }; |
| 13307 | |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13308 | struct wait_rps_boost { |
| 13309 | struct wait_queue_entry wait; |
| 13310 | |
| 13311 | struct drm_crtc *crtc; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13312 | struct i915_request *request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13313 | }; |
| 13314 | |
| 13315 | static int do_rps_boost(struct wait_queue_entry *_wait, |
| 13316 | unsigned mode, int sync, void *key) |
| 13317 | { |
| 13318 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13319 | struct i915_request *rq = wait->request; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13320 | |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13321 | /* |
| 13322 | * If we missed the vblank, but the request is already running it |
| 13323 | * is reasonable to assume that it will complete before the next |
| 13324 | * vblank without our intervention, so leave RPS alone. |
| 13325 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13326 | if (!i915_request_started(rq)) |
Chris Wilson | e9af4ea | 2018-01-18 13:16:09 +0000 | [diff] [blame] | 13327 | gen6_rps_boost(rq, NULL); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 13328 | i915_request_put(rq); |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13329 | |
| 13330 | drm_crtc_vblank_put(wait->crtc); |
| 13331 | |
| 13332 | list_del(&wait->wait.entry); |
| 13333 | kfree(wait); |
| 13334 | return 1; |
| 13335 | } |
| 13336 | |
| 13337 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, |
| 13338 | struct dma_fence *fence) |
| 13339 | { |
| 13340 | struct wait_rps_boost *wait; |
| 13341 | |
| 13342 | if (!dma_fence_is_i915(fence)) |
| 13343 | return; |
| 13344 | |
| 13345 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) |
| 13346 | return; |
| 13347 | |
| 13348 | if (drm_crtc_vblank_get(crtc)) |
| 13349 | return; |
| 13350 | |
| 13351 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); |
| 13352 | if (!wait) { |
| 13353 | drm_crtc_vblank_put(crtc); |
| 13354 | return; |
| 13355 | } |
| 13356 | |
| 13357 | wait->request = to_request(dma_fence_get(fence)); |
| 13358 | wait->crtc = crtc; |
| 13359 | |
| 13360 | wait->wait.func = do_rps_boost; |
| 13361 | wait->wait.flags = 0; |
| 13362 | |
| 13363 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); |
| 13364 | } |
| 13365 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13366 | static int intel_plane_pin_fb(struct intel_plane_state *plane_state) |
| 13367 | { |
| 13368 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); |
| 13369 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 13370 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 13371 | struct i915_vma *vma; |
| 13372 | |
| 13373 | if (plane->id == PLANE_CURSOR && |
José Roberto de Souza | d53db44 | 2018-11-30 15:20:48 -0800 | [diff] [blame] | 13374 | INTEL_INFO(dev_priv)->display.cursor_needs_physical) { |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13375 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 13376 | const int align = intel_cursor_alignment(dev_priv); |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13377 | int err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13378 | |
Chris Wilson | 4a47765 | 2018-08-17 09:24:05 +0100 | [diff] [blame] | 13379 | err = i915_gem_object_attach_phys(obj, align); |
| 13380 | if (err) |
| 13381 | return err; |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13382 | } |
| 13383 | |
| 13384 | vma = intel_pin_and_fence_fb_obj(fb, |
Ville Syrjälä | f5929c5 | 2018-09-07 18:24:06 +0300 | [diff] [blame] | 13385 | &plane_state->view, |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13386 | intel_plane_uses_fence(plane_state), |
| 13387 | &plane_state->flags); |
| 13388 | if (IS_ERR(vma)) |
| 13389 | return PTR_ERR(vma); |
| 13390 | |
| 13391 | plane_state->vma = vma; |
| 13392 | |
| 13393 | return 0; |
| 13394 | } |
| 13395 | |
| 13396 | static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) |
| 13397 | { |
| 13398 | struct i915_vma *vma; |
| 13399 | |
| 13400 | vma = fetch_and_zero(&old_plane_state->vma); |
| 13401 | if (vma) |
| 13402 | intel_unpin_fb_vma(vma, old_plane_state->flags); |
| 13403 | } |
| 13404 | |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 13405 | static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj) |
| 13406 | { |
| 13407 | struct i915_sched_attr attr = { |
| 13408 | .priority = I915_PRIORITY_DISPLAY, |
| 13409 | }; |
| 13410 | |
| 13411 | i915_gem_object_wait_priority(obj, 0, &attr); |
| 13412 | } |
| 13413 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13414 | /** |
| 13415 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13416 | * @plane: drm plane to prepare for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13417 | * @new_state: the plane state being prepared |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13418 | * |
| 13419 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13420 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13421 | * bits. Some older platforms need special physical address handling for |
| 13422 | * cursor planes. |
| 13423 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13424 | * Must be called with struct_mutex held. |
| 13425 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13426 | * Returns 0 on success, negative error code on failure. |
| 13427 | */ |
| 13428 | int |
| 13429 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13430 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13431 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13432 | struct intel_atomic_state *intel_state = |
| 13433 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 13434 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13435 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13436 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13437 | 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] | 13438 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13439 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13440 | if (old_obj) { |
| 13441 | struct drm_crtc_state *crtc_state = |
Maarten Lankhorst | 8b69449 | 2018-04-09 14:46:55 +0200 | [diff] [blame] | 13442 | drm_atomic_get_new_crtc_state(new_state->state, |
| 13443 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13444 | |
| 13445 | /* Big Hammer, we also need to ensure that any pending |
| 13446 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13447 | * current scanout is retired before unpinning the old |
| 13448 | * framebuffer. Note that we rely on userspace rendering |
| 13449 | * into the buffer attached to the pipe they are waiting |
| 13450 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13451 | * point to the MI_WAIT_FOR_EVENT. |
| 13452 | * |
| 13453 | * This should only fail upon a hung GPU, in which case we |
| 13454 | * can safely continue. |
| 13455 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13456 | if (needs_modeset(crtc_state)) { |
| 13457 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13458 | old_obj->resv, NULL, |
| 13459 | false, 0, |
| 13460 | GFP_KERNEL); |
| 13461 | if (ret < 0) |
| 13462 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 13463 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13464 | } |
| 13465 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13466 | if (new_state->fence) { /* explicit fencing */ |
| 13467 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 13468 | new_state->fence, |
| 13469 | I915_FENCE_TIMEOUT, |
| 13470 | GFP_KERNEL); |
| 13471 | if (ret < 0) |
| 13472 | return ret; |
| 13473 | } |
| 13474 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 13475 | if (!obj) |
| 13476 | return 0; |
| 13477 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13478 | ret = i915_gem_object_pin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13479 | if (ret) |
| 13480 | return ret; |
| 13481 | |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13482 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13483 | if (ret) { |
| 13484 | i915_gem_object_unpin_pages(obj); |
| 13485 | return ret; |
| 13486 | } |
| 13487 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13488 | ret = intel_plane_pin_fb(to_intel_plane_state(new_state)); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13489 | |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13490 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Chris Wilson | 4d3088c | 2017-07-26 17:00:38 +0100 | [diff] [blame] | 13491 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | fd70075 | 2017-07-26 17:00:36 +0100 | [diff] [blame] | 13492 | if (ret) |
| 13493 | return ret; |
| 13494 | |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 13495 | fb_obj_bump_render_priority(obj); |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13496 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
| 13497 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13498 | if (!new_state->fence) { /* implicit fencing */ |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13499 | struct dma_fence *fence; |
| 13500 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13501 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 13502 | obj->resv, NULL, |
| 13503 | false, I915_FENCE_TIMEOUT, |
| 13504 | GFP_KERNEL); |
| 13505 | if (ret < 0) |
| 13506 | return ret; |
Chris Wilson | 74d290f | 2017-08-17 13:37:06 +0100 | [diff] [blame] | 13507 | |
| 13508 | fence = reservation_object_get_excl_rcu(obj->resv); |
| 13509 | if (fence) { |
| 13510 | add_rps_boost_after_vblank(new_state->crtc, fence); |
| 13511 | dma_fence_put(fence); |
| 13512 | } |
| 13513 | } else { |
| 13514 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 13515 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13516 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13517 | /* |
| 13518 | * We declare pageflips to be interactive and so merit a small bias |
| 13519 | * towards upclocking to deliver the frame on time. By only changing |
| 13520 | * the RPS thresholds to sample more regularly and aim for higher |
| 13521 | * clocks we can hopefully deliver low power workloads (like kodi) |
| 13522 | * that are not quite steady state without resorting to forcing |
| 13523 | * maximum clocks following a vblank miss (see do_rps_boost()). |
| 13524 | */ |
| 13525 | if (!intel_state->rps_interactive) { |
| 13526 | intel_rps_mark_interactive(dev_priv, true); |
| 13527 | intel_state->rps_interactive = true; |
| 13528 | } |
| 13529 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 13530 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13531 | } |
| 13532 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13533 | /** |
| 13534 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13535 | * @plane: drm plane to clean up for |
Chris Wilson | c38c145 | 2018-02-14 13:49:22 +0000 | [diff] [blame] | 13536 | * @old_state: the state from the previous modeset |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13537 | * |
| 13538 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13539 | * |
| 13540 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13541 | */ |
| 13542 | void |
| 13543 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 13544 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13545 | { |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13546 | struct intel_atomic_state *intel_state = |
| 13547 | to_intel_atomic_state(old_state->state); |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13548 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13549 | |
Chris Wilson | 60548c5 | 2018-07-31 14:26:29 +0100 | [diff] [blame] | 13550 | if (intel_state->rps_interactive) { |
| 13551 | intel_rps_mark_interactive(dev_priv, false); |
| 13552 | intel_state->rps_interactive = false; |
| 13553 | } |
| 13554 | |
Chris Wilson | be1e341 | 2017-01-16 15:21:27 +0000 | [diff] [blame] | 13555 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13556 | mutex_lock(&dev_priv->drm.struct_mutex); |
| 13557 | intel_plane_unpin_fb(to_intel_plane_state(old_state)); |
| 13558 | mutex_unlock(&dev_priv->drm.struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13559 | } |
| 13560 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13561 | int |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13562 | skl_max_scale(const struct intel_crtc_state *crtc_state, |
| 13563 | u32 pixel_format) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13564 | { |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13565 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 13566 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13567 | int max_scale, mult; |
| 13568 | int crtc_clock, max_dotclk, tmpclk1, tmpclk2; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13569 | |
Ville Syrjälä | 4e0b83a | 2018-09-07 18:24:09 +0300 | [diff] [blame] | 13570 | if (!crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13571 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13572 | |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13573 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
| 13574 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
| 13575 | |
Rodrigo Vivi | 43037c8 | 2017-10-03 15:31:42 -0700 | [diff] [blame] | 13576 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) |
Ander Conselvan de Oliveira | 5b7280f | 2017-02-23 09:15:58 +0200 | [diff] [blame] | 13577 | max_dotclk *= 2; |
| 13578 | |
| 13579 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13580 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13581 | |
| 13582 | /* |
| 13583 | * skl max scale is lower of: |
| 13584 | * close to 3 but not 3, -1 is for that purpose |
| 13585 | * or |
| 13586 | * cdclk/crtc_clock |
| 13587 | */ |
Chandra Konduru | 77224cd | 2018-04-09 09:11:13 +0530 | [diff] [blame] | 13588 | mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3; |
| 13589 | tmpclk1 = (1 << 16) * mult - 1; |
| 13590 | tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock); |
| 13591 | max_scale = min(tmpclk1, tmpclk2); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13592 | |
| 13593 | return max_scale; |
| 13594 | } |
| 13595 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13596 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13597 | struct drm_crtc_state *old_crtc_state) |
| 13598 | { |
| 13599 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13600 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13601 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13602 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13603 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13604 | struct intel_atomic_state *old_intel_state = |
| 13605 | to_intel_atomic_state(old_crtc_state->state); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13606 | struct intel_crtc_state *intel_cstate = |
| 13607 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
| 13608 | bool modeset = needs_modeset(&intel_cstate->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13609 | |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13610 | if (!modeset && |
| 13611 | (intel_cstate->base.color_mgmt_changed || |
| 13612 | intel_cstate->update_pipe)) { |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 13613 | intel_color_set_csc(intel_cstate); |
| 13614 | intel_color_load_luts(intel_cstate); |
Maarten Lankhorst | 567f079 | 2017-02-28 15:28:47 +0100 | [diff] [blame] | 13615 | } |
| 13616 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13617 | /* Perform vblank evasion around commit operation */ |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13618 | intel_pipe_update_start(intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13619 | |
| 13620 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13621 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13622 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13623 | if (intel_cstate->update_pipe) |
Ville Syrjälä | 1a15b77 | 2017-08-23 18:22:25 +0300 | [diff] [blame] | 13624 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13625 | else if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | 15cbe5d | 2018-10-04 11:45:56 +0200 | [diff] [blame] | 13626 | skl_detach_scalers(intel_cstate); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 13627 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 13628 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 13629 | if (dev_priv->display.atomic_update_watermarks) |
| 13630 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 13631 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13632 | } |
| 13633 | |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13634 | void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, |
| 13635 | struct intel_crtc_state *crtc_state) |
| 13636 | { |
| 13637 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 13638 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 13639 | if (!IS_GEN(dev_priv, 2)) |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13640 | intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); |
| 13641 | |
| 13642 | if (crtc_state->has_pch_encoder) { |
| 13643 | enum pipe pch_transcoder = |
| 13644 | intel_crtc_pch_transcoder(crtc); |
| 13645 | |
| 13646 | intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); |
| 13647 | } |
| 13648 | } |
| 13649 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13650 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13651 | struct drm_crtc_state *old_crtc_state) |
| 13652 | { |
| 13653 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13654 | struct intel_atomic_state *old_intel_state = |
| 13655 | to_intel_atomic_state(old_crtc_state->state); |
| 13656 | struct intel_crtc_state *new_crtc_state = |
| 13657 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13658 | |
Ville Syrjälä | d3a8fb3 | 2017-08-23 18:22:21 +0300 | [diff] [blame] | 13659 | intel_pipe_update_end(new_crtc_state); |
Maarten Lankhorst | 33a4986 | 2017-11-13 15:40:43 +0100 | [diff] [blame] | 13660 | |
| 13661 | if (new_crtc_state->update_pipe && |
| 13662 | !needs_modeset(&new_crtc_state->base) && |
Maarten Lankhorst | d52ad9c | 2018-03-28 12:05:26 +0200 | [diff] [blame] | 13663 | old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED) |
| 13664 | intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13665 | } |
| 13666 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13667 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13668 | * intel_plane_destroy - destroy a plane |
| 13669 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13670 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13671 | * Common destruction function for all types of planes (primary, cursor, |
| 13672 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13673 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13674 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13675 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13676 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 13677 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13678 | } |
| 13679 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13680 | static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane, |
| 13681 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13682 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13683 | switch (modifier) { |
| 13684 | case DRM_FORMAT_MOD_LINEAR: |
| 13685 | case I915_FORMAT_MOD_X_TILED: |
| 13686 | break; |
| 13687 | default: |
| 13688 | return false; |
| 13689 | } |
| 13690 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13691 | switch (format) { |
| 13692 | case DRM_FORMAT_C8: |
| 13693 | case DRM_FORMAT_RGB565: |
| 13694 | case DRM_FORMAT_XRGB1555: |
| 13695 | case DRM_FORMAT_XRGB8888: |
| 13696 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13697 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13698 | default: |
| 13699 | return false; |
| 13700 | } |
| 13701 | } |
| 13702 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13703 | static bool i965_plane_format_mod_supported(struct drm_plane *_plane, |
| 13704 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13705 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13706 | switch (modifier) { |
| 13707 | case DRM_FORMAT_MOD_LINEAR: |
| 13708 | case I915_FORMAT_MOD_X_TILED: |
| 13709 | break; |
| 13710 | default: |
| 13711 | return false; |
| 13712 | } |
| 13713 | |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13714 | switch (format) { |
| 13715 | case DRM_FORMAT_C8: |
| 13716 | case DRM_FORMAT_RGB565: |
| 13717 | case DRM_FORMAT_XRGB8888: |
| 13718 | case DRM_FORMAT_XBGR8888: |
| 13719 | case DRM_FORMAT_XRGB2101010: |
| 13720 | case DRM_FORMAT_XBGR2101010: |
| 13721 | return modifier == DRM_FORMAT_MOD_LINEAR || |
| 13722 | modifier == I915_FORMAT_MOD_X_TILED; |
| 13723 | default: |
| 13724 | return false; |
| 13725 | } |
| 13726 | } |
| 13727 | |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13728 | static bool intel_cursor_format_mod_supported(struct drm_plane *_plane, |
| 13729 | u32 format, u64 modifier) |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13730 | { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13731 | return modifier == DRM_FORMAT_MOD_LINEAR && |
| 13732 | format == DRM_FORMAT_ARGB8888; |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13733 | } |
| 13734 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13735 | static const struct drm_plane_funcs i965_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13736 | .update_plane = drm_atomic_helper_update_plane, |
| 13737 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13738 | .destroy = intel_plane_destroy, |
| 13739 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13740 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13741 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13742 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13743 | .format_mod_supported = i965_plane_format_mod_supported, |
| 13744 | }; |
| 13745 | |
Ville Syrjälä | 679bfe8 | 2018-10-05 15:58:07 +0300 | [diff] [blame] | 13746 | static const struct drm_plane_funcs i8xx_plane_funcs = { |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13747 | .update_plane = drm_atomic_helper_update_plane, |
| 13748 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13749 | .destroy = intel_plane_destroy, |
| 13750 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13751 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13752 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13753 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13754 | .format_mod_supported = i8xx_plane_format_mod_supported, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13755 | }; |
| 13756 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13757 | static int |
| 13758 | intel_legacy_cursor_update(struct drm_plane *plane, |
| 13759 | struct drm_crtc *crtc, |
| 13760 | struct drm_framebuffer *fb, |
| 13761 | int crtc_x, int crtc_y, |
| 13762 | unsigned int crtc_w, unsigned int crtc_h, |
Jani Nikula | ba3f4d0 | 2019-01-18 14:01:23 +0200 | [diff] [blame] | 13763 | u32 src_x, u32 src_y, |
| 13764 | u32 src_w, u32 src_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13765 | struct drm_modeset_acquire_ctx *ctx) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13766 | { |
| 13767 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
| 13768 | int ret; |
| 13769 | struct drm_plane_state *old_plane_state, *new_plane_state; |
| 13770 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13771 | struct drm_framebuffer *old_fb; |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13772 | struct intel_crtc_state *crtc_state = |
| 13773 | to_intel_crtc_state(crtc->state); |
| 13774 | struct intel_crtc_state *new_crtc_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13775 | |
| 13776 | /* |
| 13777 | * When crtc is inactive or there is a modeset pending, |
| 13778 | * wait for it to complete in the slowpath |
| 13779 | */ |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13780 | if (!crtc_state->base.active || needs_modeset(&crtc_state->base) || |
| 13781 | crtc_state->update_pipe) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13782 | goto slow; |
| 13783 | |
| 13784 | old_plane_state = plane->state; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13785 | /* |
| 13786 | * Don't do an async update if there is an outstanding commit modifying |
| 13787 | * the plane. This prevents our async update's changes from getting |
| 13788 | * overridden by a previous synchronous update's state. |
| 13789 | */ |
| 13790 | if (old_plane_state->commit && |
| 13791 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 13792 | goto slow; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13793 | |
| 13794 | /* |
| 13795 | * If any parameters change that may affect watermarks, |
| 13796 | * take the slowpath. Only changing fb or position should be |
| 13797 | * in the fastpath. |
| 13798 | */ |
| 13799 | if (old_plane_state->crtc != crtc || |
| 13800 | old_plane_state->src_w != src_w || |
| 13801 | old_plane_state->src_h != src_h || |
| 13802 | old_plane_state->crtc_w != crtc_w || |
| 13803 | old_plane_state->crtc_h != crtc_h || |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13804 | !old_plane_state->fb != !fb) |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13805 | goto slow; |
| 13806 | |
| 13807 | new_plane_state = intel_plane_duplicate_state(plane); |
| 13808 | if (!new_plane_state) |
| 13809 | return -ENOMEM; |
| 13810 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13811 | new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc)); |
| 13812 | if (!new_crtc_state) { |
| 13813 | ret = -ENOMEM; |
| 13814 | goto out_free; |
| 13815 | } |
| 13816 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13817 | drm_atomic_set_fb_for_plane(new_plane_state, fb); |
| 13818 | |
| 13819 | new_plane_state->src_x = src_x; |
| 13820 | new_plane_state->src_y = src_y; |
| 13821 | new_plane_state->src_w = src_w; |
| 13822 | new_plane_state->src_h = src_h; |
| 13823 | new_plane_state->crtc_x = crtc_x; |
| 13824 | new_plane_state->crtc_y = crtc_y; |
| 13825 | new_plane_state->crtc_w = crtc_w; |
| 13826 | new_plane_state->crtc_h = crtc_h; |
| 13827 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13828 | ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state, |
| 13829 | to_intel_plane_state(old_plane_state), |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13830 | to_intel_plane_state(new_plane_state)); |
| 13831 | if (ret) |
| 13832 | goto out_free; |
| 13833 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13834 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
| 13835 | if (ret) |
| 13836 | goto out_free; |
| 13837 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13838 | ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state)); |
| 13839 | if (ret) |
| 13840 | goto out_unlock; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13841 | |
Dhinakaran Pandiyan | a694e22 | 2018-03-06 19:34:19 -0800 | [diff] [blame] | 13842 | intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13843 | |
Dhinakaran Pandiyan | 07bcd99 | 2018-03-06 19:34:18 -0800 | [diff] [blame] | 13844 | old_fb = old_plane_state->fb; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13845 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), |
| 13846 | intel_plane->frontbuffer_bit); |
| 13847 | |
| 13848 | /* Swap plane state */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13849 | plane->state = new_plane_state; |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13850 | |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13851 | /* |
| 13852 | * We cannot swap crtc_state as it may be in use by an atomic commit or |
| 13853 | * page flip that's running simultaneously. If we swap crtc_state and |
| 13854 | * destroy the old state, we will cause a use-after-free there. |
| 13855 | * |
| 13856 | * Only update active_planes, which is needed for our internal |
| 13857 | * bookkeeping. Either value will do the right thing when updating |
| 13858 | * planes atomically. If the cursor was part of the atomic update then |
| 13859 | * we would have taken the slowpath. |
| 13860 | */ |
| 13861 | crtc_state->active_planes = new_crtc_state->active_planes; |
| 13862 | |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13863 | if (plane->state->visible) { |
| 13864 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13865 | intel_plane->update_plane(intel_plane, crtc_state, |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 13866 | to_intel_plane_state(plane->state)); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13867 | } else { |
| 13868 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); |
Ville Syrjälä | 0dd14be | 2018-11-14 23:07:20 +0200 | [diff] [blame] | 13869 | intel_plane->disable_plane(intel_plane, crtc_state); |
Ville Syrjälä | 7225953 | 2017-03-02 19:15:05 +0200 | [diff] [blame] | 13870 | } |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13871 | |
Ville Syrjälä | ef1a191 | 2018-02-21 18:02:34 +0200 | [diff] [blame] | 13872 | intel_plane_unpin_fb(to_intel_plane_state(old_plane_state)); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13873 | |
| 13874 | out_unlock: |
| 13875 | mutex_unlock(&dev_priv->drm.struct_mutex); |
| 13876 | out_free: |
Maarten Lankhorst | c249c5f | 2018-09-20 12:27:05 +0200 | [diff] [blame] | 13877 | if (new_crtc_state) |
| 13878 | intel_crtc_destroy_state(crtc, &new_crtc_state->base); |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 13879 | if (ret) |
| 13880 | intel_plane_destroy_state(plane, new_plane_state); |
| 13881 | else |
| 13882 | intel_plane_destroy_state(plane, old_plane_state); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13883 | return ret; |
| 13884 | |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13885 | slow: |
| 13886 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 13887 | crtc_x, crtc_y, crtc_w, crtc_h, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 13888 | src_x, src_y, src_w, src_h, ctx); |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13889 | } |
| 13890 | |
| 13891 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 13892 | .update_plane = intel_legacy_cursor_update, |
| 13893 | .disable_plane = drm_atomic_helper_disable_plane, |
| 13894 | .destroy = intel_plane_destroy, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13895 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13896 | .atomic_set_property = intel_plane_atomic_set_property, |
| 13897 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13898 | .atomic_destroy_state = intel_plane_destroy_state, |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13899 | .format_mod_supported = intel_cursor_format_mod_supported, |
Maarten Lankhorst | f79f269 | 2016-12-12 11:34:55 +0100 | [diff] [blame] | 13900 | }; |
| 13901 | |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13902 | static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv, |
| 13903 | enum i9xx_plane_id i9xx_plane) |
| 13904 | { |
| 13905 | if (!HAS_FBC(dev_priv)) |
| 13906 | return false; |
| 13907 | |
| 13908 | if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) |
| 13909 | return i9xx_plane == PLANE_A; /* tied to pipe A */ |
| 13910 | else if (IS_IVYBRIDGE(dev_priv)) |
| 13911 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B || |
| 13912 | i9xx_plane == PLANE_C; |
| 13913 | else if (INTEL_GEN(dev_priv) >= 4) |
| 13914 | return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B; |
| 13915 | else |
| 13916 | return i9xx_plane == PLANE_A; |
| 13917 | } |
| 13918 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 13919 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 13920 | 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] | 13921 | { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13922 | struct intel_plane *plane; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13923 | const struct drm_plane_funcs *plane_funcs; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 13924 | unsigned int supported_rotations; |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13925 | unsigned int possible_crtcs; |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13926 | const u64 *modifiers; |
| 13927 | const u32 *formats; |
| 13928 | int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13929 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13930 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13931 | if (INTEL_GEN(dev_priv) >= 9) |
| 13932 | return skl_universal_plane_create(dev_priv, pipe, |
| 13933 | PLANE_PRIMARY); |
| 13934 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13935 | plane = intel_plane_alloc(); |
| 13936 | if (IS_ERR(plane)) |
| 13937 | return plane; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13938 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13939 | plane->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13940 | /* |
| 13941 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 13942 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 13943 | */ |
| 13944 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13945 | plane->i9xx_plane = (enum i9xx_plane_id) !pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 13946 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13947 | plane->i9xx_plane = (enum i9xx_plane_id) pipe; |
| 13948 | plane->id = PLANE_PRIMARY; |
| 13949 | plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id); |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13950 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13951 | plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane); |
| 13952 | if (plane->has_fbc) { |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13953 | struct intel_fbc *fbc = &dev_priv->fbc; |
| 13954 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13955 | fbc->possible_framebuffer_bits |= plane->frontbuffer_bit; |
Ville Syrjälä | cf1805e | 2018-02-21 19:31:01 +0200 | [diff] [blame] | 13956 | } |
| 13957 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13958 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13959 | formats = i965_primary_formats; |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 13960 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13961 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13962 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13963 | plane->max_stride = i9xx_plane_max_stride; |
| 13964 | plane->update_plane = i9xx_update_plane; |
| 13965 | plane->disable_plane = i9xx_disable_plane; |
| 13966 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13967 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13968 | |
| 13969 | plane_funcs = &i965_plane_funcs; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13970 | } else { |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13971 | formats = i8xx_primary_formats; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13972 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 13973 | modifiers = i9xx_format_modifiers; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13974 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13975 | plane->max_stride = i9xx_plane_max_stride; |
| 13976 | plane->update_plane = i9xx_update_plane; |
| 13977 | plane->disable_plane = i9xx_disable_plane; |
| 13978 | plane->get_hw_state = i9xx_plane_get_hw_state; |
| 13979 | plane->check_plane = i9xx_plane_check; |
Ville Syrjälä | a38189c | 2018-05-18 19:21:59 +0300 | [diff] [blame] | 13980 | |
| 13981 | plane_funcs = &i8xx_plane_funcs; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13982 | } |
| 13983 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13984 | possible_crtcs = BIT(pipe); |
| 13985 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 13986 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13987 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13988 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13989 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13990 | DRM_PLANE_TYPE_PRIMARY, |
| 13991 | "primary %c", pipe_name(pipe)); |
| 13992 | else |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13993 | ret = drm_universal_plane_init(&dev_priv->drm, &plane->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 13994 | possible_crtcs, plane_funcs, |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13995 | formats, num_formats, modifiers, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 13996 | DRM_PLANE_TYPE_PRIMARY, |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 13997 | "plane %c", |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 13998 | plane_name(plane->i9xx_plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 13999 | if (ret) |
| 14000 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14001 | |
Ville Syrjälä | b7c8060 | 2018-10-05 15:58:15 +0300 | [diff] [blame] | 14002 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 14003 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14004 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
| 14005 | DRM_MODE_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14006 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14007 | supported_rotations = |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14008 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14009 | } else { |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14010 | supported_rotations = DRM_MODE_ROTATE_0; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14011 | } |
| 14012 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14013 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14014 | drm_plane_create_rotation_property(&plane->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14015 | DRM_MODE_ROTATE_0, |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14016 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14017 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14018 | drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14019 | |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14020 | return plane; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14021 | |
| 14022 | fail: |
Ville Syrjälä | 881440a | 2018-10-05 15:58:17 +0300 | [diff] [blame] | 14023 | intel_plane_free(plane); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14024 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14025 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14026 | } |
| 14027 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14028 | static struct intel_plane * |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14029 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
| 14030 | enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14031 | { |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14032 | unsigned int possible_crtcs; |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14033 | struct intel_plane *cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14034 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14035 | |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14036 | cursor = intel_plane_alloc(); |
| 14037 | if (IS_ERR(cursor)) |
| 14038 | return cursor; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14039 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14040 | cursor->pipe = pipe; |
Ville Syrjälä | ed15030 | 2017-11-17 21:19:10 +0200 | [diff] [blame] | 14041 | cursor->i9xx_plane = (enum i9xx_plane_id) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 14042 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | c19e112 | 2018-01-23 20:33:43 +0200 | [diff] [blame] | 14043 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id); |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14044 | |
| 14045 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14046 | cursor->max_stride = i845_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14047 | cursor->update_plane = i845_update_cursor; |
| 14048 | cursor->disable_plane = i845_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14049 | cursor->get_hw_state = i845_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14050 | cursor->check_plane = i845_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14051 | } else { |
Ville Syrjälä | ddd5713 | 2018-09-07 18:24:02 +0300 | [diff] [blame] | 14052 | cursor->max_stride = i9xx_cursor_max_stride; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14053 | cursor->update_plane = i9xx_update_cursor; |
| 14054 | cursor->disable_plane = i9xx_disable_cursor; |
Ville Syrjälä | 51f5a096 | 2017-11-17 21:19:08 +0200 | [diff] [blame] | 14055 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
Ville Syrjälä | 659056f | 2017-03-27 21:55:39 +0300 | [diff] [blame] | 14056 | cursor->check_plane = i9xx_check_cursor; |
Ville Syrjälä | b2d03b0 | 2017-03-27 21:55:37 +0300 | [diff] [blame] | 14057 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14058 | |
Ville Syrjälä | cd5dcbf | 2017-03-27 21:55:35 +0300 | [diff] [blame] | 14059 | cursor->cursor.base = ~0; |
| 14060 | cursor->cursor.cntl = ~0; |
Ville Syrjälä | 024faac | 2017-03-27 21:55:42 +0300 | [diff] [blame] | 14061 | |
| 14062 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) |
| 14063 | cursor->cursor.size = ~0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14064 | |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14065 | possible_crtcs = BIT(pipe); |
| 14066 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14067 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
Ville Syrjälä | deb1968 | 2018-10-05 15:58:08 +0300 | [diff] [blame] | 14068 | possible_crtcs, &intel_cursor_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14069 | intel_cursor_formats, |
| 14070 | ARRAY_SIZE(intel_cursor_formats), |
Ben Widawsky | 714244e | 2017-08-01 09:58:16 -0700 | [diff] [blame] | 14071 | cursor_format_modifiers, |
| 14072 | DRM_PLANE_TYPE_CURSOR, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 14073 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14074 | if (ret) |
| 14075 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14076 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 14077 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 14078 | drm_plane_create_rotation_property(&cursor->base, |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 14079 | DRM_MODE_ROTATE_0, |
| 14080 | DRM_MODE_ROTATE_0 | |
| 14081 | DRM_MODE_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14082 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14083 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14084 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14085 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14086 | |
| 14087 | fail: |
Ville Syrjälä | c539b57 | 2018-10-05 15:58:14 +0300 | [diff] [blame] | 14088 | intel_plane_free(cursor); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 14089 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14090 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14091 | } |
| 14092 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14093 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
| 14094 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14095 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14096 | struct intel_crtc_scaler_state *scaler_state = |
| 14097 | &crtc_state->scaler_state; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14098 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14099 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14100 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 14101 | crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe]; |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14102 | if (!crtc->num_scalers) |
| 14103 | return; |
| 14104 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 14105 | for (i = 0; i < crtc->num_scalers; i++) { |
| 14106 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 14107 | |
| 14108 | scaler->in_use = 0; |
Maarten Lankhorst | 0aaf29b | 2018-09-21 16:44:37 +0200 | [diff] [blame] | 14109 | scaler->mode = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14110 | } |
| 14111 | |
| 14112 | scaler_state->scaler_id = -1; |
| 14113 | } |
| 14114 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14115 | 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] | 14116 | { |
| 14117 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14118 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14119 | struct intel_plane *primary = NULL; |
| 14120 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14121 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14122 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14123 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14124 | if (!intel_crtc) |
| 14125 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14126 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14127 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14128 | if (!crtc_state) { |
| 14129 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14130 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14131 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14132 | intel_crtc->config = crtc_state; |
| 14133 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14134 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14135 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14136 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14137 | if (IS_ERR(primary)) { |
| 14138 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14139 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14140 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14141 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14142 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14143 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14144 | struct intel_plane *plane; |
| 14145 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14146 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14147 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14148 | ret = PTR_ERR(plane); |
| 14149 | goto fail; |
| 14150 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14151 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 14152 | } |
| 14153 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 14154 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 14155 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14156 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14157 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14158 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 14159 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14160 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 14161 | 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] | 14162 | &primary->base, &cursor->base, |
| 14163 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 14164 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14165 | if (ret) |
| 14166 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14167 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14168 | intel_crtc->pipe = pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14169 | |
Nabendu Maiti | 1c74eea | 2016-11-29 11:23:14 +0530 | [diff] [blame] | 14170 | /* initialize shared scalers */ |
| 14171 | intel_crtc_init_scalers(intel_crtc, crtc_state); |
| 14172 | |
Ville Syrjälä | 1947fd1 | 2018-03-05 19:41:22 +0200 | [diff] [blame] | 14173 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) || |
| 14174 | dev_priv->pipe_to_crtc_mapping[pipe] != NULL); |
| 14175 | dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc; |
| 14176 | |
| 14177 | if (INTEL_GEN(dev_priv) < 9) { |
| 14178 | enum i9xx_plane_id i9xx_plane = primary->i9xx_plane; |
| 14179 | |
| 14180 | BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14181 | dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL); |
| 14182 | dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc; |
| 14183 | } |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14184 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14185 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14186 | |
Matt Roper | 302da0c | 2018-12-10 13:54:15 -0800 | [diff] [blame] | 14187 | intel_color_init(intel_crtc); |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14188 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14189 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14190 | |
| 14191 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14192 | |
| 14193 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14194 | /* |
| 14195 | * drm_mode_config_cleanup() will free up any |
| 14196 | * crtcs/planes already initialized. |
| 14197 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14198 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14199 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 14200 | |
| 14201 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14202 | } |
| 14203 | |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 14204 | int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, |
| 14205 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14206 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14207 | 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] | 14208 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14209 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14210 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 14211 | 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] | 14212 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14213 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14214 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14215 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14216 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14217 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14218 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14219 | } |
| 14220 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14221 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14222 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14223 | struct drm_device *dev = encoder->base.dev; |
| 14224 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14225 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14226 | int entry = 0; |
| 14227 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14228 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14229 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14230 | index_mask |= (1 << entry); |
| 14231 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14232 | entry++; |
| 14233 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14234 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14235 | return index_mask; |
| 14236 | } |
| 14237 | |
Jani Nikula | a5916fd | 2019-01-22 10:23:05 +0200 | [diff] [blame] | 14238 | static bool ilk_has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14239 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 14240 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14241 | return false; |
| 14242 | |
| 14243 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14244 | return false; |
| 14245 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14246 | 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] | 14247 | return false; |
| 14248 | |
| 14249 | return true; |
| 14250 | } |
| 14251 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14252 | static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14253 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14254 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14255 | return false; |
| 14256 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 14257 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14258 | return false; |
| 14259 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14260 | if (HAS_PCH_LPT_H(dev_priv) && |
| 14261 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14262 | return false; |
| 14263 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14264 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14265 | 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] | 14266 | return false; |
| 14267 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14268 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14269 | return false; |
| 14270 | |
| 14271 | return true; |
| 14272 | } |
| 14273 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14274 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 14275 | { |
| 14276 | int pps_num; |
| 14277 | int pps_idx; |
| 14278 | |
| 14279 | if (HAS_DDI(dev_priv)) |
| 14280 | return; |
| 14281 | /* |
| 14282 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 14283 | * everywhere where registers can be write protected. |
| 14284 | */ |
| 14285 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14286 | pps_num = 2; |
| 14287 | else |
| 14288 | pps_num = 1; |
| 14289 | |
| 14290 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 14291 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 14292 | |
| 14293 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 14294 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 14295 | } |
| 14296 | } |
| 14297 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14298 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 14299 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 14300 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14301 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 14302 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 14303 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 14304 | else |
| 14305 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 14306 | |
| 14307 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14308 | } |
| 14309 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14310 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14311 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14312 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14313 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14314 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 14315 | intel_pps_init(dev_priv); |
| 14316 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 14317 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | fc0c5a9 | 2018-08-15 21:12:07 +0100 | [diff] [blame] | 14318 | return; |
| 14319 | |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14320 | if (IS_ICELAKE(dev_priv)) { |
| 14321 | intel_ddi_init(dev_priv, PORT_A); |
| 14322 | intel_ddi_init(dev_priv, PORT_B); |
| 14323 | intel_ddi_init(dev_priv, PORT_C); |
| 14324 | intel_ddi_init(dev_priv, PORT_D); |
| 14325 | intel_ddi_init(dev_priv, PORT_E); |
Imre Deak | 3f2e9ed | 2018-12-20 15:26:03 +0200 | [diff] [blame] | 14326 | /* |
| 14327 | * On some ICL SKUs port F is not present. No strap bits for |
| 14328 | * this, so rely on VBT. |
| 14329 | */ |
| 14330 | if (intel_bios_is_port_present(dev_priv, PORT_F)) |
| 14331 | intel_ddi_init(dev_priv, PORT_F); |
| 14332 | |
Madhav Chauhan | bf4d57f | 2018-10-30 13:56:23 +0200 | [diff] [blame] | 14333 | icl_dsi_init(dev_priv); |
Paulo Zanoni | 00c92d9 | 2018-05-21 17:25:47 -0700 | [diff] [blame] | 14334 | } else if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14335 | /* |
| 14336 | * FIXME: Broxton doesn't support port detection via the |
| 14337 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14338 | * detect the ports. |
| 14339 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14340 | intel_ddi_init(dev_priv, PORT_A); |
| 14341 | intel_ddi_init(dev_priv, PORT_B); |
| 14342 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14343 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14344 | vlv_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 14345 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14346 | int found; |
| 14347 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14348 | if (intel_ddi_crt_present(dev_priv)) |
| 14349 | intel_crt_init(dev_priv); |
| 14350 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14351 | /* |
| 14352 | * Haswell uses DDI functions to detect digital outputs. |
| 14353 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14354 | * it's there. |
| 14355 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14356 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14357 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14358 | if (found || IS_GEN9_BC(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14359 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14360 | |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14361 | /* 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] | 14362 | * register */ |
| 14363 | found = I915_READ(SFUSE_STRAP); |
| 14364 | |
| 14365 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14366 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14367 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14368 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14369 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14370 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 9787e83 | 2018-01-29 15:22:22 -0800 | [diff] [blame] | 14371 | if (found & SFUSE_STRAP_DDIF_DETECTED) |
| 14372 | intel_ddi_init(dev_priv, PORT_F); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14373 | /* |
| 14374 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14375 | */ |
Rodrigo Vivi | b976dc5 | 2017-01-23 10:32:37 -0800 | [diff] [blame] | 14376 | if (IS_GEN9_BC(dev_priv) && |
Imre Deak | e9d49bb | 2018-12-20 15:26:02 +0200 | [diff] [blame] | 14377 | intel_bios_is_port_present(dev_priv, PORT_E)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14378 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14379 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 14380 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14381 | int found; |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14382 | |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14383 | /* |
| 14384 | * intel_edp_init_connector() depends on this completing first, |
| 14385 | * to prevent the registration of both eDP and LVDS and the |
| 14386 | * incorrect sharing of the PPS. |
| 14387 | */ |
| 14388 | intel_lvds_init(dev_priv); |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14389 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14390 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14391 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14392 | |
Jani Nikula | a5916fd | 2019-01-22 10:23:05 +0200 | [diff] [blame] | 14393 | if (ilk_has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14394 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14395 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14396 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14397 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14398 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14399 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14400 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14401 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14402 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14403 | } |
| 14404 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14405 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14406 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14407 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14408 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14409 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14410 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14411 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14412 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14413 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14414 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14415 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14416 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14417 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 14418 | |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14419 | if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support) |
| 14420 | intel_crt_init(dev_priv); |
| 14421 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14422 | /* |
| 14423 | * The DP_DETECTED bit is the latched state of the DDC |
| 14424 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14425 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14426 | * eDP ports may have been muxed to an alternate function. |
| 14427 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14428 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14429 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14430 | * |
| 14431 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 14432 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 14433 | * and VBT for the presence of the port. Additionally we can't |
| 14434 | * trust the port type the VBT declares as we've seen at least |
| 14435 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14436 | */ |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14437 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14438 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 14439 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14440 | 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] | 14441 | 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] | 14442 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14443 | |
Jani Nikula | 7b91bf7 | 2017-08-18 12:30:19 +0300 | [diff] [blame] | 14444 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14445 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 14446 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14447 | 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] | 14448 | 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] | 14449 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14450 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14451 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14452 | /* |
| 14453 | * eDP not supported on port D, |
| 14454 | * so no need to worry about it |
| 14455 | */ |
| 14456 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 14457 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14458 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 14459 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14460 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14461 | } |
| 14462 | |
Jani Nikula | e518634 | 2018-07-05 16:25:08 +0300 | [diff] [blame] | 14463 | vlv_dsi_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14464 | } else if (IS_PINEVIEW(dev_priv)) { |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14465 | intel_lvds_init(dev_priv); |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14466 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14467 | } else if (IS_GEN_RANGE(dev_priv, 3, 4)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14468 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14469 | |
Jani Nikula | 9bedc7e | 2019-01-22 10:23:03 +0200 | [diff] [blame] | 14470 | if (IS_MOBILE(dev_priv)) |
| 14471 | intel_lvds_init(dev_priv); |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14472 | |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14473 | intel_crt_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14474 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14475 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14476 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14477 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14478 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14479 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14480 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14481 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14482 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14483 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14484 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14485 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14486 | |
| 14487 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14488 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14489 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14490 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14491 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14492 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14493 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14494 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14495 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14496 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14497 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14498 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14499 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14500 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14501 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14502 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14503 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 14504 | 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] | 14505 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Jani Nikula | d652146 | 2019-01-22 10:23:04 +0200 | [diff] [blame] | 14506 | |
| 14507 | if (SUPPORTS_TV(dev_priv)) |
| 14508 | intel_tv_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14509 | } else if (IS_GEN(dev_priv, 2)) { |
Jani Nikula | 346073c | 2019-01-22 10:23:06 +0200 | [diff] [blame] | 14510 | if (IS_I85X(dev_priv)) |
Jani Nikula | 9bedc7e | 2019-01-22 10:23:03 +0200 | [diff] [blame] | 14511 | intel_lvds_init(dev_priv); |
Jani Nikula | 0fafa22 | 2019-01-22 10:23:02 +0200 | [diff] [blame] | 14512 | |
Jani Nikula | 74d021e | 2019-01-22 10:23:07 +0200 | [diff] [blame] | 14513 | intel_crt_init(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14514 | intel_dvo_init(dev_priv); |
Jani Nikula | 63cb4e6 | 2019-01-22 10:23:01 +0200 | [diff] [blame] | 14515 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14516 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14517 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14518 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14519 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14520 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14521 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14522 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14523 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14524 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14525 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14526 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 14527 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14528 | } |
| 14529 | |
| 14530 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14531 | { |
| 14532 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14533 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14534 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14535 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14536 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14537 | i915_gem_object_lock(obj); |
| 14538 | WARN_ON(!obj->framebuffer_references--); |
| 14539 | i915_gem_object_unlock(obj); |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14540 | |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14541 | i915_gem_object_put(obj); |
Chris Wilson | 70001cd | 2017-02-16 09:46:21 +0000 | [diff] [blame] | 14542 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14543 | kfree(intel_fb); |
| 14544 | } |
| 14545 | |
| 14546 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14547 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14548 | unsigned int *handle) |
| 14549 | { |
Daniel Stone | a5ff7a4 | 2018-05-18 15:30:07 +0100 | [diff] [blame] | 14550 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14551 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14552 | if (obj->userptr.mm) { |
| 14553 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14554 | return -EINVAL; |
| 14555 | } |
| 14556 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14557 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14558 | } |
| 14559 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14560 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14561 | struct drm_file *file, |
| 14562 | unsigned flags, unsigned color, |
| 14563 | struct drm_clip_rect *clips, |
| 14564 | unsigned num_clips) |
| 14565 | { |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14566 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14567 | |
Chris Wilson | 5a97bcc | 2017-02-22 11:40:46 +0000 | [diff] [blame] | 14568 | i915_gem_object_flush_if_display(obj); |
Chris Wilson | d59b21e | 2017-02-22 11:40:49 +0000 | [diff] [blame] | 14569 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14570 | |
| 14571 | return 0; |
| 14572 | } |
| 14573 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14574 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14575 | .destroy = intel_user_framebuffer_destroy, |
| 14576 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14577 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14578 | }; |
| 14579 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14580 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14581 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14582 | u32 pixel_format, u64 fb_modifier) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14583 | { |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14584 | struct intel_crtc *crtc; |
| 14585 | struct intel_plane *plane; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14586 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14587 | /* |
| 14588 | * We assume the primary plane for pipe A has |
| 14589 | * the highest stride limits of them all. |
| 14590 | */ |
| 14591 | crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A); |
| 14592 | plane = to_intel_plane(crtc->base.primary); |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14593 | |
Ville Syrjälä | 645d91f | 2018-09-07 18:24:03 +0300 | [diff] [blame] | 14594 | return plane->max_stride(plane, pixel_format, fb_modifier, |
| 14595 | DRM_MODE_ROTATE_0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14596 | } |
| 14597 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14598 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
| 14599 | struct drm_i915_gem_object *obj, |
| 14600 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14601 | { |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14602 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14603 | struct drm_framebuffer *fb = &intel_fb->base; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14604 | u32 pitch_limit; |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14605 | unsigned int tiling, stride; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14606 | int ret = -EINVAL; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14607 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14608 | |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14609 | i915_gem_object_lock(obj); |
| 14610 | obj->framebuffer_references++; |
| 14611 | tiling = i915_gem_object_get_tiling(obj); |
| 14612 | stride = i915_gem_object_get_stride(obj); |
| 14613 | i915_gem_object_unlock(obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14614 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14615 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14616 | /* |
| 14617 | * If there's a fence, enforce that |
| 14618 | * the fb modifier and tiling mode match. |
| 14619 | */ |
| 14620 | if (tiling != I915_TILING_NONE && |
| 14621 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14622 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14623 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14624 | } |
| 14625 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14626 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14627 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14628 | } else if (tiling == I915_TILING_Y) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14629 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14630 | goto err; |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14631 | } |
| 14632 | } |
| 14633 | |
Ville Syrjälä | 17e8fd1 | 2018-10-29 20:34:53 +0200 | [diff] [blame] | 14634 | if (!drm_any_plane_has_format(&dev_priv->drm, |
| 14635 | mode_cmd->pixel_format, |
| 14636 | mode_cmd->modifier[0])) { |
| 14637 | struct drm_format_name_buf format_name; |
| 14638 | |
| 14639 | DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n", |
| 14640 | drm_get_format_name(mode_cmd->pixel_format, |
| 14641 | &format_name), |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14642 | mode_cmd->modifier[0]); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14643 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14644 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14645 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14646 | /* |
| 14647 | * gen2/3 display engine uses the fence if present, |
| 14648 | * so the tiling mode must match the fb modifier exactly. |
| 14649 | */ |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14650 | if (INTEL_GEN(dev_priv) < 4 && |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14651 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14652 | 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] | 14653 | goto err; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14654 | } |
| 14655 | |
Dhinakaran Pandiyan | 4c8d351 | 2018-10-26 12:53:42 -0700 | [diff] [blame] | 14656 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format, |
| 14657 | mode_cmd->modifier[0]); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14658 | if (mode_cmd->pitches[0] > pitch_limit) { |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14659 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
Ben Widawsky | 2f07556 | 2017-03-24 14:29:48 -0700 | [diff] [blame] | 14660 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14661 | "tiled" : "linear", |
| 14662 | mode_cmd->pitches[0], pitch_limit); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14663 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14664 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14665 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 14666 | /* |
| 14667 | * If there's a fence, enforce that |
| 14668 | * the fb pitch and fence stride match. |
| 14669 | */ |
Ville Syrjälä | 144cc143 | 2017-03-07 21:42:10 +0200 | [diff] [blame] | 14670 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
| 14671 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", |
| 14672 | mode_cmd->pitches[0], stride); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14673 | goto err; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14674 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14675 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14676 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14677 | if (mode_cmd->offsets[0] != 0) |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14678 | goto err; |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14679 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14680 | 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] | 14681 | |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14682 | if (fb->format->format == DRM_FORMAT_NV12 && |
| 14683 | (fb->width < SKL_MIN_YUV_420_SRC_W || |
| 14684 | fb->height < SKL_MIN_YUV_420_SRC_H || |
| 14685 | (fb->width % 4) != 0 || (fb->height % 4) != 0)) { |
| 14686 | DRM_DEBUG_KMS("src dimensions not correct for NV12\n"); |
Ville Syrjälä | 3b90946 | 2018-10-29 16:00:31 +0200 | [diff] [blame] | 14687 | goto err; |
Chandra Konduru | e44134f | 2018-05-12 03:03:15 +0530 | [diff] [blame] | 14688 | } |
| 14689 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14690 | for (i = 0; i < fb->format->num_planes; i++) { |
| 14691 | u32 stride_alignment; |
| 14692 | |
| 14693 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { |
| 14694 | DRM_DEBUG_KMS("bad plane %d handle\n", i); |
Christophe JAILLET | 37875d6 | 2017-09-10 10:56:42 +0200 | [diff] [blame] | 14695 | goto err; |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14696 | } |
| 14697 | |
| 14698 | stride_alignment = intel_fb_stride_alignment(fb, i); |
| 14699 | |
| 14700 | /* |
| 14701 | * Display WA #0531: skl,bxt,kbl,glk |
| 14702 | * |
| 14703 | * Render decompression and plane width > 3840 |
| 14704 | * combined with horizontal panning requires the |
| 14705 | * plane stride to be a multiple of 4. We'll just |
| 14706 | * require the entire fb to accommodate that to avoid |
| 14707 | * potential runtime errors at plane configuration time. |
| 14708 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14709 | if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 && |
Dhinakaran Pandiyan | 63eaf9a | 2018-08-22 12:38:27 -0700 | [diff] [blame] | 14710 | is_ccs_modifier(fb->modifier)) |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14711 | stride_alignment *= 4; |
| 14712 | |
| 14713 | if (fb->pitches[i] & (stride_alignment - 1)) { |
| 14714 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", |
| 14715 | i, fb->pitches[i], stride_alignment); |
| 14716 | goto err; |
| 14717 | } |
Ville Syrjälä | d88c4af | 2017-03-07 21:42:06 +0200 | [diff] [blame] | 14718 | |
Daniel Stone | a268bcd | 2018-05-18 15:30:08 +0100 | [diff] [blame] | 14719 | fb->obj[i] = &obj->base; |
| 14720 | } |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14721 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14722 | ret = intel_fill_fb_info(dev_priv, fb); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 14723 | if (ret) |
Chris Wilson | 9aceb5c1 | 2017-03-01 15:41:27 +0000 | [diff] [blame] | 14724 | goto err; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14725 | |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 14726 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14727 | if (ret) { |
| 14728 | DRM_ERROR("framebuffer init failed %d\n", ret); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14729 | goto err; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14730 | } |
| 14731 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14732 | return 0; |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14733 | |
| 14734 | err: |
Chris Wilson | dd68928 | 2017-03-01 15:41:28 +0000 | [diff] [blame] | 14735 | i915_gem_object_lock(obj); |
| 14736 | obj->framebuffer_references--; |
| 14737 | i915_gem_object_unlock(obj); |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14738 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14739 | } |
| 14740 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14741 | static struct drm_framebuffer * |
| 14742 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14743 | struct drm_file *filp, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14744 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14745 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14746 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14747 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14748 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14749 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 14750 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 14751 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14752 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14753 | |
Chris Wilson | 24dbf51 | 2017-02-15 10:59:18 +0000 | [diff] [blame] | 14754 | fb = intel_framebuffer_create(obj, &mode_cmd); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14755 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 14756 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14757 | |
| 14758 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14759 | } |
| 14760 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14761 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 14762 | { |
| 14763 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14764 | |
| 14765 | drm_atomic_state_default_release(state); |
| 14766 | |
| 14767 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 14768 | |
| 14769 | kfree(state); |
| 14770 | } |
| 14771 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14772 | static enum drm_mode_status |
| 14773 | intel_mode_valid(struct drm_device *dev, |
| 14774 | const struct drm_display_mode *mode) |
| 14775 | { |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14776 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14777 | int hdisplay_max, htotal_max; |
| 14778 | int vdisplay_max, vtotal_max; |
| 14779 | |
Ville Syrjälä | e4dd27a | 2018-05-24 15:54:03 +0300 | [diff] [blame] | 14780 | /* |
| 14781 | * Can't reject DBLSCAN here because Xorg ddxen can add piles |
| 14782 | * of DBLSCAN modes to the output's mode list when they detect |
| 14783 | * the scaling mode property on the connector. And they don't |
| 14784 | * ask the kernel to validate those modes in any way until |
| 14785 | * modeset time at which point the client gets a protocol error. |
| 14786 | * So in order to not upset those clients we silently ignore the |
| 14787 | * DBLSCAN flag on such connectors. For other connectors we will |
| 14788 | * reject modes with the DBLSCAN flag in encoder->compute_config(). |
| 14789 | * And we always reject DBLSCAN modes in connector->mode_valid() |
| 14790 | * as we never want such modes on the connector's mode list. |
| 14791 | */ |
| 14792 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14793 | if (mode->vscan > 1) |
| 14794 | return MODE_NO_VSCAN; |
| 14795 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14796 | if (mode->flags & DRM_MODE_FLAG_HSKEW) |
| 14797 | return MODE_H_ILLEGAL; |
| 14798 | |
| 14799 | if (mode->flags & (DRM_MODE_FLAG_CSYNC | |
| 14800 | DRM_MODE_FLAG_NCSYNC | |
| 14801 | DRM_MODE_FLAG_PCSYNC)) |
| 14802 | return MODE_HSYNC; |
| 14803 | |
| 14804 | if (mode->flags & (DRM_MODE_FLAG_BCAST | |
| 14805 | DRM_MODE_FLAG_PIXMUX | |
| 14806 | DRM_MODE_FLAG_CLKDIV2)) |
| 14807 | return MODE_BAD; |
| 14808 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 14809 | if (INTEL_GEN(dev_priv) >= 9 || |
| 14810 | IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { |
| 14811 | hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ |
| 14812 | vdisplay_max = 4096; |
| 14813 | htotal_max = 8192; |
| 14814 | vtotal_max = 8192; |
| 14815 | } else if (INTEL_GEN(dev_priv) >= 3) { |
| 14816 | hdisplay_max = 4096; |
| 14817 | vdisplay_max = 4096; |
| 14818 | htotal_max = 8192; |
| 14819 | vtotal_max = 8192; |
| 14820 | } else { |
| 14821 | hdisplay_max = 2048; |
| 14822 | vdisplay_max = 2048; |
| 14823 | htotal_max = 4096; |
| 14824 | vtotal_max = 4096; |
| 14825 | } |
| 14826 | |
| 14827 | if (mode->hdisplay > hdisplay_max || |
| 14828 | mode->hsync_start > htotal_max || |
| 14829 | mode->hsync_end > htotal_max || |
| 14830 | mode->htotal > htotal_max) |
| 14831 | return MODE_H_ILLEGAL; |
| 14832 | |
| 14833 | if (mode->vdisplay > vdisplay_max || |
| 14834 | mode->vsync_start > vtotal_max || |
| 14835 | mode->vsync_end > vtotal_max || |
| 14836 | mode->vtotal > vtotal_max) |
| 14837 | return MODE_V_ILLEGAL; |
| 14838 | |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14839 | return MODE_OK; |
| 14840 | } |
| 14841 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14842 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14843 | .fb_create = intel_user_framebuffer_create, |
Ville Syrjälä | bbfb6ce | 2017-08-01 09:58:12 -0700 | [diff] [blame] | 14844 | .get_format_info = intel_get_format_info, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14845 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Ville Syrjälä | e995ca0b | 2017-11-14 20:32:58 +0200 | [diff] [blame] | 14846 | .mode_valid = intel_mode_valid, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14847 | .atomic_check = intel_atomic_check, |
| 14848 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14849 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14850 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 14851 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14852 | }; |
| 14853 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14854 | /** |
| 14855 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14856 | * @dev_priv: device private |
| 14857 | */ |
| 14858 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14859 | { |
Ville Syrjälä | 7ff89ca | 2017-02-07 20:33:05 +0200 | [diff] [blame] | 14860 | intel_init_cdclk_hooks(dev_priv); |
| 14861 | |
Tvrtko Ursulin | c56b89f | 2018-02-09 21:58:46 +0000 | [diff] [blame] | 14862 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14863 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14864 | dev_priv->display.get_initial_plane_config = |
| 14865 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14866 | dev_priv->display.crtc_compute_clock = |
| 14867 | haswell_crtc_compute_clock; |
| 14868 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14869 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14870 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14871 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14872 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14873 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14874 | dev_priv->display.crtc_compute_clock = |
| 14875 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14876 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14877 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14878 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14879 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14880 | dev_priv->display.get_initial_plane_config = |
Ville Syrjälä | 81894b2 | 2017-11-17 21:19:13 +0200 | [diff] [blame] | 14881 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14882 | dev_priv->display.crtc_compute_clock = |
| 14883 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14884 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14885 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14886 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14887 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14888 | dev_priv->display.get_initial_plane_config = |
| 14889 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14890 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 14891 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14892 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14893 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 14894 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14895 | dev_priv->display.get_initial_plane_config = |
| 14896 | i9xx_get_initial_plane_config; |
| 14897 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14898 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14899 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 14900 | } else if (IS_G4X(dev_priv)) { |
| 14901 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14902 | dev_priv->display.get_initial_plane_config = |
| 14903 | i9xx_get_initial_plane_config; |
| 14904 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 14905 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14906 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 14907 | } else if (IS_PINEVIEW(dev_priv)) { |
| 14908 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14909 | dev_priv->display.get_initial_plane_config = |
| 14910 | i9xx_get_initial_plane_config; |
| 14911 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 14912 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14913 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14914 | } else if (!IS_GEN(dev_priv, 2)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14915 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14916 | dev_priv->display.get_initial_plane_config = |
| 14917 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14918 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14919 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14920 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14921 | } else { |
| 14922 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14923 | dev_priv->display.get_initial_plane_config = |
| 14924 | i9xx_get_initial_plane_config; |
| 14925 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 14926 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14927 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14928 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14929 | |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14930 | if (IS_GEN(dev_priv, 5)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14931 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 14932 | } else if (IS_GEN(dev_priv, 6)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14933 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14934 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14935 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14936 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14937 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14938 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 14939 | } |
| 14940 | |
Rodrigo Vivi | bd30ca2 | 2017-09-26 14:13:46 -0700 | [diff] [blame] | 14941 | if (INTEL_GEN(dev_priv) >= 9) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14942 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 14943 | else |
| 14944 | dev_priv->display.update_crtcs = intel_update_crtcs; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14945 | } |
| 14946 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14947 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 14948 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14949 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14950 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14951 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 14952 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14953 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14954 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14955 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14956 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14957 | sr1 = inb(VGA_SR_DATA); |
| 14958 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 14959 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14960 | udelay(300); |
| 14961 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14962 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14963 | POSTING_READ(vga_reg); |
| 14964 | } |
| 14965 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14966 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14967 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14968 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 14969 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 14970 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | cfddadc | 2017-10-24 12:52:16 +0300 | [diff] [blame] | 14971 | intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK"); |
Ville Syrjälä | bb0f4aa | 2017-01-20 20:21:59 +0200 | [diff] [blame] | 14972 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14973 | } |
| 14974 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14975 | /* |
| 14976 | * Calculate what we think the watermarks should be for the state we've read |
| 14977 | * out of the hardware and then immediately program those watermarks so that |
| 14978 | * we ensure the hardware settings match our internal state. |
| 14979 | * |
| 14980 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 14981 | * current state (which was constructed during hardware readout) and running it |
| 14982 | * through the atomic check code to calculate new watermark values in the |
| 14983 | * state object. |
| 14984 | */ |
| 14985 | static void sanitize_watermarks(struct drm_device *dev) |
| 14986 | { |
| 14987 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14988 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14989 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14990 | struct drm_crtc *crtc; |
| 14991 | struct drm_crtc_state *cstate; |
| 14992 | struct drm_modeset_acquire_ctx ctx; |
| 14993 | int ret; |
| 14994 | int i; |
| 14995 | |
| 14996 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14997 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 14998 | return; |
| 14999 | |
| 15000 | /* |
| 15001 | * We need to hold connection_mutex before calling duplicate_state so |
| 15002 | * that the connector loop is protected. |
| 15003 | */ |
| 15004 | drm_modeset_acquire_init(&ctx, 0); |
| 15005 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15006 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15007 | if (ret == -EDEADLK) { |
| 15008 | drm_modeset_backoff(&ctx); |
| 15009 | goto retry; |
| 15010 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15011 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15012 | } |
| 15013 | |
| 15014 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 15015 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15016 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15017 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15018 | intel_state = to_intel_atomic_state(state); |
| 15019 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15020 | /* |
| 15021 | * Hardware readout is the only time we don't want to calculate |
| 15022 | * intermediate watermarks (since we don't trust the current |
| 15023 | * watermarks). |
| 15024 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15025 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 15026 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15027 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15028 | ret = intel_atomic_check(dev, state); |
| 15029 | if (ret) { |
| 15030 | /* |
| 15031 | * If we fail here, it means that the hardware appears to be |
| 15032 | * programmed in a way that shouldn't be possible, given our |
| 15033 | * understanding of watermark requirements. This might mean a |
| 15034 | * mistake in the hardware readout code or a mistake in the |
| 15035 | * watermark calculations for a given platform. Raise a WARN |
| 15036 | * so that this is noticeable. |
| 15037 | * |
| 15038 | * If this actually happens, we'll have to just leave the |
| 15039 | * BIOS-programmed watermarks untouched and hope for the best. |
| 15040 | */ |
| 15041 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 15042 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15043 | } |
| 15044 | |
| 15045 | /* Write calculated watermark values back */ |
Maarten Lankhorst | aa5e9b4 | 2017-03-09 15:52:04 +0100 | [diff] [blame] | 15046 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15047 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 15048 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15049 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 15050 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Maarten Lankhorst | 556fe36 | 2017-11-10 12:34:53 +0100 | [diff] [blame] | 15051 | |
| 15052 | to_intel_crtc_state(crtc->state)->wm = cs->wm; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15053 | } |
| 15054 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 15055 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15056 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15057 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15058 | drm_modeset_drop_locks(&ctx); |
| 15059 | drm_modeset_acquire_fini(&ctx); |
| 15060 | } |
| 15061 | |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15062 | static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv) |
| 15063 | { |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15064 | if (IS_GEN(dev_priv, 5)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15065 | u32 fdi_pll_clk = |
| 15066 | I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK; |
| 15067 | |
| 15068 | dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15069 | } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) { |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15070 | dev_priv->fdi_pll_freq = 270000; |
| 15071 | } else { |
| 15072 | return; |
| 15073 | } |
| 15074 | |
| 15075 | DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq); |
| 15076 | } |
| 15077 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15078 | static int intel_initial_commit(struct drm_device *dev) |
| 15079 | { |
| 15080 | struct drm_atomic_state *state = NULL; |
| 15081 | struct drm_modeset_acquire_ctx ctx; |
| 15082 | struct drm_crtc *crtc; |
| 15083 | struct drm_crtc_state *crtc_state; |
| 15084 | int ret = 0; |
| 15085 | |
| 15086 | state = drm_atomic_state_alloc(dev); |
| 15087 | if (!state) |
| 15088 | return -ENOMEM; |
| 15089 | |
| 15090 | drm_modeset_acquire_init(&ctx, 0); |
| 15091 | |
| 15092 | retry: |
| 15093 | state->acquire_ctx = &ctx; |
| 15094 | |
| 15095 | drm_for_each_crtc(crtc, dev) { |
| 15096 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 15097 | if (IS_ERR(crtc_state)) { |
| 15098 | ret = PTR_ERR(crtc_state); |
| 15099 | goto out; |
| 15100 | } |
| 15101 | |
| 15102 | if (crtc_state->active) { |
| 15103 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 15104 | if (ret) |
| 15105 | goto out; |
Ville Syrjälä | fa6af514 | 2018-11-20 15:54:49 +0200 | [diff] [blame] | 15106 | |
| 15107 | /* |
| 15108 | * FIXME hack to force a LUT update to avoid the |
| 15109 | * plane update forcing the pipe gamma on without |
| 15110 | * having a proper LUT loaded. Remove once we |
| 15111 | * have readout for pipe gamma enable. |
| 15112 | */ |
| 15113 | crtc_state->color_mgmt_changed = true; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15114 | } |
| 15115 | } |
| 15116 | |
| 15117 | ret = drm_atomic_commit(state); |
| 15118 | |
| 15119 | out: |
| 15120 | if (ret == -EDEADLK) { |
| 15121 | drm_atomic_state_clear(state); |
| 15122 | drm_modeset_backoff(&ctx); |
| 15123 | goto retry; |
| 15124 | } |
| 15125 | |
| 15126 | drm_atomic_state_put(state); |
| 15127 | |
| 15128 | drm_modeset_drop_locks(&ctx); |
| 15129 | drm_modeset_acquire_fini(&ctx); |
| 15130 | |
| 15131 | return ret; |
| 15132 | } |
| 15133 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15134 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15135 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15136 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15137 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15138 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15139 | struct intel_crtc *crtc; |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15140 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15141 | |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 15142 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
| 15143 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15144 | drm_mode_config_init(dev); |
| 15145 | |
| 15146 | dev->mode_config.min_width = 0; |
| 15147 | dev->mode_config.min_height = 0; |
| 15148 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15149 | dev->mode_config.preferred_depth = 24; |
| 15150 | dev->mode_config.prefer_shadow = 1; |
| 15151 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15152 | dev->mode_config.allow_fb_modifiers = true; |
| 15153 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15154 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15155 | |
Andrea Arcangeli | 400c19d | 2017-04-07 01:23:45 +0200 | [diff] [blame] | 15156 | init_llist_head(&dev_priv->atomic_helper.free_list); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15157 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
Chris Wilson | ba318c6 | 2017-02-02 20:47:41 +0000 | [diff] [blame] | 15158 | intel_atomic_helper_free_state_worker); |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 15159 | |
Jani Nikula | 27a981b | 2018-10-17 12:35:39 +0300 | [diff] [blame] | 15160 | intel_init_quirks(dev_priv); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15161 | |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 15162 | intel_fbc_init(dev_priv); |
| 15163 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 15164 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15165 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15166 | /* |
| 15167 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15168 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15169 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15170 | * indicates as much. |
| 15171 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15172 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15173 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15174 | DREF_SSC1_ENABLE); |
| 15175 | |
| 15176 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15177 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15178 | bios_lvds_use_ssc ? "en" : "dis", |
| 15179 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15180 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15181 | } |
| 15182 | } |
| 15183 | |
Ville Syrjälä | ad77c53 | 2018-06-15 20:44:05 +0300 | [diff] [blame] | 15184 | /* maximum framebuffer dimensions */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15185 | if (IS_GEN(dev_priv, 2)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15186 | dev->mode_config.max_width = 2048; |
| 15187 | dev->mode_config.max_height = 2048; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15188 | } else if (IS_GEN(dev_priv, 3)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15189 | dev->mode_config.max_width = 4096; |
| 15190 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15191 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15192 | dev->mode_config.max_width = 8192; |
| 15193 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15194 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15195 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 15196 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 15197 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15198 | dev->mode_config.cursor_height = 1023; |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 15199 | } else if (IS_GEN(dev_priv, 2)) { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15200 | dev->mode_config.cursor_width = 64; |
| 15201 | dev->mode_config.cursor_height = 64; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15202 | } else { |
Ville Syrjälä | 98fac1d | 2018-06-15 20:44:04 +0300 | [diff] [blame] | 15203 | dev->mode_config.cursor_width = 256; |
| 15204 | dev->mode_config.cursor_height = 256; |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15205 | } |
| 15206 | |
Matthew Auld | 73ebd50 | 2017-12-11 15:18:20 +0000 | [diff] [blame] | 15207 | dev->mode_config.fb_base = ggtt->gmadr.start; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15208 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15209 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15210 | INTEL_INFO(dev_priv)->num_pipes, |
| 15211 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15212 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15213 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15214 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15215 | if (ret) { |
| 15216 | drm_mode_config_cleanup(dev); |
| 15217 | return ret; |
| 15218 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15219 | } |
| 15220 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15221 | intel_shared_dpll_init(dev); |
Chris Wilson | 58ecd9d | 2017-11-05 13:49:05 +0000 | [diff] [blame] | 15222 | intel_update_fdi_pll_freq(dev_priv); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15223 | |
Ville Syrjälä | 5be6e33 | 2017-02-20 16:04:43 +0200 | [diff] [blame] | 15224 | intel_update_czclk(dev_priv); |
| 15225 | intel_modeset_init_hw(dev); |
| 15226 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15227 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 15228 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 15229 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15230 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15231 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15232 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15233 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15234 | drm_modeset_lock_all(dev); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15235 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15236 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15237 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15238 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15239 | struct intel_initial_plane_config plane_config = {}; |
| 15240 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15241 | if (!crtc->active) |
| 15242 | continue; |
| 15243 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15244 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15245 | * Note that reserving the BIOS fb up front prevents us |
| 15246 | * from stuffing other stolen allocations like the ring |
| 15247 | * on top. This prevents some ugliness at boot time, and |
| 15248 | * can even allow for smooth boot transitions if the BIOS |
| 15249 | * fb is large enough for the active pipe configuration. |
| 15250 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15251 | dev_priv->display.get_initial_plane_config(crtc, |
| 15252 | &plane_config); |
| 15253 | |
| 15254 | /* |
| 15255 | * If the fb is shared between multiple heads, we'll |
| 15256 | * just get the first one. |
| 15257 | */ |
| 15258 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15259 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15260 | |
| 15261 | /* |
| 15262 | * Make sure hardware watermarks really match the state we read out. |
| 15263 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15264 | * since the watermark calculation done here will use pstate->fb. |
| 15265 | */ |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15266 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
| 15267 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15268 | |
Azhar Shaikh | 516a49c | 2018-07-06 11:37:30 -0700 | [diff] [blame] | 15269 | /* |
| 15270 | * Force all active planes to recompute their states. So that on |
| 15271 | * mode_setcrtc after probe, all the intel_plane_state variables |
| 15272 | * are already calculated and there is no assert_plane warnings |
| 15273 | * during bootup. |
| 15274 | */ |
| 15275 | ret = intel_initial_commit(dev); |
| 15276 | if (ret) |
| 15277 | DRM_DEBUG_KMS("Initial commit in probe failed.\n"); |
| 15278 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15279 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15280 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15281 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15282 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15283 | { |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15284 | 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] | 15285 | /* 640x480@60Hz, ~25175 kHz */ |
| 15286 | struct dpll clock = { |
| 15287 | .m1 = 18, |
| 15288 | .m2 = 7, |
| 15289 | .p1 = 13, |
| 15290 | .p2 = 4, |
| 15291 | .n = 2, |
| 15292 | }; |
| 15293 | u32 dpll, fp; |
| 15294 | int i; |
| 15295 | |
| 15296 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); |
| 15297 | |
| 15298 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", |
| 15299 | pipe_name(pipe), clock.vco, clock.dot); |
| 15300 | |
| 15301 | fp = i9xx_dpll_compute_fp(&clock); |
| 15302 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | |
| 15303 | DPLL_VGA_MODE_DIS | |
| 15304 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | |
| 15305 | PLL_P2_DIVIDE_BY_4 | |
| 15306 | PLL_REF_INPUT_DREFCLK | |
| 15307 | DPLL_VCO_ENABLE; |
| 15308 | |
| 15309 | I915_WRITE(FP0(pipe), fp); |
| 15310 | I915_WRITE(FP1(pipe), fp); |
| 15311 | |
| 15312 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15313 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); |
| 15314 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); |
| 15315 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15316 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); |
| 15317 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); |
| 15318 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); |
| 15319 | |
| 15320 | /* |
| 15321 | * Apparently we need to have VGA mode enabled prior to changing |
| 15322 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 15323 | * dividers, even though the register value does change. |
| 15324 | */ |
| 15325 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); |
| 15326 | I915_WRITE(DPLL(pipe), dpll); |
| 15327 | |
| 15328 | /* Wait for the clocks to stabilize. */ |
| 15329 | POSTING_READ(DPLL(pipe)); |
| 15330 | udelay(150); |
| 15331 | |
| 15332 | /* The pixel multiplier can only be updated once the |
| 15333 | * DPLL is enabled and the clocks are stable. |
| 15334 | * |
| 15335 | * So write it again. |
| 15336 | */ |
| 15337 | I915_WRITE(DPLL(pipe), dpll); |
| 15338 | |
| 15339 | /* We do this three times for luck */ |
| 15340 | for (i = 0; i < 3 ; i++) { |
| 15341 | I915_WRITE(DPLL(pipe), dpll); |
| 15342 | POSTING_READ(DPLL(pipe)); |
| 15343 | udelay(150); /* wait for warmup */ |
| 15344 | } |
| 15345 | |
| 15346 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); |
| 15347 | POSTING_READ(PIPECONF(pipe)); |
Ville Syrjälä | d5fb43c | 2017-11-29 17:37:31 +0200 | [diff] [blame] | 15348 | |
| 15349 | intel_wait_for_pipe_scanline_moving(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15350 | } |
| 15351 | |
| 15352 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 15353 | { |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15354 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15355 | |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15356 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
| 15357 | pipe_name(pipe)); |
| 15358 | |
Ville Syrjälä | 5816d9c | 2017-11-29 14:54:11 +0200 | [diff] [blame] | 15359 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
| 15360 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); |
| 15361 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); |
Ville Syrjälä | b99b9ec | 2018-01-31 16:37:09 +0200 | [diff] [blame] | 15362 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE); |
| 15363 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15364 | |
| 15365 | I915_WRITE(PIPECONF(pipe), 0); |
| 15366 | POSTING_READ(PIPECONF(pipe)); |
| 15367 | |
Ville Syrjälä | 8fedd64 | 2017-11-29 17:37:30 +0200 | [diff] [blame] | 15368 | intel_wait_for_pipe_scanline_stopped(crtc); |
Ville Syrjälä | 2ee0da1 | 2017-06-01 17:36:16 +0300 | [diff] [blame] | 15369 | |
| 15370 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
| 15371 | POSTING_READ(DPLL(pipe)); |
| 15372 | } |
| 15373 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15374 | static void |
| 15375 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) |
| 15376 | { |
| 15377 | struct intel_crtc *crtc; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15378 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15379 | if (INTEL_GEN(dev_priv) >= 4) |
| 15380 | return; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15381 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15382 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15383 | struct intel_plane *plane = |
| 15384 | to_intel_plane(crtc->base.primary); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15385 | struct intel_crtc *plane_crtc; |
| 15386 | enum pipe pipe; |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15387 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15388 | if (!plane->get_hw_state(plane, &pipe)) |
| 15389 | continue; |
| 15390 | |
| 15391 | if (pipe == crtc->pipe) |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15392 | continue; |
| 15393 | |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15394 | DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", |
| 15395 | plane->base.base.id, plane->base.name); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15396 | |
| 15397 | plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15398 | intel_plane_disable_noatomic(plane_crtc, plane); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15399 | } |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15400 | } |
| 15401 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15402 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15403 | { |
| 15404 | struct drm_device *dev = crtc->base.dev; |
| 15405 | struct intel_encoder *encoder; |
| 15406 | |
| 15407 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15408 | return true; |
| 15409 | |
| 15410 | return false; |
| 15411 | } |
| 15412 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15413 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 15414 | { |
| 15415 | struct drm_device *dev = encoder->base.dev; |
| 15416 | struct intel_connector *connector; |
| 15417 | |
| 15418 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15419 | return connector; |
| 15420 | |
| 15421 | return NULL; |
| 15422 | } |
| 15423 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15424 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15425 | enum pipe pch_transcoder) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15426 | { |
| 15427 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15428 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15429 | } |
| 15430 | |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15431 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
| 15432 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15433 | { |
| 15434 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15435 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15436 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15437 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15438 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15439 | /* 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] | 15440 | if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15441 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15442 | |
| 15443 | I915_WRITE(reg, |
| 15444 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15445 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15446 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15447 | if (crtc_state->base.active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15448 | struct intel_plane *plane; |
| 15449 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15450 | /* Disable everything but the primary plane */ |
| 15451 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15452 | const struct intel_plane_state *plane_state = |
| 15453 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15454 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15455 | if (plane_state->base.visible && |
| 15456 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) |
| 15457 | intel_plane_disable_noatomic(crtc, plane); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15458 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15459 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15460 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15461 | /* Adjust the state of the output pipe according to whether we |
| 15462 | * have active connectors/encoders. */ |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15463 | if (crtc_state->base.active && !intel_crtc_has_encoders(crtc)) |
Ville Syrjälä | da1d0e2 | 2017-06-01 17:36:14 +0300 | [diff] [blame] | 15464 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15465 | |
Maarten Lankhorst | 1b52ad4 | 2018-10-11 12:04:53 +0200 | [diff] [blame] | 15466 | if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15467 | /* |
| 15468 | * We start out with underrun reporting disabled to avoid races. |
| 15469 | * For correct bookkeeping mark this on active crtcs. |
| 15470 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15471 | * Also on gmch platforms we dont have any hardware bits to |
| 15472 | * disable the underrun reporting. Which means we need to start |
| 15473 | * out with underrun reporting disabled also on inactive pipes, |
| 15474 | * since otherwise we'll complain about the garbage we read when |
| 15475 | * e.g. coming up after runtime pm. |
| 15476 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15477 | * No protection against concurrent access is required - at |
| 15478 | * worst a fifo underrun happens which also sets this to false. |
| 15479 | */ |
| 15480 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15481 | /* |
| 15482 | * We track the PCH trancoder underrun reporting state |
| 15483 | * within the crtc. With crtc for pipe A housing the underrun |
| 15484 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 15485 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 15486 | * and marking underrun reporting as disabled for the non-existing |
| 15487 | * PCH transcoders B and C would prevent enabling the south |
| 15488 | * error interrupt (see cpt_can_enable_serr_int()). |
| 15489 | */ |
Ville Syrjälä | ecf837d9 | 2017-10-10 15:55:56 +0300 | [diff] [blame] | 15490 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 15491 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15492 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15493 | } |
| 15494 | |
| 15495 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15496 | { |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15497 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15498 | struct intel_connector *connector; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15499 | |
| 15500 | /* We need to check both for a crtc link (meaning that the |
| 15501 | * encoder is active and trying to read from a pipe) and the |
| 15502 | * pipe itself being active. */ |
| 15503 | bool has_active_crtc = encoder->base.crtc && |
| 15504 | to_intel_crtc(encoder->base.crtc)->active; |
| 15505 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 15506 | connector = intel_encoder_find_connector(encoder); |
| 15507 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15508 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15509 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15510 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15511 | |
| 15512 | /* Connector is active, but has no active pipe. This is |
| 15513 | * fallout from our resume register restoring. Disable |
| 15514 | * the encoder manually again. */ |
| 15515 | if (encoder->base.crtc) { |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15516 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
| 15517 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15518 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15519 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15520 | encoder->base.name); |
Jani Nikula | c84c6fe | 2018-10-16 15:41:34 +0300 | [diff] [blame] | 15521 | if (encoder->disable) |
| 15522 | encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15523 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15524 | encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15525 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15526 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15527 | |
| 15528 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15529 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15530 | * in our code, like the register restore mess on resume. Clamp |
| 15531 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 15532 | |
| 15533 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15534 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15535 | } |
Maarten Lankhorst | d6cae4a | 2018-05-16 10:50:38 +0200 | [diff] [blame] | 15536 | |
| 15537 | /* notify opregion of the sanitized encoder state */ |
| 15538 | intel_opregion_notify_encoder(encoder, connector && has_active_crtc); |
Imre Deak | 70332ac | 2018-11-01 16:04:27 +0200 | [diff] [blame] | 15539 | |
| 15540 | if (INTEL_GEN(dev_priv) >= 11) |
| 15541 | icl_sanitize_encoder_pll_mapping(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15542 | } |
| 15543 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15544 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15545 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15546 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15547 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15548 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15549 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15550 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15551 | } |
| 15552 | } |
| 15553 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15554 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15555 | { |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15556 | intel_wakeref_t wakeref; |
| 15557 | |
| 15558 | /* |
| 15559 | * 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] | 15560 | * at a very early point in our resume sequence, where the power well |
| 15561 | * structures are not yet restored. Since this function is at a very |
| 15562 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15563 | * level, just check if the power well is enabled instead of trying to |
| 15564 | * 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] | 15565 | * the rest of the driver uses. |
| 15566 | */ |
| 15567 | wakeref = intel_display_power_get_if_enabled(dev_priv, |
| 15568 | POWER_DOMAIN_VGA); |
| 15569 | if (!wakeref) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15570 | return; |
| 15571 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 15572 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15573 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15574 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15575 | } |
| 15576 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15577 | /* FIXME read out full plane state for all planes */ |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15578 | static void readout_plane_state(struct drm_i915_private *dev_priv) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15579 | { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15580 | struct intel_plane *plane; |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15581 | struct intel_crtc *crtc; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15582 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15583 | for_each_intel_plane(&dev_priv->drm, plane) { |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15584 | struct intel_plane_state *plane_state = |
| 15585 | to_intel_plane_state(plane->base.state); |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15586 | struct intel_crtc_state *crtc_state; |
| 15587 | enum pipe pipe = PIPE_A; |
Ville Syrjälä | eade6c8 | 2018-01-30 22:38:03 +0200 | [diff] [blame] | 15588 | bool visible; |
| 15589 | |
| 15590 | visible = plane->get_hw_state(plane, &pipe); |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15591 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15592 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
| 15593 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15594 | |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15595 | intel_set_plane_visible(crtc_state, plane_state, visible); |
Ville Syrjälä | 7a4a2a4 | 2018-10-03 17:50:52 +0300 | [diff] [blame] | 15596 | |
| 15597 | DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n", |
| 15598 | plane->base.base.id, plane->base.name, |
| 15599 | enableddisabled(visible), pipe_name(pipe)); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15600 | } |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15601 | |
| 15602 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15603 | struct intel_crtc_state *crtc_state = |
| 15604 | to_intel_crtc_state(crtc->base.state); |
| 15605 | |
| 15606 | fixup_active_planes(crtc_state); |
| 15607 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15608 | } |
| 15609 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15610 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15611 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15612 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15613 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15614 | struct intel_crtc *crtc; |
| 15615 | struct intel_encoder *encoder; |
| 15616 | struct intel_connector *connector; |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15617 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15618 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15619 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15620 | dev_priv->active_crtcs = 0; |
| 15621 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15622 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15623 | struct intel_crtc_state *crtc_state = |
| 15624 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15625 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 15626 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15627 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15628 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15629 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15630 | crtc_state->base.active = crtc_state->base.enable = |
| 15631 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15632 | |
| 15633 | crtc->base.enabled = crtc_state->base.enable; |
| 15634 | crtc->active = crtc_state->base.active; |
| 15635 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15636 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15637 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15638 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 15639 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 15640 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15641 | enableddisabled(crtc_state->base.active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15642 | } |
| 15643 | |
Ville Syrjälä | 62358aa | 2018-10-03 17:50:17 +0300 | [diff] [blame] | 15644 | readout_plane_state(dev_priv); |
| 15645 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15646 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15647 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15648 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15649 | pll->on = pll->info->funcs->get_hw_state(dev_priv, pll, |
| 15650 | &pll->state.hw_state); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15651 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15652 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15653 | struct intel_crtc_state *crtc_state = |
| 15654 | to_intel_crtc_state(crtc->base.state); |
| 15655 | |
| 15656 | if (crtc_state->base.active && |
| 15657 | crtc_state->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15658 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15659 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 15660 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15661 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15662 | 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] | 15663 | pll->info->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15664 | } |
| 15665 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15666 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15667 | pipe = 0; |
| 15668 | |
| 15669 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15670 | struct intel_crtc_state *crtc_state; |
| 15671 | |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 15672 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15673 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15674 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15675 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15676 | encoder->get_config(encoder, crtc_state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15677 | } else { |
| 15678 | encoder->base.crtc = NULL; |
| 15679 | } |
| 15680 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15681 | 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] | 15682 | encoder->base.base.id, encoder->base.name, |
| 15683 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15684 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15685 | } |
| 15686 | |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15687 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15688 | for_each_intel_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15689 | if (connector->get_hw_state(connector)) { |
| 15690 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15691 | |
| 15692 | encoder = connector->encoder; |
| 15693 | connector->base.encoder = &encoder->base; |
| 15694 | |
| 15695 | if (encoder->base.crtc && |
| 15696 | encoder->base.crtc->state->active) { |
| 15697 | /* |
| 15698 | * This has to be done during hardware readout |
| 15699 | * because anything calling .crtc_disable may |
| 15700 | * rely on the connector_mask being accurate. |
| 15701 | */ |
| 15702 | encoder->base.crtc->state->connector_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15703 | drm_connector_mask(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15704 | encoder->base.crtc->state->encoder_mask |= |
Ville Syrjälä | 40560e2 | 2018-06-26 22:47:11 +0300 | [diff] [blame] | 15705 | drm_encoder_mask(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15706 | } |
| 15707 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15708 | } else { |
| 15709 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15710 | connector->base.encoder = NULL; |
| 15711 | } |
| 15712 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 15713 | connector->base.base.id, connector->base.name, |
| 15714 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15715 | } |
Daniel Vetter | f9e905c | 2017-03-01 10:52:25 +0100 | [diff] [blame] | 15716 | drm_connector_list_iter_end(&conn_iter); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15717 | |
| 15718 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15719 | struct intel_crtc_state *crtc_state = |
| 15720 | to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15721 | int min_cdclk = 0; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15722 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15723 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15724 | if (crtc_state->base.active) { |
| 15725 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); |
Ville Syrjälä | bd4cd03 | 2018-04-26 19:30:15 +0300 | [diff] [blame] | 15726 | crtc->base.mode.hdisplay = crtc_state->pipe_src_w; |
| 15727 | crtc->base.mode.vdisplay = crtc_state->pipe_src_h; |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15728 | 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] | 15729 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15730 | |
| 15731 | /* |
| 15732 | * The initial mode needs to be set in order to keep |
| 15733 | * the atomic core happy. It wants a valid mode if the |
| 15734 | * crtc's enabled, so we do the above call. |
| 15735 | * |
Daniel Vetter | 7800fb6 | 2016-12-19 09:24:23 +0100 | [diff] [blame] | 15736 | * But we don't set all the derived state fully, hence |
| 15737 | * set a flag to indicate that a full recalculation is |
| 15738 | * needed on the next commit. |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15739 | */ |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15740 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15741 | |
Ville Syrjälä | a7d1b3f | 2017-01-26 21:50:31 +0200 | [diff] [blame] | 15742 | intel_crtc_compute_pixel_rate(crtc_state); |
| 15743 | |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15744 | if (dev_priv->display.modeset_calc_cdclk) { |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15745 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
Ville Syrjälä | 9c61de4 | 2017-07-10 22:33:47 +0300 | [diff] [blame] | 15746 | if (WARN_ON(min_cdclk < 0)) |
| 15747 | min_cdclk = 0; |
| 15748 | } |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15749 | |
Daniel Vetter | 5caa0fe | 2017-05-09 16:03:29 +0200 | [diff] [blame] | 15750 | drm_calc_timestamping_constants(&crtc->base, |
| 15751 | &crtc_state->base.adjusted_mode); |
Maarten Lankhorst | f2bdd11 | 2018-10-11 12:04:52 +0200 | [diff] [blame] | 15752 | update_scanline_offset(crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15753 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15754 | |
Ville Syrjälä | d305e06 | 2017-08-30 21:57:03 +0300 | [diff] [blame] | 15755 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
Ville Syrjälä | 53e9bf5 | 2017-10-24 12:52:14 +0300 | [diff] [blame] | 15756 | dev_priv->min_voltage_level[crtc->pipe] = |
| 15757 | crtc_state->min_voltage_level; |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 15758 | |
Ville Syrjälä | a8cd6da | 2016-12-22 16:04:41 +0200 | [diff] [blame] | 15759 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15760 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15761 | } |
| 15762 | |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15763 | static void |
| 15764 | get_encoder_power_domains(struct drm_i915_private *dev_priv) |
| 15765 | { |
| 15766 | struct intel_encoder *encoder; |
| 15767 | |
| 15768 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
| 15769 | u64 get_domains; |
| 15770 | enum intel_display_power_domain domain; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15771 | struct intel_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15772 | |
| 15773 | if (!encoder->get_power_domains) |
| 15774 | continue; |
| 15775 | |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15776 | /* |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15777 | * MST-primary and inactive encoders don't have a crtc state |
| 15778 | * and neither of these require any power domain references. |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15779 | */ |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15780 | if (!encoder->base.crtc) |
| 15781 | continue; |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15782 | |
Imre Deak | b79ebe7 | 2018-07-05 15:26:54 +0300 | [diff] [blame] | 15783 | crtc_state = to_intel_crtc_state(encoder->base.crtc->state); |
Imre Deak | 5252805 | 2018-06-21 21:44:49 +0300 | [diff] [blame] | 15784 | get_domains = encoder->get_power_domains(encoder, crtc_state); |
Ander Conselvan de Oliveira | 62b6956 | 2017-02-24 16:19:59 +0200 | [diff] [blame] | 15785 | for_each_power_domain(domain, get_domains) |
| 15786 | intel_display_power_get(dev_priv, domain); |
| 15787 | } |
| 15788 | } |
| 15789 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15790 | static void intel_early_display_was(struct drm_i915_private *dev_priv) |
| 15791 | { |
| 15792 | /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */ |
| 15793 | if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv)) |
| 15794 | I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) | |
| 15795 | DARBF_GATING_DIS); |
| 15796 | |
| 15797 | if (IS_HASWELL(dev_priv)) { |
| 15798 | /* |
| 15799 | * WaRsPkgCStateDisplayPMReq:hsw |
| 15800 | * System hang if this isn't done before disabling all planes! |
| 15801 | */ |
| 15802 | I915_WRITE(CHICKEN_PAR1_1, |
| 15803 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); |
| 15804 | } |
| 15805 | } |
| 15806 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 15807 | static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv, |
| 15808 | enum port port, i915_reg_t hdmi_reg) |
| 15809 | { |
| 15810 | u32 val = I915_READ(hdmi_reg); |
| 15811 | |
| 15812 | if (val & SDVO_ENABLE || |
| 15813 | (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A)) |
| 15814 | return; |
| 15815 | |
| 15816 | DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n", |
| 15817 | port_name(port)); |
| 15818 | |
| 15819 | val &= ~SDVO_PIPE_SEL_MASK; |
| 15820 | val |= SDVO_PIPE_SEL(PIPE_A); |
| 15821 | |
| 15822 | I915_WRITE(hdmi_reg, val); |
| 15823 | } |
| 15824 | |
| 15825 | static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv, |
| 15826 | enum port port, i915_reg_t dp_reg) |
| 15827 | { |
| 15828 | u32 val = I915_READ(dp_reg); |
| 15829 | |
| 15830 | if (val & DP_PORT_EN || |
| 15831 | (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A)) |
| 15832 | return; |
| 15833 | |
| 15834 | DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n", |
| 15835 | port_name(port)); |
| 15836 | |
| 15837 | val &= ~DP_PIPE_SEL_MASK; |
| 15838 | val |= DP_PIPE_SEL(PIPE_A); |
| 15839 | |
| 15840 | I915_WRITE(dp_reg, val); |
| 15841 | } |
| 15842 | |
| 15843 | static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv) |
| 15844 | { |
| 15845 | /* |
| 15846 | * The BIOS may select transcoder B on some of the PCH |
| 15847 | * ports even it doesn't enable the port. This would trip |
| 15848 | * assert_pch_dp_disabled() and assert_pch_hdmi_disabled(). |
| 15849 | * Sanitize the transcoder select bits to prevent that. We |
| 15850 | * assume that the BIOS never actually enabled the port, |
| 15851 | * because if it did we'd actually have to toggle the port |
| 15852 | * on and back off to make the transcoder A select stick |
| 15853 | * (see. intel_dp_link_down(), intel_disable_hdmi(), |
| 15854 | * intel_disable_sdvo()). |
| 15855 | */ |
| 15856 | ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B); |
| 15857 | ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C); |
| 15858 | ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D); |
| 15859 | |
| 15860 | /* PCH SDVOB multiplex with HDMIB */ |
| 15861 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB); |
| 15862 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC); |
| 15863 | ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID); |
| 15864 | } |
| 15865 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15866 | /* Scan out the current hw modeset state, |
| 15867 | * and sanitizes it to the current state |
| 15868 | */ |
| 15869 | static void |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15870 | intel_modeset_setup_hw_state(struct drm_device *dev, |
| 15871 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15872 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 15873 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15874 | struct intel_crtc_state *crtc_state; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15875 | struct intel_encoder *encoder; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15876 | struct intel_crtc *crtc; |
| 15877 | intel_wakeref_t wakeref; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15878 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15879 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15880 | wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15881 | |
Rodrigo Vivi | df49ec8 | 2017-11-10 16:03:19 -0800 | [diff] [blame] | 15882 | intel_early_display_was(dev_priv); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15883 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15884 | |
| 15885 | /* 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] | 15886 | get_encoder_power_domains(dev_priv); |
| 15887 | |
Ville Syrjälä | 3aefb67 | 2018-11-08 16:36:35 +0200 | [diff] [blame] | 15888 | if (HAS_PCH_IBX(dev_priv)) |
| 15889 | ibx_sanitize_pch_ports(dev_priv); |
| 15890 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15891 | /* |
| 15892 | * intel_sanitize_plane_mapping() may need to do vblank |
| 15893 | * waits, so we need vblank interrupts restored beforehand. |
| 15894 | */ |
| 15895 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 15896 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | b1e0159 | 2017-11-17 21:19:09 +0200 | [diff] [blame] | 15897 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15898 | if (crtc->base.state->active) |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15899 | drm_crtc_vblank_on(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15900 | } |
| 15901 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15902 | intel_sanitize_plane_mapping(dev_priv); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15903 | |
Ville Syrjälä | 68bc30d | 2018-10-03 17:49:51 +0300 | [diff] [blame] | 15904 | for_each_intel_encoder(dev, encoder) |
| 15905 | intel_sanitize_encoder(encoder); |
| 15906 | |
| 15907 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15908 | crtc_state = to_intel_crtc_state(crtc->base.state); |
Ville Syrjälä | aecd36b | 2017-06-01 17:36:13 +0300 | [diff] [blame] | 15909 | intel_sanitize_crtc(crtc, ctx); |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15910 | intel_dump_pipe_config(crtc, crtc_state, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15911 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15912 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15913 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15914 | intel_modeset_update_connector_atomic_state(dev); |
| 15915 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15916 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15917 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15918 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15919 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15920 | continue; |
| 15921 | |
Lucas De Marchi | 72f775f | 2018-03-20 15:06:34 -0700 | [diff] [blame] | 15922 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", |
| 15923 | pll->info->name); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15924 | |
Lucas De Marchi | ee1398b | 2018-03-20 15:06:33 -0700 | [diff] [blame] | 15925 | pll->info->funcs->disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15926 | pll->on = false; |
| 15927 | } |
| 15928 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15929 | if (IS_G4X(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15930 | g4x_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 15931 | g4x_wm_sanitize(dev_priv); |
| 15932 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15933 | vlv_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15934 | vlv_wm_sanitize(dev_priv); |
Rodrigo Vivi | a029fa4 | 2017-08-09 13:52:48 -0700 | [diff] [blame] | 15935 | } else if (INTEL_GEN(dev_priv) >= 9) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15936 | skl_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15937 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 15938 | ilk_wm_get_hw_state(dev_priv); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 15939 | } |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15940 | |
| 15941 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | d8fc70b | 2017-02-09 11:31:21 +0200 | [diff] [blame] | 15942 | u64 put_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15943 | |
Maarten Lankhorst | 91d7819 | 2018-10-11 12:04:54 +0200 | [diff] [blame] | 15944 | crtc_state = to_intel_crtc_state(crtc->base.state); |
| 15945 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15946 | if (WARN_ON(put_domains)) |
| 15947 | modeset_put_power_domains(dev_priv, put_domains); |
| 15948 | } |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 15949 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 15950 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15951 | |
| 15952 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15953 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15954 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15955 | void intel_display_resume(struct drm_device *dev) |
| 15956 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15957 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15958 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15959 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15960 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15961 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15962 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15963 | if (state) |
| 15964 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15965 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15966 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15967 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15968 | while (1) { |
| 15969 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 15970 | if (ret != -EDEADLK) |
| 15971 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15972 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15973 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15974 | } |
| 15975 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15976 | if (!ret) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 15977 | ret = __intel_display_resume(dev, state, &ctx); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 15978 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 15979 | intel_enable_ipc(dev_priv); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15980 | drm_modeset_drop_locks(&ctx); |
| 15981 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15982 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 15983 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15984 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 3c5e37f | 2017-01-15 12:58:25 +0000 | [diff] [blame] | 15985 | if (state) |
| 15986 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15987 | } |
| 15988 | |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15989 | static void intel_hpd_poll_fini(struct drm_device *dev) |
| 15990 | { |
| 15991 | struct intel_connector *connector; |
| 15992 | struct drm_connector_list_iter conn_iter; |
| 15993 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 15994 | /* Kill all the work that may have been queued by hpd. */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 15995 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 15996 | for_each_intel_connector_iter(connector, &conn_iter) { |
| 15997 | if (connector->modeset_retry_work.func) |
| 15998 | cancel_work_sync(&connector->modeset_retry_work); |
Ramalingam C | d3dacc7 | 2018-10-29 15:15:46 +0530 | [diff] [blame] | 15999 | if (connector->hdcp.shim) { |
| 16000 | cancel_delayed_work_sync(&connector->hdcp.check_work); |
| 16001 | cancel_work_sync(&connector->hdcp.prop_work); |
Sean Paul | ee5e5e7 | 2018-01-08 14:55:39 -0500 | [diff] [blame] | 16002 | } |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16003 | } |
| 16004 | drm_connector_list_iter_end(&conn_iter); |
| 16005 | } |
| 16006 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16007 | void intel_modeset_cleanup(struct drm_device *dev) |
| 16008 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16009 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 16010 | |
Chris Wilson | 8bcf9f7 | 2018-07-10 10:44:20 +0100 | [diff] [blame] | 16011 | flush_workqueue(dev_priv->modeset_wq); |
| 16012 | |
Chris Wilson | eb955ee | 2017-01-23 21:29:39 +0000 | [diff] [blame] | 16013 | flush_work(&dev_priv->atomic_helper.free_work); |
| 16014 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); |
| 16015 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16016 | /* |
| 16017 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 16018 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16019 | * experience fancy races otherwise. |
| 16020 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 16021 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 16022 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16023 | /* |
| 16024 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 16025 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 16026 | */ |
Manasi Navare | 886c6b8 | 2017-10-26 14:52:00 -0700 | [diff] [blame] | 16027 | intel_hpd_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 16028 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 16029 | /* poll work can call into fbdev, hence clean that up afterwards */ |
| 16030 | intel_fbdev_fini(dev_priv); |
| 16031 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 16032 | intel_unregister_dsm_handler(); |
| 16033 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 16034 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 16035 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 16036 | /* flush any delayed tasks or pending work */ |
| 16037 | flush_scheduled_work(); |
| 16038 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16039 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 16040 | |
José Roberto de Souza | 58db08a7 | 2018-11-07 16:16:47 -0800 | [diff] [blame] | 16041 | intel_overlay_cleanup(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16042 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 16043 | intel_teardown_gmbus(dev_priv); |
Ville Syrjälä | 757fffc | 2017-11-13 15:36:22 +0200 | [diff] [blame] | 16044 | |
| 16045 | destroy_workqueue(dev_priv->modeset_wq); |
José Roberto de Souza | acde44b | 2018-11-07 16:16:45 -0800 | [diff] [blame] | 16046 | |
| 16047 | intel_fbc_cleanup_cfb(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16048 | } |
| 16049 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16050 | /* |
| 16051 | * set vga decode state - true == enable VGA decode |
| 16052 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16053 | 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] | 16054 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16055 | 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] | 16056 | u16 gmch_ctrl; |
| 16057 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16058 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 16059 | DRM_ERROR("failed to read control word\n"); |
| 16060 | return -EIO; |
| 16061 | } |
| 16062 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 16063 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 16064 | return 0; |
| 16065 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16066 | if (state) |
| 16067 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 16068 | else |
| 16069 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16070 | |
| 16071 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 16072 | DRM_ERROR("failed to write control word\n"); |
| 16073 | return -EIO; |
| 16074 | } |
| 16075 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16076 | return 0; |
| 16077 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16078 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16079 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 16080 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16081 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16082 | |
| 16083 | u32 power_well_driver; |
| 16084 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16085 | int num_transcoders; |
| 16086 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16087 | struct intel_cursor_error_state { |
| 16088 | u32 control; |
| 16089 | u32 position; |
| 16090 | u32 base; |
| 16091 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16092 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16093 | |
| 16094 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16095 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16096 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16097 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16098 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16099 | |
| 16100 | struct intel_plane_error_state { |
| 16101 | u32 control; |
| 16102 | u32 stride; |
| 16103 | u32 size; |
| 16104 | u32 pos; |
| 16105 | u32 addr; |
| 16106 | u32 surface; |
| 16107 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16108 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16109 | |
| 16110 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16111 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16112 | enum transcoder cpu_transcoder; |
| 16113 | |
| 16114 | u32 conf; |
| 16115 | |
| 16116 | u32 htotal; |
| 16117 | u32 hblank; |
| 16118 | u32 hsync; |
| 16119 | u32 vtotal; |
| 16120 | u32 vblank; |
| 16121 | u32 vsync; |
| 16122 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16123 | }; |
| 16124 | |
| 16125 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16126 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16127 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16128 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16129 | int transcoders[] = { |
| 16130 | TRANSCODER_A, |
| 16131 | TRANSCODER_B, |
| 16132 | TRANSCODER_C, |
| 16133 | TRANSCODER_EDP, |
| 16134 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16135 | int i; |
| 16136 | |
José Roberto de Souza | e1bf094 | 2018-11-30 15:20:47 -0800 | [diff] [blame] | 16137 | if (!HAS_DISPLAY(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16138 | return NULL; |
| 16139 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16140 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16141 | if (error == NULL) |
| 16142 | return NULL; |
| 16143 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16144 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Imre Deak | 75e3968 | 2018-08-06 12:58:39 +0300 | [diff] [blame] | 16145 | error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16146 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16147 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16148 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16149 | __intel_display_power_is_enabled(dev_priv, |
| 16150 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16151 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16152 | continue; |
| 16153 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16154 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16155 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16156 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16157 | |
| 16158 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16159 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16160 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16161 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16162 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16163 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16164 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16165 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16166 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16167 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16168 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16169 | } |
| 16170 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16171 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16172 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16173 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16174 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16175 | } |
| 16176 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16177 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 16178 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 16179 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16180 | error->num_transcoders++; /* Account for eDP. */ |
| 16181 | |
| 16182 | for (i = 0; i < error->num_transcoders; i++) { |
| 16183 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16184 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16185 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16186 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16187 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16188 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16189 | continue; |
| 16190 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16191 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16192 | |
| 16193 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16194 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16195 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16196 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16197 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16198 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16199 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16200 | } |
| 16201 | |
| 16202 | return error; |
| 16203 | } |
| 16204 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16205 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16206 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16207 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16208 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16209 | struct intel_display_error_state *error) |
| 16210 | { |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 16211 | struct drm_i915_private *dev_priv = m->i915; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16212 | int i; |
| 16213 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16214 | if (!error) |
| 16215 | return; |
| 16216 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16217 | 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] | 16218 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16219 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16220 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16221 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16222 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16223 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16224 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16225 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16226 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16227 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16228 | err_printf(m, "Plane [%d]:\n", i); |
| 16229 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16230 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16231 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16232 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16233 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16234 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 16235 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16236 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 16237 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16238 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16239 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16240 | } |
| 16241 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16242 | err_printf(m, "Cursor [%d]:\n", i); |
| 16243 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16244 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16245 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16246 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16247 | |
| 16248 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16249 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16250 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16251 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16252 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16253 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16254 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16255 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16256 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16257 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16258 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16259 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16260 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16261 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 16262 | |
| 16263 | #endif |